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

Added framework to get default query string using dataset and language combination #8896

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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/8896.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Added framework to get default query string using dataset and language combination ([#8896](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8896))
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DatasetField,
DatasetSearchOptions,
DataStructure,
Query,
SavedObject,
} from '../../../../common';
import { IDataPluginServices } from '../../../types';
Expand Down Expand Up @@ -106,4 +107,8 @@ export interface DatasetTypeConfig {
* Service used for indexedViews related operations
*/
indexedViewsService?: DatasetIndexedViewsService;
/**
* Returns the initial query that is added to the query editor when a dataset is selected.
*/
getInitialQueryString?: (query: Query) => string | void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
return this.storage.get('userQueryString') || '';
}

private getInitialDatasetQueryString(query: Query, dataset: Dataset) {
amsiglan marked this conversation as resolved.
Show resolved Hide resolved
const { language } = query;

Check warning on line 67 in src/plugins/data/public/query/query_string/query_string_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/query_string_manager.ts#L67

Added line #L67 was not covered by tests

const languageConfig = this.languageService.getLanguage(language);
const typeConfig = this.datasetService.getType(dataset.type);
return (

Check warning on line 71 in src/plugins/data/public/query/query_string/query_string_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/query_string_manager.ts#L69-L71

Added lines #L69 - L71 were not covered by tests
typeConfig?.getInitialQueryString?.(query) ?? (languageConfig?.getQueryString(query) || '')
);
}

public getDefaultQuery(): Query {
const defaultLanguageId = this.getDefaultLanguage();
const defaultQuery = this.getDefaultQueryString();
Expand All @@ -79,13 +89,11 @@
defaultDataset &&
this.languageService
) {
const language = this.languageService.getLanguage(defaultLanguageId);
const newQuery = { ...query, dataset: defaultDataset };
const newQueryString = language?.getQueryString(newQuery) || '';

return {
...newQuery,
query: newQueryString,
query: this.getInitialDatasetQueryString(newQuery, defaultDataset),
};
}

Expand Down Expand Up @@ -244,13 +252,12 @@

// Both language and dataset provided - generate fresh query
if (language && dataset) {
const languageService = this.languageService.getLanguage(language);
const newQuery = {
language,
dataset,
query: '',
};
newQuery.query = languageService?.getQueryString(newQuery) || '';
newQuery.query = this.getInitialDatasetQueryString(newQuery, dataset);

Check warning on line 260 in src/plugins/data/public/query/query_string/query_string_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/query_string_manager.ts#L260

Added line #L260 was not covered by tests
return newQuery;
}

Expand Down Expand Up @@ -279,7 +286,11 @@
...curQuery,
language: languageId,
};
const queryString = language?.getQueryString(newQuery) || '';
let queryString = language?.getQueryString(newQuery) || '';
amsiglan marked this conversation as resolved.
Show resolved Hide resolved

if (curQuery.dataset) {
queryString = this.getInitialDatasetQueryString(newQuery, curQuery.dataset) ?? queryString;
}
this.languageService.setUserQueryString(queryString);

return {
Expand All @@ -296,17 +307,15 @@
const curQuery = this.query$.getValue();
// Use dataset's preferred language or fallback to current language
const languageId = newDataset.language || curQuery.language;
const language = this.languageService.getLanguage(languageId);
const newQuery = {
...curQuery,
language: languageId,
dataset: newDataset,
};
const queryString = language?.getQueryString(newQuery) || '';

return {
...newQuery,
query: queryString,
query: this.getInitialDatasetQueryString(newQuery, newDataset),
};
};

Expand Down
Loading