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 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..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 { @@ -93,6 +93,11 @@ const getAvailableLanguages$ = (http: HttpSetup, data: DataPublicPluginSetup) => }) ); +const queryAssistantSupportedDatasetTypes = [ + DEFAULT_DATA.SET_TYPES.INDEX, + DEFAULT_DATA.SET_TYPES.INDEX_PATTERN, +]; + export const createQueryAssistExtension = ( core: CoreSetup, data: DataPublicPluginSetup, @@ -119,8 +124,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 of(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 (