Skip to content

Commit

Permalink
feat: disable query assistant when dataset type is not supported
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Jan 23, 2025
1 parent 11918b6 commit 2f954e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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 @@ -88,6 +88,8 @@ const getAvailableLanguages$ = (http: HttpSetup, data: DataPublicPluginSetup) =>
})
);

const queryAssistantSupportedDatasetTypes = ['INDEXES', 'INDEX_PATTERN'];

export const createQueryAssistExtension = (
core: CoreSetup,
data: DataPublicPluginSetup,
Expand Down Expand Up @@ -115,8 +117,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 (
Expand Down

0 comments on commit 2f954e9

Please sign in to comment.