Skip to content

Commit

Permalink
feat: update discover summary UX
Browse files Browse the repository at this point in the history
It will only auto-trigger the summary generating the first time a ppl
query was generated. The following summary generation requires user to
click a "Generate summary" button.

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
  • Loading branch information
ruanyl committed Oct 24, 2024
1 parent 12d072d commit 943741e
Show file tree
Hide file tree
Showing 8 changed files with 655 additions and 434 deletions.

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

9 changes: 9 additions & 0 deletions src/plugins/data/public/search/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* under the License.
*/

import { BehaviorSubject } from 'rxjs';
import { IDataFrame } from '../../common';
import { searchAggsSetupMock, searchAggsStartMock } from './aggs/mocks';
import { searchSourceMock } from './search_source/mocks';
import { ISearchSetup, ISearchStart } from './types';
Expand All @@ -37,6 +39,12 @@ function createSetupContract(): jest.Mocked<ISearchSetup> {
aggs: searchAggsSetupMock(),
__enhance: jest.fn(),
getDefaultSearchInterceptor: jest.fn(),
df: {
get: jest.fn().mockReturnValue({}),
set: jest.fn().mockReturnValue({}),
clear: jest.fn(),
df$: new BehaviorSubject<IDataFrame | undefined>(undefined),
},
};
}

Expand All @@ -52,6 +60,7 @@ function createStartContract(): jest.Mocked<ISearchStart> {
get: jest.fn().mockReturnValue({}),
set: jest.fn().mockReturnValue({}),
clear: jest.fn(),
df$: new BehaviorSubject<IDataFrame | undefined>(undefined),
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jest.mock('../hooks', () => ({
useGenerateQuery: jest.fn().mockReturnValue({ generateQuery: jest.fn(), loading: false }),
useQueryAssist: jest
.fn()
.mockReturnValue({ updateQuestion: jest.fn(), isQueryAssistCollapsed: false }),
.mockReturnValue({ updateQueryState: jest.fn(), isQueryAssistCollapsed: false }),
}));

jest.mock('./query_assist_input', () => ({
Expand Down Expand Up @@ -91,7 +91,10 @@ describe('QueryAssistBar', () => {
});

it('renders null if question assist is collapsed', () => {
useQueryAssist.mockReturnValueOnce({ updateQuestion: jest.fn(), isQueryAssistCollapsed: true });
useQueryAssist.mockReturnValueOnce({
updateQueryState: jest.fn(),
isQueryAssistCollapsed: true,
});
const { component } = renderQueryAssistBar({
dependencies: { ...dependencies, isCollapsed: false },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const QueryAssistBar: React.FC<QueryAssistInputProps> = (props) => {
);
const selectedIndex = selectedDataset?.title;
const previousQuestionRef = useRef<string>();
const { updateQuestion, isQueryAssistCollapsed } = useQueryAssist();
const { isQueryAssistCollapsed, updateQueryState } = useQueryAssist();

useEffect(() => {
const subscription = queryString.getUpdates$().subscribe((query) => {
Expand All @@ -66,7 +66,6 @@ export const QueryAssistBar: React.FC<QueryAssistInputProps> = (props) => {
setAgentError(undefined);
previousQuestionRef.current = inputRef.current.value;
persistedLog.add(inputRef.current.value);
updateQuestion(inputRef.current.value);
const params: QueryAssistParameters = {
question: inputRef.current.value,
index: selectedIndex,
Expand All @@ -88,6 +87,7 @@ export const QueryAssistBar: React.FC<QueryAssistInputProps> = (props) => {
language: params.language,
dataset: selectedDataset,
});
updateQueryState({ question: previousQuestionRef.current, answer: response.query });
if (response.timeRange) services.data.query.timefilter.timefilter.setTime(response.timeRange);
setCallOutType('query_generated');
}
Expand Down
Loading

0 comments on commit 943741e

Please sign in to comment.