Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Support overriding solutionNavId used for root profile resolution in embeddable #205986

Merged
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 @@ -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.

Expand All @@ -22,5 +22,10 @@ import { LazySavedSearchComponent } from '@kbn/saved-search-component';
filters={optionalFilters}
query={optionalQuery}
timestampField={optionalTimestampFieldString}
displayOptions={{
solutionNavIdOverride: 'oblt',
enableDocumentViewer: true,
enableFilters: false,
}}
/>
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const SavedSearchComponent: React.FC<SavedSearchComponentProps> = (props)
} = props;

const {
solutionNavIdOverride,
enableDocumentViewer: documentViewerEnabled = true,
enableFilters: filtersEnabled = true,
} = props.displayOptions ?? {};
Expand Down Expand Up @@ -75,6 +76,7 @@ export const SavedSearchComponent: React.FC<SavedSearchComponentProps> = (props)
attributes: { ...attributes, references },
timeRange,
nonPersistedDisplayOptions: {
solutionNavIdOverride,
enableDocumentViewer: documentViewerEnabled,
enableFilters: filtersEnabled,
},
Expand All @@ -100,6 +102,7 @@ export const SavedSearchComponent: React.FC<SavedSearchComponentProps> = (props)
index,
query,
searchSourceService,
solutionNavIdOverride,
timeRange,
timestampField,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'search' as const,
},
};
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: 'search',
});
});

it('should resolve data source profile when fetching', async () => {
const resolveDataSourceProfileSpy = jest.spyOn(
discoverServiceMock.profilesManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?: 'oblt' | 'security' | 'search';
enableDocumentViewer?: boolean;
enableFilters?: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const LogCategoryDocumentExamplesTable: React.FC<LogCategoryDocumentExamp
index={logsSource.indexName}
timestampField={logsSource.timestampField}
displayOptions={{
solutionNavIdOverride: 'oblt',
enableDocumentViewer: false,
enableFilters: false,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function ClassicServiceLogsStream() {
query={query}
height={'60vh'}
displayOptions={{
solutionNavIdOverride: 'oblt',
enableDocumentViewer: true,
enableFilters: false,
}}
Expand Down
Loading