Skip to content
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 @@ -416,6 +416,17 @@ export const internalStateSlice = createSlice({
}),
},

setProfileStateFieldsToResetWithoutResetId: (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better a new action that represents a semantic exception than a flag on the previous action.

state,
action: TabAction<Pick<TabState['defaultProfileState'], 'fieldsToReset'>>
) =>
withTab(state, action.payload, (tab) => {
tab.defaultProfileState = {
...tab.defaultProfileState,
fieldsToReset: action.payload.fieldsToReset,
};
}),

resetOnSavedSearchChange: (state, action: TabAction) =>
withTab(state, action.payload, (tab) => {
tab.overriddenVisContextAfterInvalidation = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,32 @@ describe('buildEsqlFetchSubscribe', () => {
});
});

test('should keep resetId stable when a transformational fetch requests a columns reset', async () => {
const { toolkit, dataState } = await setupTest({});
const documents$ = dataState.data$.documents$;

documents$.next(msgComplete);

const prevDefaultProfileState = toolkit.getCurrentTab().defaultProfileState;

documents$.next({
fetchStatus: FetchStatus.PARTIAL,
result: [
{
id: '1',
raw: { field1: 1 },
flattened: { field1: 1 },
} as unknown as DataTableRecord,
],
query: { esql: 'from the-data-view-title | keep field1' },
});

const nextDefaultProfileState = toolkit.getCurrentTab().defaultProfileState;

expect(nextDefaultProfileState.fieldsToReset).toEqual(['columns']);
expect(nextDefaultProfileState.resetId).toBe(prevDefaultProfileState.resetId);
});

test('changing an ES|QL query with same result columns but a different index pattern should change state when loading and finished', async () => {
const { replaceUrlState, dataState, tabId } = await setupTest({});
const documents$ = dataState.data$.documents$;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ export const buildEsqlFetchSubscribe = ({

const { viewMode } = getCurrentTab().appState;
const changeViewMode = viewMode !== getValidViewMode({ viewMode, isEsqlMode: true });

// If the index pattern hasn't changed, but the available columns have changed
// due to transformational commands, mark the associated profile state fields to reset
if (!indexPatternChanged && allColumnsChanged) {
internalState.dispatch(
injectCurrentTab(internalStateActions.setProfileStateFieldsToReset)({
// This reset comes from the current fetch, so keep the same resetId.
// Otherwise the snapshot taken at fetch start looks stale when cleanup runs.
injectCurrentTab(internalStateActions.setProfileStateFieldsToResetWithoutResetId)({
Comment on lines +159 to +161
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went down the rabbit hole on this and funny enough, it seems like this is likely dead code anyway (other than the bug 🙃). Not certain yet so these changes are good for now until we investigate, but opened a separate issue for it here: #264870.

fieldsToReset: ['columns'],
})
);
Expand Down
Loading