From 7f670a7ad2a50fa340333345fb6bf73a7f1d5454 Mon Sep 17 00:00:00 2001 From: Davis McPhee Date: Wed, 8 Jan 2025 22:10:14 -0400 Subject: [PATCH 1/2] [Discover] Support overriding solutionNavId used for root profile resolution in embeddable --- packages/kbn-saved-search-component/README.md | 9 +++++-- .../src/components/saved_search.tsx | 3 +++ .../get_search_embeddable_factory.test.tsx | 25 +++++++++++++++++++ .../get_search_embeddable_factory.tsx | 6 ++--- .../discover/public/embeddable/types.ts | 1 + .../log_category_document_examples_table.tsx | 1 + .../components/app/service_logs/index.tsx | 1 + 7 files changed, 41 insertions(+), 5 deletions(-) diff --git a/packages/kbn-saved-search-component/README.md b/packages/kbn-saved-search-component/README.md index 61ec5a6cd8a90..f6662646a5662 100644 --- a/packages/kbn-saved-search-component/README.md +++ b/packages/kbn-saved-search-component/README.md @@ -2,7 +2,7 @@ A component wrapper around Discover session embeddable. This can be used in solutions without being within a Dasboard context. -This can be used to render a context-aware (logs etc) "document table". +This can be used to render a context-aware (logs etc) "document table". In the past you may have used the Log Stream Component to achieve this, this component supersedes that. @@ -22,5 +22,10 @@ import { LazySavedSearchComponent } from '@kbn/saved-search-component'; filters={optionalFilters} query={optionalQuery} timestampField={optionalTimestampFieldString} + displayOptions={{ + solutionNavIdOverride: 'oblt', + enableDocumentViewer: true, + enableFilters: false, + }} /> -``` \ No newline at end of file +``` diff --git a/packages/kbn-saved-search-component/src/components/saved_search.tsx b/packages/kbn-saved-search-component/src/components/saved_search.tsx index f5cf7cc2a59ab..5172d5c5e0210 100644 --- a/packages/kbn-saved-search-component/src/components/saved_search.tsx +++ b/packages/kbn-saved-search-component/src/components/saved_search.tsx @@ -41,6 +41,7 @@ export const SavedSearchComponent: React.FC = (props) } = props; const { + solutionNavIdOverride, enableDocumentViewer: documentViewerEnabled = true, enableFilters: filtersEnabled = true, } = props.displayOptions ?? {}; @@ -75,6 +76,7 @@ export const SavedSearchComponent: React.FC = (props) attributes: { ...attributes, references }, timeRange, nonPersistedDisplayOptions: { + solutionNavIdOverride, enableDocumentViewer: documentViewerEnabled, enableFilters: filtersEnabled, }, @@ -100,6 +102,7 @@ export const SavedSearchComponent: React.FC = (props) index, query, searchSourceService, + solutionNavIdOverride, timeRange, timestampField, ]); diff --git a/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.test.tsx b/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.test.tsx index 621703ad3991b..ad95f4f8cae6f 100644 --- a/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.test.tsx +++ b/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.test.tsx @@ -244,6 +244,31 @@ describe('saved search embeddable', () => { expect(resolveRootProfileSpy).not.toHaveBeenCalled(); }); + it('should allow overriding the solutionNavId used to resolve the root profile', async () => { + const resolveRootProfileSpy = jest.spyOn( + discoverServiceMock.profilesManager, + 'resolveRootProfile' + ); + const initialRuntimeState = { + ...getInitialRuntimeState(), + nonPersistedDisplayOptions: { + solutionNavIdOverride: 'override-solution-nav-id', + }, + }; + await factory.buildEmbeddable( + initialRuntimeState, + buildApiMock, + uuid, + mockedDashboardApi, + jest.fn().mockImplementation((newApi) => newApi), + initialRuntimeState // initialRuntimeState only contains lastSavedRuntimeState + ); + await waitOneTick(); // wait for build to complete + expect(resolveRootProfileSpy).toHaveBeenCalledWith({ + solutionNavId: 'override-solution-nav-id', + }); + }); + it('should resolve data source profile when fetching', async () => { const resolveDataSourceProfileSpy = jest.spyOn( discoverServiceMock.profilesManager, diff --git a/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.tsx b/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.tsx index 7c08cdc95e585..298ac7bc20b9e 100644 --- a/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.tsx +++ b/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.tsx @@ -69,9 +69,9 @@ export const getSearchEmbeddableFactory = ({ }, buildEmbeddable: async (initialState, buildApi, uuid, parentApi) => { /** One Discover context awareness */ - const solutionNavId = await firstValueFrom( - discoverServices.core.chrome.getActiveSolutionNavId$() - ); + const solutionNavId = + initialState.nonPersistedDisplayOptions?.solutionNavIdOverride ?? + (await firstValueFrom(discoverServices.core.chrome.getActiveSolutionNavId$())); const { getRenderAppWrapper } = await discoverServices.profilesManager.resolveRootProfile({ solutionNavId, }); diff --git a/src/platform/plugins/shared/discover/public/embeddable/types.ts b/src/platform/plugins/shared/discover/public/embeddable/types.ts index 0443801ec7245..0d875a477776f 100644 --- a/src/platform/plugins/shared/discover/public/embeddable/types.ts +++ b/src/platform/plugins/shared/discover/public/embeddable/types.ts @@ -64,6 +64,7 @@ export type SearchEmbeddableSerializedAttributes = Omit< // These are options that are not persisted in the saved object, but can be used by solutions // when utilising the SavedSearchComponent package outside of dashboard contexts. export interface NonPersistedDisplayOptions { + solutionNavIdOverride?: string; enableDocumentViewer?: boolean; enableFilters?: boolean; } diff --git a/x-pack/platform/packages/shared/observability/logs_overview/src/components/log_category_details/log_category_document_examples_table.tsx b/x-pack/platform/packages/shared/observability/logs_overview/src/components/log_category_details/log_category_document_examples_table.tsx index 0101a2496415f..45e8080e04b13 100644 --- a/x-pack/platform/packages/shared/observability/logs_overview/src/components/log_category_details/log_category_document_examples_table.tsx +++ b/x-pack/platform/packages/shared/observability/logs_overview/src/components/log_category_details/log_category_document_examples_table.tsx @@ -41,6 +41,7 @@ export const LogCategoryDocumentExamplesTable: React.FC Date: Mon, 13 Jan 2025 11:22:13 -0400 Subject: [PATCH 2/2] Better type for solutionNavIdOverride --- .../public/embeddable/get_search_embeddable_factory.test.tsx | 4 ++-- .../plugins/shared/discover/public/embeddable/types.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.test.tsx b/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.test.tsx index ad95f4f8cae6f..dbabe1a6bfd28 100644 --- a/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.test.tsx +++ b/src/platform/plugins/shared/discover/public/embeddable/get_search_embeddable_factory.test.tsx @@ -252,7 +252,7 @@ describe('saved search embeddable', () => { const initialRuntimeState = { ...getInitialRuntimeState(), nonPersistedDisplayOptions: { - solutionNavIdOverride: 'override-solution-nav-id', + solutionNavIdOverride: 'search' as const, }, }; await factory.buildEmbeddable( @@ -265,7 +265,7 @@ describe('saved search embeddable', () => { ); await waitOneTick(); // wait for build to complete expect(resolveRootProfileSpy).toHaveBeenCalledWith({ - solutionNavId: 'override-solution-nav-id', + solutionNavId: 'search', }); }); diff --git a/src/platform/plugins/shared/discover/public/embeddable/types.ts b/src/platform/plugins/shared/discover/public/embeddable/types.ts index 0d875a477776f..57932b2508ee1 100644 --- a/src/platform/plugins/shared/discover/public/embeddable/types.ts +++ b/src/platform/plugins/shared/discover/public/embeddable/types.ts @@ -64,7 +64,7 @@ export type SearchEmbeddableSerializedAttributes = Omit< // These are options that are not persisted in the saved object, but can be used by solutions // when utilising the SavedSearchComponent package outside of dashboard contexts. export interface NonPersistedDisplayOptions { - solutionNavIdOverride?: string; + solutionNavIdOverride?: 'oblt' | 'security' | 'search'; enableDocumentViewer?: boolean; enableFilters?: boolean; }