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

[Discover]Sample Queries and Saved Queries in No Results Page #8616

Merged
merged 3 commits into from
Oct 18, 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))
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not be specific about the return value being an array of title-query combos?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, i think maybe we should consider just returning an actual Query object and not the query string.

}
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 {
Copy link
Member

@kavilla kavilla Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this PR, unless we want to modify the type from query: string to query: Query. i think we should create an action item to unify this and recent query and saved queries to extend from a base class. because i can see a world where we add buttons near the sample queries and instead of fighting to update to set the query behavior subject we can just push the entire query object. for example, it will set the date range to 1 week before and 1 week after.

recent query kind of acts the same and so does saved queries. so if we have a base class we could re-use it everywhere. not sure of a good name though but an example to drive the point home like QueryWithAttributes

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[];
}
5 changes: 5 additions & 0 deletions src/plugins/data/public/ui/_common.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

.dataUI-centerPanel {
height: 100%;
width: 100%;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

.discoverNoResults-sampleContainer {
@include euiLegibilityMaxWidth(100%);

margin: 0 auto;
}
Loading
Loading