diff --git a/src/plugins/data/public/query/query_string/dataset_service/dataset_service.mock.ts b/src/plugins/data/public/query/query_string/dataset_service/dataset_service.mock.ts index ecf7c74410ca..0b9372b73092 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/dataset_service.mock.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/dataset_service.mock.ts @@ -18,7 +18,7 @@ const createSetupDatasetServiceMock = (): jest.Mocked => toDataset: jest.fn(), fetch: jest.fn(), fetchFields: jest.fn(), - supportedLanguages: jest.fn().mockReturnValue(['DQL', 'Lucene', 'PPL', 'SQL']), + supportedLanguages: jest.fn().mockReturnValue(['kuery', 'lucene', 'PPL', 'SQL']), }; const defaultDataset: Dataset = { diff --git a/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts b/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts index 1034850c41ba..9ca564abdf3d 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts @@ -65,9 +65,9 @@ export const indexPatternTypeConfig: DatasetTypeConfig = { supportedLanguages: (dataset): string[] => { if (dataset.dataSource?.type === 'OpenSearch Serverless') { - return ['DQL', 'Lucene']; + return ['kuery', 'lucene']; } - return ['DQL', 'Lucene', 'PPL', 'SQL']; + return ['kuery', 'lucene', 'PPL', 'SQL']; }, }; diff --git a/src/plugins/data/public/query/query_string/dataset_service/types.ts b/src/plugins/data/public/query/query_string/dataset_service/types.ts index 8d597694ac49..c0d97a45ca1b 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/types.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/types.ts @@ -41,7 +41,7 @@ export interface DatasetTypeConfig { fetchFields: (dataset: Dataset) => Promise; /** * Retrieves the supported query languages for this dataset type. - * @returns {Promise} A promise that resolves to an array of supported language names. + * @returns {Promise} A promise that resolves to an array of supported language ids. */ supportedLanguages: (dataset: Dataset) => string[]; } diff --git a/src/plugins/data/public/query/query_string/language_service/language_service.ts b/src/plugins/data/public/query/query_string/language_service/language_service.ts index 113a85e25e10..899915248e52 100644 --- a/src/plugins/data/public/query/query_string/language_service/language_service.ts +++ b/src/plugins/data/public/query/query_string/language_service/language_service.ts @@ -57,8 +57,8 @@ export class LanguageService { this.languages.set(config.id, config); } - public getLanguage(language: string): LanguageConfig | undefined { - return this.languages.get(language); + public getLanguage(languageId: string): LanguageConfig | undefined { + return this.languages.get(languageId); } public getLanguages(): LanguageConfig[] { diff --git a/src/plugins/data/public/query/query_string/query_string_manager.ts b/src/plugins/data/public/query/query_string/query_string_manager.ts index 754b444435c0..9171799c28e6 100644 --- a/src/plugins/data/public/query/query_string/query_string_manager.ts +++ b/src/plugins/data/public/query/query_string/query_string_manager.ts @@ -157,14 +157,14 @@ export class QueryStringManager { public getInitialQueryByDataset = (newDataset: Dataset) => { const curQuery = this.query$.getValue(); - const languageId = curQuery.language; + const languageId = newDataset.language || curQuery.language; const language = this.languageService.getLanguage(languageId); - const newQuery = { ...curQuery, dataset: newDataset }; - const input = language?.getQueryString(newQuery) || ''; + const newQuery = { ...curQuery, language: languageId, dataset: newDataset }; + const newQueryString = language?.getQueryString(newQuery) || ''; return { ...newQuery, - query: input, + query: newQueryString, }; }; diff --git a/src/plugins/data/public/ui/dataset_selector/configurator.tsx b/src/plugins/data/public/ui/dataset_selector/configurator.tsx index e59683dffa28..527d5f7e66c8 100644 --- a/src/plugins/data/public/ui/dataset_selector/configurator.tsx +++ b/src/plugins/data/public/ui/dataset_selector/configurator.tsx @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useEffect, useState } from 'react'; import { EuiButton, EuiButtonEmpty, @@ -19,8 +18,9 @@ import { } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; +import React, { useEffect, useState } from 'react'; import { BaseDataset, Dataset, DatasetField } from '../../../common'; -import { getQueryService, getIndexPatterns } from '../../services'; +import { getIndexPatterns, getQueryService } from '../../services'; export const Configurator = ({ baseDataset, @@ -35,14 +35,20 @@ export const Configurator = ({ }) => { const queryService = getQueryService(); const queryString = queryService.queryString; + const languageService = queryService.queryString.getLanguageService(); const indexPatternsService = getIndexPatterns(); const type = queryString.getDatasetService().getType(baseDataset.type); const languages = type?.supportedLanguages(baseDataset) || []; - const [dataset, setDataset] = useState(baseDataset); const [timeFields, setTimeFields] = useState(); - const [timeField, setTimeField] = useState(dataset.timeFieldName); - const [language, setLanguage] = useState(languages[0]); + const [timeFieldName, setTimeFieldName] = useState(); + const [language, setLanguage] = useState(() => { + const currentLanguage = queryString.getQuery().language; + if (languages.includes(currentLanguage)) { + return currentLanguage; + } + return languages[0]; + }); useEffect(() => { const fetchFields = async () => { @@ -88,7 +94,7 @@ export const Configurator = ({ } )} > - + {timeFields && timeFields.length > 0 && ( { const value = e.target.value === 'undefined' ? undefined : e.target.value; - setTimeField(value); - setDataset({ ...dataset, timeFieldName: value }); + setTimeFieldName(value); }} /> @@ -127,7 +132,7 @@ export const Configurator = ({ > ({ - text: languageId, + text: languageService.getLanguage(languageId)?.title || languageId, value: languageId, }))} value={language} @@ -149,7 +154,7 @@ export const Configurator = ({ defaultMessage="Previous" /> - onConfirm(dataset)} fill> + onConfirm({ ...baseDataset, language, timeFieldName })} fill> { iconSize="s" onClick={onButtonClick} className="languageSelector__button" - iconType={'arrowDown'} + iconType="arrowDown" > {selectedLanguage.label}