Skip to content

Commit

Permalink
[Dashboard] Fixes Copy to dashboard includes filters. (#136275)
Browse files Browse the repository at this point in the history
* Fixed applying of the pinned filters.

* Filtered unrelated filters to dashboard with saving the filters state.

* Added handling filters from bwc urls.

* Changed the code, according to the nit.

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
Kuznietsov and kibanamachine authored Jul 19, 2022
1 parent 1a1ecc1 commit 568e631
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const createDashboardAppStateServices = () => {

const data = dataPluginMock.createStartContract();
data.query.filterManager.getUpdates$ = jest.fn().mockImplementation(() => of(void 0));
data.query.filterManager.getFilters = jest.fn().mockImplementation(() => []);
data.query.queryString.getUpdates$ = jest.fn().mockImplementation(() => of({}));
data.query.timefilter.timefilter.getTimeUpdate$ = jest.fn().mockImplementation(() => of(void 0));
data.query.timefilter.timefilter.getRefreshIntervalUpdate$ = jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
import _ from 'lodash';
import type { KibanaExecutionContext } from '@kbn/core/public';
import { ControlGroupInput } from '@kbn/controls-plugin/public';
import {
compareFilters,
isFilterPinned,
migrateFilter,
COMPARE_ALL_OPTIONS,
type Filter,
} from '@kbn/es-query';
import { DashboardSavedObject } from '../../saved_dashboards';
import { getTagsFromSavedDashboard, migrateAppState } from '.';
import { EmbeddablePackageState, ViewMode } from '../../services/embeddable';
Expand Down Expand Up @@ -110,11 +117,20 @@ export const stateToDashboardContainerInput = ({
query,
title,
timeRestore,
filters: dashboardFilters,
} = dashboardState;

return {
refreshConfig: timefilter.getRefreshInterval(),
filters: filterManager.getFilters(),
filters: filterManager
.getFilters()
.filter(
(filter) =>
isFilterPinned(filter) ||
dashboardFilters.some((dashboardFilter) =>
filtersAreEqual(migrateFilter(_.cloneDeep(dashboardFilter)), filter)
)
),
isFullScreenMode: fullScreenMode,
id: savedDashboard.id || '',
dashboardCapabilities,
Expand All @@ -136,6 +152,9 @@ export const stateToDashboardContainerInput = ({
};
};

const filtersAreEqual = (first: Filter, second: Filter) =>
compareFilters(first, second, { ...COMPARE_ALL_OPTIONS, state: false });

/**
* Converts a given dashboard state object to raw dashboard state. This is useful for sharing, and session restoration, as
* they require panels to be formatted as an array.
Expand Down

0 comments on commit 568e631

Please sign in to comment.