diff --git a/packages/kbn-es-query/src/filters/helpers/only_disabled.ts b/packages/kbn-es-query/src/filters/helpers/only_disabled.ts index d605d8b0be628..73ffc146bae88 100644 --- a/packages/kbn-es-query/src/filters/helpers/only_disabled.ts +++ b/packages/kbn-es-query/src/filters/helpers/only_disabled.ts @@ -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); }; diff --git a/src/plugins/dashboard/public/dashboard_container/embeddable/integrations/diff_state/dashboard_diffing_functions.ts b/src/plugins/dashboard/public/dashboard_container/embeddable/integrations/diff_state/dashboard_diffing_functions.ts index 59c5fdfca3334..375b03b73b3f4 100644 --- a/src/plugins/dashboard/public/dashboard_container/embeddable/integrations/diff_state/dashboard_diffing_functions.ts +++ b/src/plugins/dashboard/public/dashboard_container/embeddable/integrations/diff_state/dashboard_diffing_functions.ts @@ -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), }; diff --git a/src/plugins/dashboard/public/dashboard_container/embeddable/integrations/diff_state/dashboard_diffing_integration.test.ts b/src/plugins/dashboard/public/dashboard_container/embeddable/integrations/diff_state/dashboard_diffing_integration.test.ts index 65cf2ad39cca4..ca17780f3e803 100644 --- a/src/plugins/dashboard/public/dashboard_container/embeddable/integrations/diff_state/dashboard_diffing_integration.test.ts +++ b/src/plugins/dashboard/public/dashboard_container/embeddable/integrations/diff_state/dashboard_diffing_integration.test.ts @@ -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); + }); });