diff --git a/src/plugins/dashboard/public/dashboard_container/state/dashboard_container_reducers.ts b/src/plugins/dashboard/public/dashboard_container/state/dashboard_container_reducers.ts index fee2d80939686..47849a4946ff3 100644 --- a/src/plugins/dashboard/public/dashboard_container/state/dashboard_container_reducers.ts +++ b/src/plugins/dashboard/public/dashboard_container/state/dashboard_container_reducers.ts @@ -250,4 +250,8 @@ export const dashboardContainerReducers = { setDisableAutoRefresh: (state: DashboardReduxState, action: PayloadAction) => { state.componentState.disableAutoRefresh = action.payload; }, + + setDisableFilters: (state: DashboardReduxState, action: PayloadAction) => { + state.componentState.disableFilters = action.payload; + }, }; diff --git a/src/plugins/dashboard/public/dashboard_container/state/diffing/dashboard_diffing_integration.ts b/src/plugins/dashboard/public/dashboard_container/state/diffing/dashboard_diffing_integration.ts index e626c98c4321d..8bf60bbd4d43d 100644 --- a/src/plugins/dashboard/public/dashboard_container/state/diffing/dashboard_diffing_integration.ts +++ b/src/plugins/dashboard/public/dashboard_container/state/diffing/dashboard_diffing_integration.ts @@ -32,6 +32,7 @@ export const reducersToIgnore: Array = 'setHasUnsavedChanges', 'setDisableQueryInput', 'setDisableAutoRefresh', + 'setDisableFilters', ]; /** diff --git a/src/plugins/dashboard/public/dashboard_container/types.ts b/src/plugins/dashboard/public/dashboard_container/types.ts index 64dc9cee28497..68c89d9c269b7 100644 --- a/src/plugins/dashboard/public/dashboard_container/types.ts +++ b/src/plugins/dashboard/public/dashboard_container/types.ts @@ -55,6 +55,7 @@ export interface DashboardPublicState { disableQueryInput?: boolean; disableAutoRefresh?: boolean; + disableFilters?: boolean; } export type DashboardLoadType = diff --git a/src/plugins/dashboard/public/dashboard_top_nav/internal_dashboard_top_nav.tsx b/src/plugins/dashboard/public/dashboard_top_nav/internal_dashboard_top_nav.tsx index 0f07afde9339f..33ab4153fe37f 100644 --- a/src/plugins/dashboard/public/dashboard_top_nav/internal_dashboard_top_nav.tsx +++ b/src/plugins/dashboard/public/dashboard_top_nav/internal_dashboard_top_nav.tsx @@ -95,6 +95,7 @@ export function InternalDashboardTopNav({ ); const disableQueryInput = dashboard.select((state) => state.componentState.disableQueryInput); const disableAutoRefresh = dashboard.select((state) => state.componentState.disableAutoRefresh); + const disableFilters = dashboard.select((state) => state.componentState.disableFilters); const hasUnsavedChanges = dashboard.select((state) => state.componentState.hasUnsavedChanges); const fullScreenMode = dashboard.select((state) => state.componentState.fullScreenMode); const savedQueryId = dashboard.select((state) => state.componentState.savedQueryId); @@ -341,6 +342,7 @@ export function InternalDashboardTopNav({ : setHeaderActionMenu } disableQueryInput={disableQueryInput} + showFilterBar={!disableFilters} disableAutoRefresh={disableAutoRefresh} className={fullScreenMode ? 'kbnTopNavMenu-isFullScreen' : undefined} config={ diff --git a/src/plugins/discover/public/embeddable/components/editor/saved_search_editor_dataview.tsx b/src/plugins/discover/public/embeddable/components/editor/saved_search_editor_dataview.tsx index 76e065ecaed71..35323f5c2931e 100644 --- a/src/plugins/discover/public/embeddable/components/editor/saved_search_editor_dataview.tsx +++ b/src/plugins/discover/public/embeddable/components/editor/saved_search_editor_dataview.tsx @@ -7,6 +7,7 @@ */ import React, { useCallback, useEffect, useRef, useState } from 'react'; +import deepEqual from 'react-fast-compare'; import { debounceTime } from 'rxjs'; import { EuiPanel } from '@elastic/eui'; @@ -97,7 +98,7 @@ export function SavedSearchDataviewEditor({ .pipe(debounceTime(1)) .subscribe(() => { const newTimeRange = services.timefilter.getTime(); - api.setTimeRange(newTimeRange); + api.setTimeRange(deepEqual(originalTime, newTimeRange) ? undefined : newTimeRange); }); return () => { diff --git a/src/plugins/discover/public/embeddable/components/editor/saved_search_editor_esql.tsx b/src/plugins/discover/public/embeddable/components/editor/saved_search_editor_esql.tsx index 9c25f486edf2c..87690fa2c995f 100644 --- a/src/plugins/discover/public/embeddable/components/editor/saved_search_editor_esql.tsx +++ b/src/plugins/discover/public/embeddable/components/editor/saved_search_editor_esql.tsx @@ -7,11 +7,12 @@ */ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import deepEqual from 'react-fast-compare'; import { debounceTime } from 'rxjs'; import { EuiPanel, EuiSpacer } from '@elastic/eui'; import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container'; -import { AggregateQuery, Filter, isOfAggregateQueryType } from '@kbn/es-query'; +import { AggregateQuery, isOfAggregateQueryType } from '@kbn/es-query'; import { useBatchedPublishingSubjects } from '@kbn/presentation-publishing'; import { TextBasedLangEditor } from '@kbn/text-based-languages/public'; import { @@ -58,20 +59,7 @@ export function SavedSearchEsqlEditor({ (api.parentApi as DashboardContainer).ignoreUnifiedSearch = true; (api.parentApi as DashboardContainer).dispatch.setDisableQueryInput(true); (api.parentApi as DashboardContainer).dispatch.setDisableAutoRefresh(true); - - /** Handle filters */ - const originalFilters = services.filterManager.getFilters(); - const customFilters = (savedSearch.searchSource.getOwnField('filter') ?? []) as Filter[]; - if (customFilters.length > 0) { - services.filterManager.setFilters(customFilters); - } - const filtersSubscription = services.filterManager - .getUpdates$() - .pipe(debounceTime(1)) - .subscribe(() => { - const newFilters = services.filterManager.getFilters(); - stateManager.searchSource.next(savedSearch.searchSource.setField('filter', newFilters)); - }); + (api.parentApi as DashboardContainer).dispatch.setDisableFilters(true); /** Handle time range */ const originalTime = services.timefilter.getTime(); @@ -84,17 +72,16 @@ export function SavedSearchEsqlEditor({ .pipe(debounceTime(1)) .subscribe(() => { const newTimeRange = services.timefilter.getTime(); - api.setTimeRange(newTimeRange); + api.setTimeRange(deepEqual(originalTime, newTimeRange) ? undefined : newTimeRange); }); return () => { - services.filterManager.setFilters(originalFilters); services.timefilter.setTime(originalTime); (api.parentApi as DashboardContainer).ignoreUnifiedSearch = false; (api.parentApi as DashboardContainer).dispatch.setDisableQueryInput(false); (api.parentApi as DashboardContainer).dispatch.setDisableAutoRefresh(false); - filtersSubscription.unsubscribe(); + (api.parentApi as DashboardContainer).dispatch.setDisableFilters(false); timeRangeSubscription.unsubscribe(); }; // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/plugins/discover/public/embeddable/get_search_embeddable_factory.tsx b/src/plugins/discover/public/embeddable/get_search_embeddable_factory.tsx index 68aa4f4de8560..aa1782a196253 100644 --- a/src/plugins/discover/public/embeddable/get_search_embeddable_factory.tsx +++ b/src/plugins/discover/public/embeddable/get_search_embeddable_factory.tsx @@ -162,6 +162,7 @@ export const getSearchEmbeddableFactory = ({ serializeState: async () => { const savedObjectId = savedObjectId$.getValue(); const updatedSavedSearch = searchEmbeddable.api.savedSearch$.getValue(); + console.log('timeRange.serialize()', timeRange.serialize()); if (savedObjectId && api.unsavedChanges.getValue()) { // update the saved object **only** if something changed await save({