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

Disable query assistant when dataset type is not supported #9157

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/9157.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Disable query assistant when dataset type is not supported ([#9157](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9157))
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { DEFAULT_DATA } from '../../../../data/common';

export const DATA2SUMMARY_AGENT_CONFIG_ID = 'os_data2summary';

export const QUERY_ASSISTANT_SUPPORT_DATASET_TYPES = [
DEFAULT_DATA.SET_TYPES.INDEX,
DEFAULT_DATA.SET_TYPES.INDEX_PATTERN,
];
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,6 +21,7 @@ import { QueryAssistBanner, QueryAssistBar, QueryAssistSummary } from '../compon
import { UsageCollectionSetup } from '../../../../usage_collection/public';
import { QueryAssistContext } from '../hooks/use_query_assist';
import { CoreSetup } from '../../../../../core/public';
import { QUERY_ASSISTANT_SUPPORT_DATASET_TYPES } from './constant';

const [getAvailableLanguagesForDataSource, clearCache] = (() => {
const availableLanguagesByDataSource: Map<string | undefined, string[]> = new Map();
Expand Down Expand Up @@ -79,7 +80,7 @@ const getAvailableLanguages$ = (http: HttpSetup, data: DataPublicPluginSetup) =>
if (
query.dataset?.dataSource?.type !== DEFAULT_DATA.SOURCE_TYPES.OPENSEARCH && // datasource is MDS OpenSearch
query.dataset?.dataSource?.type !== 'DATA_SOURCE' && // datasource is MDS OpenSearch when using indexes
query.dataset?.type !== DEFAULT_DATA.SET_TYPES.INDEX_PATTERN // dataset is index pattern
!QUERY_ASSISTANT_SUPPORT_DATASET_TYPES.includes(query.dataset?.type || '')
)
return [];

Expand Down Expand Up @@ -115,8 +116,13 @@ export const createQueryAssistExtension = (
};
}
},
isEnabled$: () =>
getAvailableLanguages$(http, data).pipe(map((languages) => languages.length > 0)),
isEnabled$: (dependencies) => {
const query = dependencies.query;
if (!QUERY_ASSISTANT_SUPPORT_DATASET_TYPES.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 (
Expand Down
Loading