Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type EditableSavedSearchAttributes = Partial<
Pick<SavedSearchAttributes, (typeof EDITABLE_SAVED_SEARCH_KEYS)[number]>
>;

type SearchEmbeddableBaseState = SerializedTitles &
export type SearchEmbeddableBaseState = SerializedTitles &
SerializedTimeRange &
SerializedDrilldowns &
EditableSavedSearchAttributes & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import type { SearchResponseIncompleteWarning } from '@kbn/search-response-warnings/src/types';
import type { DocViewFilterFn } from '@kbn/unified-doc-viewer/types';
import { ON_APPLY_FILTER, ON_OPEN_PANEL_MENU } from '@kbn/ui-actions-plugin/common/trigger_ids';
import { getSearchEmbeddableDefaults } from './get_search_embeddable_defaults';
import {
getDiscoverSessionEmbeddableComparators,
getSearchEmbeddableComparators,
} from './utils/get_search_embeddable_comparators';
import type { DiscoverServices } from '../build_services';
import { SearchEmbeddablFieldStatsTableComponent } from './components/search_embeddable_field_stats_table_component';
import { SearchEmbeddableGridComponent } from './components/search_embeddable_grid_component';
Expand All @@ -43,7 +48,6 @@ import type { SearchEmbeddableApi, SearchEmbeddablePanelApiState } from './types
import { deserializeState, serializeState } from './utils/serialization_utils';
import { ScopedServicesProvider } from '../components/scoped_services_provider';
import { isFieldStatsMode } from './utils/is_field_stats_mode';
import { compareSelectedTabId } from './utils/compare_selected_tab_id';
import { isTabDeleted } from './utils/is_tab_deleted';

export const getSearchEmbeddableFactory = ({
Expand Down Expand Up @@ -100,8 +104,14 @@ export const getSearchEmbeddableFactory = ({

const tabs = runtimeState.tabs ?? [];

const isSelectedTabDeleted = (tabId: string | undefined, availableTabs: typeof tabs = tabs) =>
isTabDeleted(tabId, availableTabs);
const defaultState = embeddableTransformsEnabled
? { selected_tab_id: tabs[0]?.id }
: {
selectedTabId: tabs[0]?.id,
sort: [],
grid: {},
...getSearchEmbeddableDefaults(discoverServices.uiSettings),
};

/** All other state */
const blockingError$ = new BehaviorSubject<Error | undefined>(undefined);
Expand Down Expand Up @@ -145,6 +155,7 @@ export const getSearchEmbeddableFactory = ({
const unsavedChangesApi = initializeUnsavedChanges<SearchEmbeddablePanelApiState>({
uuid,
parentApi,
defaultState,
serializeState: () => serialize(savedObjectId$.getValue()),
anyStateChange$: merge(
drilldownsManager.anyStateChange$,
Expand All @@ -158,52 +169,18 @@ export const getSearchEmbeddableFactory = ({
inlineEditingApi.anyStateChange$
),
getComparators: () => {
const isDeleted = isSelectedTabDeleted(selectedTabId$.getValue());
const shouldSkipTabComparators = isDeleted || inlineEditingApi.isEditing();

if (embeddableTransformsEnabled) {
const isByValue = !savedObjectId$.getValue();
return {
...drilldownsManager.comparators,
...titleComparators,
...timeRangeComparators,
ref_id: 'skip',
selected_tab_id: shouldSkipTabComparators ? 'skip' : 'referenceEquality',
overrides: shouldSkipTabComparators ? 'skip' : 'deepEquality',
tabs: !isByValue || shouldSkipTabComparators ? 'skip' : 'deepEquality',
};
}
const isByValue = !savedObjectId$.getValue();
const shouldSkipTabComparators =
isTabDeleted(selectedTabId$.getValue(), tabs) || inlineEditingApi.isEditing();

return {
...drilldownsManager.comparators,
...titleComparators,
...timeRangeComparators,
...searchEmbeddable.comparators,
// While the selected tab is missing or inline editing is in progress,
// skip tab-dependent comparators so unsaved-changes badges don't appear
// until the user explicitly applies a tab change.
...(shouldSkipTabComparators
? Object.fromEntries(
Object.keys(searchEmbeddable.comparators).map((k) => [k, 'skip'])
)
: {}),
Comment on lines -182 to -189
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.

Do you know if removing this logic has any actual impact?

selectedTabId: shouldSkipTabComparators
? 'skip'
: (last, current) => compareSelectedTabId(tabs[0]?.id, last, current),
attributes: 'skip',
breakdownField: 'skip',
hideAggregatedPreview: 'skip',
hideChart: 'skip',
isTextBasedQuery: 'skip',
kibanaSavedObjectMeta: 'skip',
...(embeddableTransformsEnabled
? getDiscoverSessionEmbeddableComparators(isByValue, shouldSkipTabComparators)
: getSearchEmbeddableComparators(isByValue, shouldSkipTabComparators)),
nonPersistedDisplayOptions: 'skip',
refreshInterval: 'skip',
savedObjectId: 'skip',
timeRestore: 'skip',
usesAdHocDataView: 'skip',
controlGroupJson: 'skip',
visContext: 'skip',
tabs: 'skip',
};
},
onReset: async (lastSaved) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { DataTableRecord } from '@kbn/discover-utils/types';
import type {
PublishesWritableUnifiedSearch,
PublishesWritableDataViews,
StateComparators,
ProjectRoutingOverrides,
PublishesProjectRoutingOverrides,
} from '@kbn/presentation-publishing';
Expand All @@ -38,7 +37,6 @@ import { SavedObjectNotFound } from '@kbn/kibana-utils-plugin/common';
import { getEsqlDataView } from '@kbn/discover-utils';
import type { DiscoverServices } from '../build_services';
import { EDITABLE_SAVED_SEARCH_KEYS } from '../../common/embeddable/constants';
import { getSearchEmbeddableDefaults } from './get_search_embeddable_defaults';
import type {
PublishesWritableSavedSearch,
SearchEmbeddableSerializedAttributes,
Expand Down Expand Up @@ -118,7 +116,6 @@ export const initializeSearchEmbeddableApi = async ({
PublishesProjectRoutingOverrides;
stateManager: SearchEmbeddableStateManager;
anyStateChange$: Observable<void>;
comparators: StateComparators<SearchEmbeddableSerializedAttributes>;
cleanup: () => void;
reinitializeState: (lastSaved: SearchEmbeddableSerializedAttributes) => Promise<void>;
}> => {
Expand All @@ -130,8 +127,6 @@ export const initializeSearchEmbeddableApi = async ({
const searchSource$ = new BehaviorSubject<ISearchSource>(searchSource);
const dataViews$ = new BehaviorSubject<DataView[] | undefined>(dataView ? [dataView] : undefined);

const defaults = getSearchEmbeddableDefaults(discoverServices.uiSettings);

/** This is the state that can be initialized from the saved initial state */
const columns$ = new BehaviorSubject<string[] | undefined>(initialState.columns);
const grid$ = new BehaviorSubject<DiscoverGridSettings | undefined>(initialState.grid);
Expand Down Expand Up @@ -295,19 +290,6 @@ export const initializeSearchEmbeddableApi = async ({
},
stateManager,
anyStateChange$: onAnyStateChange.pipe(map(() => undefined)),
comparators: {
sort: (a, b) => deepEqual(a ?? [], b ?? []),
columns: 'deepEquality',
grid: (a, b) => deepEqual(a ?? {}, b ?? {}),
sampleSize: (a, b) => (a ?? defaults.sampleSize) === (b ?? defaults.sampleSize),
rowsPerPage: (a, b) => (a ?? defaults.rowsPerPage) === (b ?? defaults.rowsPerPage),
rowHeight: (a, b) => (a ?? defaults.rowHeight) === (b ?? defaults.rowHeight),
headerRowHeight: (a, b) =>
(a ?? defaults.headerRowHeight) === (b ?? defaults.headerRowHeight),
serializedSearchSource: 'referenceEquality',
viewMode: 'referenceEquality',
density: 'referenceEquality',
},
reinitializeState,
};
};

This file was deleted.

This file was deleted.

Loading
Loading