From d99541867ccbe8e1d99eb5d982343f551de0a563 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Wed, 8 Jan 2025 16:12:06 +0800 Subject: [PATCH 1/4] feat: disable query assistant when dataset type is not supported Signed-off-by: SuZhou-Joe --- .../utils/create_extension.test.tsx | 18 ++++++++++++++++++ .../query_assist/utils/create_extension.tsx | 11 +++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.test.tsx b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.test.tsx index fc790cc79c11..42fc98f10209 100644 --- a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.test.tsx +++ b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.test.tsx @@ -180,4 +180,22 @@ describe('CreateExtension', () => { expect(screen.getByText('QueryAssistSummary')).toBeInTheDocument(); }); + + it('should return disabled when dataset is not supported', async () => { + httpMock.get.mockResolvedValueOnce({ configuredLanguages: ['PPL'] }); + const extension = createQueryAssistExtension(coreSetupMock, dataMock, config); + const isEnabled = await firstValueFrom( + extension.isEnabled$({ + ...dependencies, + query: { + ...mockQueryWithIndexPattern, + dataset: { + ...mockQueryWithIndexPattern.dataset, + type: 'S3', + }, + }, + }) + ); + expect(isEnabled).toBeFalsy(); + }); }); diff --git a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx index 238ef40ff354..6b2a40b29040 100644 --- a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx +++ b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx @@ -93,6 +93,8 @@ const getAvailableLanguages$ = (http: HttpSetup, data: DataPublicPluginSetup) => }) ); +const queryAssistantSupportedDatasetTypes = ['INDEXES', 'INDEX_PATTERN']; + export const createQueryAssistExtension = ( core: CoreSetup, data: DataPublicPluginSetup, @@ -119,8 +121,13 @@ export const createQueryAssistExtension = ( }; } }, - isEnabled$: () => - getAvailableLanguages$(http, data).pipe(map((languages) => languages.length > 0)), + isEnabled$: (dependencies) => { + const query = dependencies.query; + if (!queryAssistantSupportedDatasetTypes.includes(query.dataset?.type || '')) { + return new BehaviorSubject(false); + } + return getAvailableLanguages$(http, data).pipe(map((languages) => languages.length > 0)); + }, getComponent: (dependencies) => { // only show the component if user is on a supported language. return ( From 9d0a41fe7cebbd6ff78b387fd6ba167e6ec1d7d3 Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 08:28:52 +0000 Subject: [PATCH 2/4] Changeset file for PR #9157 created/updated --- changelogs/fragments/9157.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/9157.yml diff --git a/changelogs/fragments/9157.yml b/changelogs/fragments/9157.yml new file mode 100644 index 000000000000..652721e89e72 --- /dev/null +++ b/changelogs/fragments/9157.yml @@ -0,0 +1,2 @@ +fix: +- Disable query assistant when dataset type is not supported ([#9157](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9157)) \ No newline at end of file From 751203fa7d23da3a5ef65b86ed92a3f126556ce2 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Wed, 8 Jan 2025 18:09:47 +0800 Subject: [PATCH 3/4] feat: use constant Signed-off-by: SuZhou-Joe --- .../public/query_assist/utils/create_extension.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx index 6b2a40b29040..0702d306d4d4 100644 --- a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx +++ b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx @@ -93,7 +93,10 @@ const getAvailableLanguages$ = (http: HttpSetup, data: DataPublicPluginSetup) => }) ); -const queryAssistantSupportedDatasetTypes = ['INDEXES', 'INDEX_PATTERN']; +const queryAssistantSupportedDatasetTypes = [ + DEFAULT_DATA.SET_TYPES.INDEX, + DEFAULT_DATA.SET_TYPES.INDEX_PATTERN, +]; export const createQueryAssistExtension = ( core: CoreSetup, From 46cec9d2f294bc41d0212630a8547357da233905 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Wed, 8 Jan 2025 18:11:39 +0800 Subject: [PATCH 4/4] feat: optimize code Signed-off-by: SuZhou-Joe --- .../public/query_assist/utils/create_extension.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx index 0702d306d4d4..926d89b05204 100644 --- a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx +++ b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx @@ -6,7 +6,7 @@ import { i18n } from '@osd/i18n'; import { HttpSetup } from 'opensearch-dashboards/public'; import React, { useEffect, useState } from 'react'; -import { BehaviorSubject } from 'rxjs'; +import { BehaviorSubject, of } from 'rxjs'; import { distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators'; import { DATA_STRUCTURE_META_TYPES, DEFAULT_DATA } from '../../../../data/common'; import { @@ -127,7 +127,7 @@ export const createQueryAssistExtension = ( isEnabled$: (dependencies) => { const query = dependencies.query; if (!queryAssistantSupportedDatasetTypes.includes(query.dataset?.type || '')) { - return new BehaviorSubject(false); + return of(false); } return getAvailableLanguages$(http, data).pipe(map((languages) => languages.length > 0)); },