Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Manual backport 2.x] [Discover]Sample Queries and Saved Queries in No Results Page #8616 #8663

Merged
merged 3 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8616.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Adds sample queries and saved queries to Discover no results page ([#8616](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8616))
2 changes: 2 additions & 0 deletions changelogs/fragments/8651.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Update the appearance of Discover ([#8651](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8651))
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.context-nav-wrapper {
border: none !important;
border-top-right-radius: $euiSizeL;
border-bottom-right-radius: $euiSizeL;
background-color: $euiSideNavBackgroundColor;
overflow: hidden;
box-shadow: 1px 0 0 $euiBorderColor !important;

.nav-link-item {
padding: $euiSizeS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import { IndexPatternsContract } from './index_patterns';
import { UiSettingsCommon } from '../types';

export type EnsureDefaultIndexPattern = () => Promise<unknown> | undefined;
export type EnsureDefaultIndexPattern = (
shouldRedirect?: boolean
) => Promise<unknown | void> | undefined;

export const createEnsureDefaultIndexPattern = (
uiSettings: UiSettingsCommon,
Expand All @@ -42,7 +44,10 @@
* Checks whether a default index pattern is set and exists and defines
* one otherwise.
*/
return async function ensureDefaultIndexPattern(this: IndexPatternsContract) {
return async function ensureDefaultIndexPattern(
this: IndexPatternsContract,
shouldRedirect: boolean = true
) {
const patterns = await this.getIds();
let defaultId = await uiSettings.get('defaultIndex');
let defined = !!defaultId;
Expand All @@ -62,7 +67,8 @@
defaultId = patterns[0];
await uiSettings.set('defaultIndex', defaultId);
} else {
return onRedirectNoIndexPattern();
if (shouldRedirect) return onRedirectNoIndexPattern();
else return;

Check warning on line 71 in src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts#L71

Added line #L71 was not covered by tests
}
};
};
11 changes: 10 additions & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ import {
} from '../common';

import { FilterLabel } from './ui';
export { createEditor, DefaultInput, DQLBody, SingleLineInput } from './ui';
export {
createEditor,
DefaultInput,
DQLBody,
SingleLineInput,
DatasetSelector,
AdvancedSelector,
NoIndexPatternsPanel,
DatasetSelectorAppearance,
} from './ui';

import {
generateFilters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@
return Number(this.sessionStorage.get('lastCacheTime')) || undefined;
}

public removeFromRecentDatasets(datasetId: string): void {
this.recentDatasets.del(datasetId);
this.serializeRecentDatasets();

Check warning on line 212 in src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts#L211-L212

Added lines #L211 - L212 were not covered by tests
}

private setLastCacheTime(time: number): void {
this.sessionStorage.set('lastCacheTime', time);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { SavedObjectsClientContract } from 'opensearch-dashboards/public';
import { i18n } from '@osd/i18n';
import { DataSourceAttributes } from '../../../../../../data_source/common/data_sources';
import {
DEFAULT_DATA,
Expand Down Expand Up @@ -70,6 +71,29 @@
}
return ['kuery', 'lucene', 'PPL', 'SQL'];
},

getSampleQueries: (dataset: Dataset, language: string) => {
switch (language) {
case 'PPL':
return [

Check warning on line 78 in src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts#L78

Added line #L78 was not covered by tests
{
title: i18n.translate('data.indexPatternType.sampleQuery.basicPPLQuery', {
defaultMessage: 'Sample query for PPL',
}),
query: `source = ${dataset.title}`,
},
];
case 'SQL':
return [

Check warning on line 87 in src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts#L87

Added line #L87 was not covered by tests
{
title: i18n.translate('data.indexPatternType.sampleQuery.basicSQLQuery', {
defaultMessage: 'Sample query for SQL',
}),
query: `SELECT * FROM ${dataset.title} LIMIT 10`,
},
];
}
},
};

const fetchIndexPatterns = async (client: SavedObjectsClientContract): Promise<DataStructure[]> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { SavedObjectsClientContract } from 'opensearch-dashboards/public';
import { map } from 'rxjs/operators';
import { i18n } from '@osd/i18n';
import {
DEFAULT_DATA,
DataStructure,
Expand Down Expand Up @@ -88,6 +89,29 @@
supportedLanguages: (dataset: Dataset): string[] => {
return ['SQL', 'PPL'];
},

getSampleQueries: (dataset: Dataset, language: string) => {
switch (language) {
case 'PPL':
return [

Check warning on line 96 in src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts#L96

Added line #L96 was not covered by tests
{
title: i18n.translate('data.indexType.sampleQuery.basicPPLQuery', {
defaultMessage: 'Sample query for PPL',
}),
query: `source = ${dataset.title}`,
},
];
case 'SQL':
return [

Check warning on line 105 in src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts#L105

Added line #L105 was not covered by tests
{
title: i18n.translate('data.indexType.sampleQuery.basicSQLQuery', {
defaultMessage: 'Sample query for SQL',
}),
query: `SELECT * FROM ${dataset.title} LIMIT 10`,
},
];
}
},
};

const fetchDataSources = async (client: SavedObjectsClientContract) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ export interface DatasetTypeConfig {
* @see https://github.com/opensearch-project/OpenSearch-Dashboards/issues/8362.
*/
combineDataStructures?: (dataStructures: DataStructure[]) => DataStructure | undefined;
/**
* Returns a list of sample queries for this dataset type
*/
getSampleQueries?: (dataset: Dataset, language: string) => any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import { LanguageConfig } from '../types';
import { ISearchInterceptor } from '../../../../search';

Expand All @@ -25,5 +26,51 @@ export const getDQLLanguageConfig = (
showDocLinks: true,
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer', 'vis-builder', '*'],
sampleQueries: [
{
title: i18n.translate('data.dqlLanguage.sampleQuery.titleContainsWind', {
defaultMessage: 'The title field contains the word wind.',
}),
query: 'title: wind',
},
{
title: i18n.translate('data.dqlLanguage.sampleQuery.titleContainsWindOrWindy', {
defaultMessage: 'The title field contains the word wind or the word windy.',
}),
query: 'title: (wind OR windy)',
},
{
title: i18n.translate('data.dqlLanguage.sampleQuery.titleContainsPhraseWindRises', {
defaultMessage: 'The title field contains the phrase wind rises.',
}),
query: 'title: "wind rises"',
},
{
title: i18n.translate('data.dqlLanguage.sampleQuery.titleKeywordExactMatch', {
defaultMessage: 'The title.keyword field exactly matches The wind rises.',
}),
query: 'title.keyword: The wind rises',
},
{
title: i18n.translate('data.dqlLanguage.sampleQuery.titleFieldsContainWind', {
defaultMessage:
'Any field that starts with title (for example, title and title.keyword) contains the word wind',
}),
query: 'title*: wind',
},
{
title: i18n.translate('data.dqlLanguage.sampleQuery.articleTitleContainsWind', {
defaultMessage:
'The field that starts with article and ends with title contains the word wind. Matches the field article title.',
}),
query: 'article*title: wind',
},
{
title: i18n.translate('data.dqlLanguage.sampleQuery.descriptionFieldExists', {
defaultMessage: 'Documents in which the field description exists.',
}),
query: 'description:*',
},
],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import { LanguageConfig } from '../types';
import { ISearchInterceptor } from '../../../../search';

Expand All @@ -25,5 +26,51 @@ export const getLuceneLanguageConfig = (
showDocLinks: true,
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer', 'vis-builder', '*'],
sampleQueries: [
{
title: i18n.translate('data.luceneLanguage.sampleQuery.titleContainsWind', {
defaultMessage: 'The title field contains the word wind.',
}),
query: 'title: wind',
},
{
title: i18n.translate('data.luceneLanguage.sampleQuery.titleContainsWindOrWindy', {
defaultMessage: 'The title field contains the word wind or the word windy.',
}),
query: 'title: (wind OR windy)',
},
{
title: i18n.translate('data.luceneLanguage.sampleQuery.titleContainsPhraseWindRises', {
defaultMessage: 'The title field contains the phrase wind rises.',
}),
query: 'title: "wind rises"',
},
{
title: i18n.translate('data.luceneLanguage.sampleQuery.titleKeywordExactMatch', {
defaultMessage: 'The title.keyword field exactly matches The wind rises.',
}),
query: 'title.keyword: The wind rises',
},
{
title: i18n.translate('data.luceneLanguage.sampleQuery.titleFieldsContainWind', {
defaultMessage:
'Any field that starts with title (for example, title and title.keyword) contains the word wind',
}),
query: 'title*: wind',
},
{
title: i18n.translate('data.luceneLanguage.sampleQuery.articleTitleContainsWind', {
defaultMessage:
'The field that starts with article and ends with title contains the word wind. Matches the field article title.',
}),
query: 'article*title: wind',
},
{
title: i18n.translate('data.luceneLanguage.sampleQuery.descriptionFieldExists', {
defaultMessage: 'Documents in which the field description exists.',
}),
query: 'description:*',
},
],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export interface EditorEnhancements {
queryEditorExtension?: QueryEditorExtensionConfig;
}

export interface SampleQuery {
title: string;
query: string;
}

export interface LanguageConfig {
id: string;
title: string;
Expand All @@ -53,4 +58,5 @@ export interface LanguageConfig {
editorSupportedAppNames?: string[];
supportedAppNames?: string[];
hideDatePicker?: boolean;
sampleQueries?: SampleQuery[];
}
16 changes: 16 additions & 0 deletions src/plugins/data/public/ui/_common.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

.dataUI-centerPanel {
height: 100%;
width: 100%;

// Push the centralized child up, just like ouiOverlayMask
padding-bottom: 10vh;

& > * {
@include euiLegibilityMaxWidth(100%);
}
}
1 change: 1 addition & 0 deletions src/plugins/data/public/ui/_index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "./common";
@import "./filter_bar/index";
@import "./typeahead/index";
@import "./saved_query_management/index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
&__advancedModal {
width: 1200px;
height: 800px;
max-height: calc(100vh - $euiSizeS);

// euiOverlayMask pushes the modal up due to having padding-bottom: 10vh
max-height: calc(90vh - $euiSizeL);

.euiModal__flex {
max-height: none;
Expand Down
Loading
Loading