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

[Query assistant]feat: add error callout when dataset is not supported #9232

Open
wants to merge 2 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/9232.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add error callout when dataset is not supported ([#9232](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9232))

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ const dependencies: QueryEditorExtensionDependencies = {
onSelectLanguage: jest.fn(),
isCollapsed: false,
setIsCollapsed: jest.fn(),
query: {
query: '',
language: '',
dataset: {
type: 'INDEX_PATTERN',
id: '',
title: '',
},
},
};

type Props = ComponentProps<typeof QueryAssistBar>;
Expand Down Expand Up @@ -227,4 +236,25 @@ describe('QueryAssistBar', () => {
});
expect(screen.getByTestId('query-assist-query-generated-callout')).toBeInTheDocument();
});

it('should render callout when dataset is not supported', async () => {
const { component } = renderQueryAssistBar({
dependencies: {
...dependencies,
query: {
query: '',
language: 'kuery',
dataset: {
id: 'foo',
title: 'mock',
type: 'S3',
},
},
},
});

await component.findByText(
'The selected datasource mock is not supported for Amazon Q query assistance. Please select another data source that is compatible.'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiFlexGroup, EuiFlexItem, EuiForm, EuiFormRow } from '@elastic/eui';
import { EuiCallOut, EuiFlexGroup, EuiFlexItem, EuiForm, EuiFormRow } from '@elastic/eui';
import React, { SyntheticEvent, useEffect, useMemo, useRef, useState } from 'react';
import { i18n } from '@osd/i18n';
import { Dataset } from '../../../../data/common';
import {
IDataPluginServices,
Expand All @@ -20,6 +21,7 @@ import { QueryAssistCallOut, QueryAssistCallOutType } from './call_outs';
import { QueryAssistInput } from './query_assist_input';
import { QueryAssistSubmitButton } from './submit_button';
import { useQueryAssist } from '../hooks';
import { PPL_SUPPORT_DATASET_TYPES } from '../utils/constant';

interface QueryAssistInputProps {
dependencies: QueryEditorExtensionDependencies;
Expand Down Expand Up @@ -95,24 +97,47 @@ export const QueryAssistBar: React.FC<QueryAssistInputProps> = (props) => {

if (props.dependencies.isCollapsed || isQueryAssistCollapsed) return null;

const { dependencies } = props;

const datasetSupported = PPL_SUPPORT_DATASET_TYPES.includes(
dependencies.query.dataset?.type || ''
);

return (
<EuiForm component="form" onSubmit={onSubmit} className="queryAssist queryAssist__form">
<EuiFormRow fullWidth>
<EuiFlexGroup gutterSize="xs" responsive={false} alignItems="center">
<EuiFlexItem>
<QueryAssistInput
inputRef={inputRef}
persistedLog={persistedLog}
isDisabled={loading}
selectedIndex={selectedIndex}
previousQuestion={previousQuestionRef.current}
error={agentError}
<>
<EuiFlexGroup gutterSize="xs" responsive={false} alignItems="center">
<EuiFlexItem>
<QueryAssistInput
inputRef={inputRef}
persistedLog={persistedLog}
isDisabled={loading || !datasetSupported}
selectedIndex={selectedIndex}
previousQuestion={previousQuestionRef.current}
error={agentError}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<QueryAssistSubmitButton isDisabled={loading || !datasetSupported} />
</EuiFlexItem>
</EuiFlexGroup>
{!datasetSupported && dependencies.query.dataset?.title ? (
<EuiCallOut
color="danger"
iconType="alert"
title={i18n.translate('queryEnhancements.query_assist_bar.unsupported.dataset', {
defaultMessage:
'The selected datasource {datasource} is not supported for Amazon Q query assistance. Please select another data source that is compatible.',
values: {
datasource: dependencies.query.dataset.title,
},
})}
size="s"
data-test-subj="queryAssistUnsupportedDataset"
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<QueryAssistSubmitButton isDisabled={loading} />
</EuiFlexItem>
</EuiFlexGroup>
) : null}
</>
</EuiFormRow>
<QueryAssistCallOut
language={props.dependencies.language}
Expand Down
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 PPL_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 @@ -26,6 +26,7 @@ import {
import { UsageCollectionSetup } from '../../../../usage_collection/public';
import { QueryAssistContext } from '../hooks/use_query_assist';
import { CoreSetup } from '../../../../../core/public';
import { PPL_SUPPORT_DATASET_TYPES } from './constant';

const [getAvailableLanguagesForDataSource, clearCache] = (() => {
const availableLanguagesByDataSource: Map<string | undefined, string[]> = new Map();
Expand Down Expand Up @@ -84,7 +85,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
!PPL_SUPPORT_DATASET_TYPES.includes(query.dataset?.type || '')
)
return [];

Expand Down
Loading