Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
} from '@kbn/discover-plugin/public';
import { SerializedPanelState } from '@kbn/presentation-publishing';
import { css } from '@emotion/react';
import { SavedSearchAttributes } from '@kbn/saved-search-plugin/common';
import { SavedSearchComponentProps } from '../types';
import { SavedSearchComponentErrorContent } from './error';

Expand All @@ -36,6 +37,7 @@ export const SavedSearchComponent: React.FC<SavedSearchComponentProps> = (props)
filters,
index,
timestampField,
columns,
height,
} = props;

Expand Down Expand Up @@ -65,10 +67,11 @@ export const SavedSearchComponent: React.FC<SavedSearchComponentProps> = (props)
searchSource.setField('filter', filters);
const { searchSourceJSON, references } = searchSource.serialize();
// By-value saved object structure
const attributes = {
const attributes: Partial<SavedSearchAttributes> = {
kibanaSavedObjectMeta: {
searchSourceJSON,
},
columns,
};
setInitialSerializedState({
rawState: {
Expand All @@ -94,6 +97,7 @@ export const SavedSearchComponent: React.FC<SavedSearchComponentProps> = (props)
abortController.abort();
};
}, [
columns,
dataViews,
documentViewerEnabled,
filters,
Expand Down Expand Up @@ -137,6 +141,7 @@ const SavedSearchComponentTable: React.FC<
timeRange,
timestampField,
index,
columns,
} = props;
const embeddableApi = useRef<SearchEmbeddableApi | undefined>(undefined);

Expand Down Expand Up @@ -198,6 +203,14 @@ const SavedSearchComponentTable: React.FC<
[timeRange]
);

useEffect(
function syncColumns() {
if (!embeddableApi.current) return;
embeddableApi.current.setColumns(columns);
},
[columns]
);

return (
<EmbeddableRenderer<SearchEmbeddableSerializedState, SearchEmbeddableApi>
maybeId={undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface SavedSearchComponentProps {
query?: Query;
filters?: Filter[];
timestampField?: string;
columns?: string[];
height?: CSSProperties['height'];
displayOptions?: NonPersistedDisplayOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"@kbn/discover-plugin",
"@kbn/i18n",
"@kbn/presentation-publishing",
"@kbn/saved-search-plugin",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { DiscoverServices } from '../build_services';
import { EDITABLE_SAVED_SEARCH_KEYS } from './constants';
import { getSearchEmbeddableDefaults } from './get_search_embeddable_defaults';
import type {
PublishesSavedSearch,
PublishesWritableSavedSearch,
SearchEmbeddableRuntimeState,
SearchEmbeddableSerializedAttributes,
SearchEmbeddableSerializedState,
Expand Down Expand Up @@ -73,7 +73,9 @@ export const initializeSearchEmbeddableApi = async (
discoverServices: DiscoverServices;
}
): Promise<{
api: PublishesSavedSearch & PublishesWritableDataViews & Partial<PublishesWritableUnifiedSearch>;
api: PublishesWritableSavedSearch &
PublishesWritableDataViews &
Partial<PublishesWritableUnifiedSearch>;
stateManager: SearchEmbeddableStateManager;
anyStateChange$: Observable<void>;
comparators: StateComparators<SearchEmbeddableSerializedAttributes>;
Expand Down Expand Up @@ -170,6 +172,10 @@ export const initializeSearchEmbeddableApi = async (
searchSource$.next(searchSource);
};

const setColumns = (columns: string[] | undefined) => {
stateManager.columns.next(columns);
};
Comment on lines +175 to +177
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.

just for my understanding here, we are calling this from saved_search, and I guess this is an observable which already has some subscribers. So this change propagates the new columns to the subscribers from the saved search?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes your understanding is accurate! But specifically in this case the subscribers are other areas of the embeddable that use these observables for state management. Essentially changes are propagated throughout the saved search embeddable, so things like the UI are updated and any other functionality that depends on the state has the latest values.


/** Keep the saved search in sync with any state changes */
const syncSavedSearch = combineLatest([onAnyStateChange, searchSource$])
.pipe(
Expand Down Expand Up @@ -197,6 +203,7 @@ export const initializeSearchEmbeddableApi = async (
query$,
setQuery,
canEditUnifiedSearch,
setColumns,
},
stateManager,
anyStateChange$: onAnyStateChange.pipe(map(() => undefined)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export type SearchEmbeddableApi = DefaultEmbeddableApi<SearchEmbeddableSerialize
PublishesBlockingError &
Required<PublishesWritableTitle> &
Required<PublishesDescription> &
PublishesSavedSearch &
PublishesWritableSavedSearch &
PublishesWritableDataViews &
PublishesWritableUnifiedSearch &
HasLibraryTransforms &
Expand All @@ -119,6 +119,10 @@ export interface PublishesSavedSearch {
savedSearch$: PublishingSubject<SavedSearch>;
}

export interface PublishesWritableSavedSearch extends PublishesSavedSearch {
setColumns: (columns: string[] | undefined) => void;
}

export const apiPublishesSavedSearch = (
api: EmbeddableApiContext['embeddable']
): api is PublishesSavedSearch => {
Expand Down
1 change: 1 addition & 0 deletions src/platform/plugins/shared/discover/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export {
SEARCH_EMBEDDABLE_CELL_ACTIONS_TRIGGER_ID,
apiPublishesSavedSearch,
type PublishesSavedSearch,
type PublishesWritableSavedSearch,
type HasTimeRange,
type SearchEmbeddableSerializedState,
type SearchEmbeddableRuntimeState,
Expand Down