From 999bc05498d9907a166badc0663df3c67323921f Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 4 Sep 2024 02:33:18 -0700 Subject: [PATCH] [discover][bug] configurator dataset issue (#7981) (#7982) * [discover][bug] configurator dataset issue bad rebase caused only conflict was the dataset. * fix test * fix connections --------- (cherry picked from commit 7dedc5832416ab860413e6ca55704419b66e617a) Signed-off-by: Kawika Avilla Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../lib/index_pattern_type.test.ts | 8 ++++---- .../public/ui/dataset_selector/configurator.tsx | 15 ++++++++++----- .../query_enhancements/public/datasets/s3_type.ts | 8 ++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.test.ts b/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.test.ts index 58961289b298..980d9bb7cf89 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.test.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.test.ts @@ -75,16 +75,16 @@ describe('indexPatternTypeConfig', () => { dataSource: { id: 'dataSourceId', title: 'Cluster 1', type: 'OpenSearch' }, }; expect(indexPatternTypeConfig.supportedLanguages(mockDataset)).toEqual([ - 'DQL', - 'Lucene', + 'kuery', + 'lucene', 'PPL', 'SQL', ]); mockDataset.dataSource = { ...mockDataset.dataSource!, type: 'other' }; expect(indexPatternTypeConfig.supportedLanguages(mockDataset)).toEqual([ - 'DQL', - 'Lucene', + 'kuery', + 'lucene', 'PPL', 'SQL', ]); diff --git a/src/plugins/data/public/ui/dataset_selector/configurator.tsx b/src/plugins/data/public/ui/dataset_selector/configurator.tsx index f90695ab6b84..4db2419bbbd6 100644 --- a/src/plugins/data/public/ui/dataset_selector/configurator.tsx +++ b/src/plugins/data/public/ui/dataset_selector/configurator.tsx @@ -40,8 +40,9 @@ export const Configurator = ({ const type = queryString.getDatasetService().getType(baseDataset.type); const languages = type?.supportedLanguages(baseDataset) || []; + const [dataset, setDataset] = useState(baseDataset); const [timeFields, setTimeFields] = useState(); - const [timeFieldName, setTimeFieldName] = useState(); + const [timeFieldName, setTimeFieldName] = useState(dataset.timeFieldName); const [language, setLanguage] = useState(() => { const currentLanguage = queryString.getQuery().language; if (languages.includes(currentLanguage)) { @@ -94,7 +95,7 @@ export const Configurator = ({ } )} > - + {timeFields && timeFields.length > 0 && ( { const value = e.target.value === 'undefined' ? undefined : e.target.value; setTimeFieldName(value); + setDataset({ ...dataset, timeFieldName: value }); }} /> @@ -136,7 +138,10 @@ export const Configurator = ({ value: languageId, }))} value={language} - onChange={(e) => setLanguage(e.target.value)} + onChange={(e) => { + setLanguage(e.target.value); + setDataset({ ...dataset, language: e.target.value }); + }} /> @@ -156,8 +161,8 @@ export const Configurator = ({ { - queryString.getDatasetService().cacheDataset({ ...dataset, language, timeFieldName }); - onConfirm({ ...dataset, language, timeFieldName }); + queryString.getDatasetService().cacheDataset(dataset); + onConfirm(dataset); }} fill > diff --git a/src/plugins/query_enhancements/public/datasets/s3_type.ts b/src/plugins/query_enhancements/public/datasets/s3_type.ts index d2bca88696b3..a04101ebbff5 100644 --- a/src/plugins/query_enhancements/public/datasets/s3_type.ts +++ b/src/plugins/query_enhancements/public/datasets/s3_type.ts @@ -197,7 +197,7 @@ const fetchDatabases = async (http: HttpSetup, path: DataStructure[]): Promise => { const dataSource = path.find((ds) => ds.type === 'DATA_SOURCE'); - const sessionId = (path.find((ds) => ds.type === 'CONNECTION')?.meta as DataStructureCustomMeta) - .sessionId; + const connection = path.find((ds) => ds.type === 'CONNECTION'); + const sessionId = (connection?.meta as DataStructureCustomMeta).sessionId; const database = path[path.length - 1]; const response = await http.post(`../../api/enhancements/datasource/jobs`, { body: JSON.stringify({ lang: 'sql', query: `SHOW TABLES in ${database.title}`, - datasource: dataSource?.title, + datasource: connection?.title, ...(sessionId && { sessionId }), }), query: {