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

[ES|QL] Resets selected columns when changing query #167492

Merged
merged 1 commit into from
Sep 29, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe('useTextBasedQueryLanguage', () => {
await waitFor(() => {
expect(replaceUrlState).toHaveBeenCalledWith({
index: 'the-data-view-id',
columns: [],
});
});

Expand All @@ -123,6 +124,7 @@ describe('useTextBasedQueryLanguage', () => {
expect(replaceUrlState).toHaveBeenCalledWith({
index: 'the-data-view-id',
viewMode: VIEW_MODE.DOCUMENT_LEVEL,
columns: [],
});
});
test('changing a text based query with different result columns should change state when loading and finished', async () => {
Expand Down Expand Up @@ -155,6 +157,35 @@ describe('useTextBasedQueryLanguage', () => {
});
});

test('changing a text based query with same result columns should change state when loading and finished', async () => {
const { replaceUrlState, stateContainer } = renderHookWithContext(false);
const documents$ = stateContainer.dataState.data$.documents$;
stateContainer.dataState.data$.documents$.next(msgComplete);
await waitFor(() => expect(replaceUrlState).toHaveBeenCalledTimes(1));
replaceUrlState.mockReset();

documents$.next({
recordRawType: RecordRawType.PLAIN,
fetchStatus: FetchStatus.PARTIAL,
result: [
{
id: '1',
raw: { field1: 1 },
flattened: { field1: 1 },
} as unknown as DataTableRecord,
],
query: { esql: 'from the-data-view-2' },
});
await waitFor(() => expect(replaceUrlState).toHaveBeenCalledTimes(1));

await waitFor(() => {
expect(replaceUrlState).toHaveBeenCalledWith({
index: 'the-data-view-id',
columns: [],
});
});
});

test('changing a text based query with no transformational commands should only change dataview state when loading and finished', async () => {
const { replaceUrlState, stateContainer } = renderHookWithContext(false);
const documents$ = stateContainer.dataState.data$.documents$;
Expand All @@ -180,6 +211,7 @@ describe('useTextBasedQueryLanguage', () => {
await waitFor(() => {
expect(replaceUrlState).toHaveBeenCalledWith({
index: 'the-data-view-id',
columns: [],
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function useTextBasedQueryLanguage({
}
const nextState = {
...(addDataViewToState && { index: dataViewObj.id }),
...(addColumnsToState && { columns: nextColumns }),
...((addColumnsToState || queryChanged) && { columns: nextColumns }),
...(viewMode === VIEW_MODE.AGGREGATED_LEVEL && {
viewMode: getValidViewMode({ viewMode, isTextBasedQueryMode: true }),
}),
Expand Down