Skip to content

Commit

Permalink
do not refresh on pin/unpin action
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Feb 16, 2023
1 parent 97dbb7f commit 7abb62a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/filters/helpers/only_disabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const isEnabled = (f: Filter) => f && f.meta && !f.meta.disabled;
*
* @public
*/
export const onlyDisabledFiltersChanged = (newFilters?: Filter[], oldFilters?: Filter[]) => {
export const onlyDisabledFiltersChanged = (newFilters?: Filter[], oldFilters?: Filter[], comparatorOptions?: FilterCompareOptions = COMPARE_ALL_OPTIONS) => {
// If it's the same - compare only enabled filters
const newEnabledFilters = filter(newFilters || [], isEnabled);
const oldEnabledFilters = filter(oldFilters || [], isEnabled);

return compareFilters(oldEnabledFilters, newEnabledFilters, COMPARE_ALL_OPTIONS);
return compareFilters(oldEnabledFilters, newEnabledFilters, comparatorOptions);
};
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ export const unsavedChangesDiffingFunctions: DashboardDiffFunctions = {
viewMode: () => false, // When compared view mode is always considered unequal so that it gets backed up.
};

const shouldRefreshFilterCompareOptions = {
...COMPARE_ALL_OPTIONS,
// do not compare $state to avoid refreshing when filter is pinned/unpinned (which does not impact results)
state: false,
};

export const shouldRefreshDiffingFunctions: DashboardDiffFunctions = {
...unsavedChangesDiffingFunctions,
filters: ({ currentValue, lastValue }) => onlyDisabledFiltersChanged(currentValue, lastValue),
filters: ({ currentValue, lastValue }) =>
onlyDisabledFiltersChanged(lastValue, currentValue, shouldRefreshFilterCompareOptions),
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ describe('getShouldRefresh', () => {
};
expect(await getShouldRefresh.bind(dashboardContainerMock)(lastInput, input)).toBe(false);
});

test('should return false when pinned filter changes to unpinned', async () => {
const lastInput = {
filters: [existsFilter],
};
const input = {
filters: [pinFilter(existsFilter)],
};
expect(await getShouldRefresh.bind(dashboardContainerMock)(lastInput, input)).toBe(false);
});
});

0 comments on commit 7abb62a

Please sign in to comment.