Skip to content

Commit

Permalink
[Manual backport 2.x] [Discover]Sample Queries and Saved Queries in N…
Browse files Browse the repository at this point in the history
…o Results Page #8616  (#8663)

* Update Discover appearance (#8651)

* Update Discover appearance

Signed-off-by: Miki <miki@amazon.com>

* Changeset file for PR #8651 created/updated

---------

Signed-off-by: Miki <miki@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>

(cherry picked from commit 17103ba)
Signed-off-by: Miki <miki@amazon.com>

* Improve Empty State Handling: Add No Index Patterns Panel with Data Selection in Discover View (#8613)

* Improve Empty State Handling: Add No Index Patterns Panel with Data Selection in Discover View

This PR primarily addresses the scenario when no index patterns (general) is available in the Discover view.
Instead of redirecting users to the index management page, it introduces a new "No Index Patterns" panel.
This panel provides users with the option to open a data selector and add index patterns
directly from the Discover view, improving the user experience for new or empty deployments.

To achieve, we move the selectedDataset state from ConnectedDatasetSelector to the app container's
state management. This allows the AdvancedSelector, opened from the AppContainer, to update
the dataset state effectively. Key changes include:

* Implementing NoIndexPatternsPanel and AdvancedSelector components.
* Refactoring dataset state management in AppContainer and Sidebar.
* Modifying DiscoverCanvas to conditionally render NoIndexPatternsPanel.
* Updating ConnectedDatasetSelector to use shared state and dataset change handling.

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Signed-off-by: Miki <miki@amazon.com>

* Update design of no data selected

Signed-off-by: Miki <miki@amazon.com>

* use i18n

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Signed-off-by: Miki <miki@amazon.com>

* fix comments

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* Update design of no data selected

Signed-off-by: Miki <miki@amazon.com>

* fix lint error

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

---------

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Signed-off-by: Miki <miki@amazon.com>
Co-authored-by: Miki <miki@amazon.com>

(cherry picked from commit 6659139)
Signed-off-by: Miki <miki@amazon.com>

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

* Sample Queries and Saved Queries in No Results Page

Signed-off-by: Sean Li <lnse@amazon.com>
Signed-off-by: Miki <miki@amazon.com>

* Changeset file for PR #8616 created/updated

* Update styling

Signed-off-by: Miki <miki@amazon.com>

---------

Signed-off-by: Sean Li <lnse@amazon.com>
Signed-off-by: Miki <miki@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: Miki <miki@amazon.com>
(cherry picked from commit 9da1b77)

---------

Signed-off-by: Miki <miki@amazon.com>
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: Sean Li <lnse@amazon.com>
  • Loading branch information
4 people authored Oct 19, 2024
1 parent 1995d7d commit 74a69d6
Show file tree
Hide file tree
Showing 54 changed files with 1,133 additions and 176 deletions.
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 { includes } from 'lodash';
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 @@ export const createEnsureDefaultIndexPattern = (
* 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 @@ export const createEnsureDefaultIndexPattern = (
defaultId = patterns[0];
await uiSettings.set('defaultIndex', defaultId);
} else {
return onRedirectNoIndexPattern();
if (shouldRedirect) return onRedirectNoIndexPattern();
else return;
}
};
};
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 @@ export class DatasetService {
return Number(this.sessionStorage.get('lastCacheTime')) || undefined;
}

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

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 @@ export const indexPatternTypeConfig: DatasetTypeConfig = {
}
return ['kuery', 'lucene', 'PPL', 'SQL'];
},

getSampleQueries: (dataset: Dataset, language: string) => {
switch (language) {
case 'PPL':
return [
{
title: i18n.translate('data.indexPatternType.sampleQuery.basicPPLQuery', {
defaultMessage: 'Sample query for PPL',
}),
query: `source = ${dataset.title}`,
},
];
case 'SQL':
return [
{
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 @@ export const indexTypeConfig: DatasetTypeConfig = {
supportedLanguages: (dataset: Dataset): string[] => {
return ['SQL', 'PPL'];
},

getSampleQueries: (dataset: Dataset, language: string) => {
switch (language) {
case 'PPL':
return [
{
title: i18n.translate('data.indexType.sampleQuery.basicPPLQuery', {
defaultMessage: 'Sample query for PPL',
}),
query: `source = ${dataset.title}`,
},
];
case 'SQL':
return [
{
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

0 comments on commit 74a69d6

Please sign in to comment.