diff --git a/src/plugins/data/public/search/search_interceptor/search_interceptor.test.ts b/src/plugins/data/public/search/search_interceptor/search_interceptor.test.ts index 5ee9d5be50f75..3306ac90ab288 100644 --- a/src/plugins/data/public/search/search_interceptor/search_interceptor.test.ts +++ b/src/plugins/data/public/search/search_interceptor/search_interceptor.test.ts @@ -8,7 +8,7 @@ import type { MockedKeys } from '@kbn/utility-types-jest'; import { CoreSetup, CoreStart } from '@kbn/core/public'; -import { coreMock, themeServiceMock } from '@kbn/core/public/mocks'; +import { coreMock } from '@kbn/core/public/mocks'; import { IEsSearchRequest } from '@kbn/search-types'; import { SearchInterceptor } from './search_interceptor'; import { AbortError } from '@kbn/kibana-utils-plugin/public'; @@ -44,7 +44,6 @@ import { SearchSessionIncompleteWarning } from './search_session_incomplete_warn import { getMockSearchConfig } from '../../../config.mock'; let searchInterceptor: SearchInterceptor; -let mockCoreSetup: MockedKeys; let bfetchSetup: jest.Mocked; let fetchMock: jest.Mock; @@ -87,6 +86,7 @@ function mockFetchImplementation(responses: any[]) { } describe('SearchInterceptor', () => { + let mockCoreSetup: MockedKeys; let mockCoreStart: MockedKeys; let sessionService: jest.Mocked; let sessionState$: BehaviorSubject; @@ -139,7 +139,6 @@ describe('SearchInterceptor', () => { http: mockCoreSetup.http, executionContext: mockCoreSetup.executionContext, session: sessionService, - theme: themeServiceMock.createSetupContract(), searchConfig: getMockSearchConfig({}), }); }); diff --git a/src/plugins/data/public/search/search_interceptor/search_interceptor.ts b/src/plugins/data/public/search/search_interceptor/search_interceptor.ts index 2474158c10833..ec0585fe8469e 100644 --- a/src/plugins/data/public/search/search_interceptor/search_interceptor.ts +++ b/src/plugins/data/public/search/search_interceptor/search_interceptor.ts @@ -36,18 +36,20 @@ import { PublicMethodsOf } from '@kbn/utility-types'; import type { HttpSetup, IHttpFetchError } from '@kbn/core-http-browser'; import { type Start as InspectorStart, RequestAdapter } from '@kbn/inspector-plugin/public'; -import { +import type { + AnalyticsServiceStart, ApplicationStart, CoreStart, DocLinksStart, ExecutionContextSetup, + I18nStart, IUiSettingsClient, - ThemeServiceSetup, + ThemeServiceStart, ToastsSetup, } from '@kbn/core/public'; import { BatchedFunc, BfetchPublicSetup, DISABLE_BFETCH } from '@kbn/bfetch-plugin/public'; -import { toMountPoint } from '@kbn/kibana-react-plugin/public'; +import { toMountPoint } from '@kbn/react-kibana-mount'; import { AbortError, KibanaServerError } from '@kbn/kibana-utils-plugin/public'; import { BfetchRequestError } from '@kbn/bfetch-error'; import type { @@ -84,7 +86,6 @@ export interface SearchInterceptorDeps { toasts: ToastsSetup; usageCollector?: SearchUsageCollector; session: ISessionService; - theme: ThemeServiceSetup; searchConfig: SearchConfigSchema; } @@ -117,6 +118,16 @@ export class SearchInterceptor { >; private inspector!: InspectorStart; + /* + * Services for toMountPoint + * @internal + */ + private startRenderServices!: { + analytics: Pick; + i18n: I18nStart; + theme: Pick; + }; + /* * @internal */ @@ -124,8 +135,10 @@ export class SearchInterceptor { this.deps.http.addLoadingCountSource(this.pendingCount$); this.deps.startServices.then(([coreStart, depsStart]) => { - this.application = coreStart.application; - this.docLinks = coreStart.docLinks; + const { application, docLinks, analytics, i18n: i18nStart, theme } = coreStart; + this.application = application; + this.docLinks = docLinks; + this.startRenderServices = { analytics, i18n: i18nStart, theme }; this.inspector = (depsStart as SearchServiceStartDependencies).inspector; }); @@ -288,7 +301,7 @@ export class SearchInterceptor { const search = () => { const [{ isSearchStored }, afterPoll] = searchTracker?.beforePoll() ?? [ { isSearchStored: false }, - ({ isSearchStored: boolean }) => {}, + () => {}, ]; return this.runSearch( { id, ...request }, @@ -560,10 +573,10 @@ export class SearchInterceptor { ); } - private showTimeoutErrorToast = (e: SearchTimeoutError, sessionId?: string) => { + private showTimeoutErrorToast = (e: SearchTimeoutError, _sessionId?: string) => { this.deps.toasts.addDanger({ title: 'Timed out', - text: toMountPoint(e.getErrorMessage(this.application), { theme$: this.deps.theme.theme$ }), + text: toMountPoint(e.getErrorMessage(this.application), this.startRenderServices), }); }; @@ -574,13 +587,11 @@ export class SearchInterceptor { } ); - private showRestoreWarningToast = (sessionId?: string) => { + private showRestoreWarningToast = (_sessionId?: string) => { this.deps.toasts.addWarning( { title: 'Your search session is still running', - text: toMountPoint(SearchSessionIncompleteWarning(this.docLinks), { - theme$: this.deps.theme.theme$, - }), + text: toMountPoint(SearchSessionIncompleteWarning(this.docLinks), this.startRenderServices), }, { toastLifeTimeMs: 60000, @@ -613,7 +624,7 @@ export class SearchInterceptor { if (searchErrorDisplay) { this.deps.toasts.addDanger({ title: searchErrorDisplay.title, - text: toMountPoint(searchErrorDisplay.body, { theme$: this.deps.theme.theme$ }), + text: toMountPoint(searchErrorDisplay.body, this.startRenderServices), }); } else { this.deps.toasts.addError(e, { diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 325850fa409e1..10d84a8db93a1 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -113,7 +113,7 @@ export class SearchService implements Plugin { management, }: SearchServiceSetupDependencies ): ISearchSetup { - const { http, getStartServices, notifications, uiSettings, executionContext, theme } = core; + const { http, getStartServices, notifications, uiSettings, executionContext } = core; this.usageCollector = createUsageCollector(getStartServices, usageCollection); this.sessionsClient = new SessionsClient({ http }); @@ -137,7 +137,6 @@ export class SearchService implements Plugin { startServices: getStartServices(), usageCollector: this.usageCollector!, session: this.sessionService, - theme, searchConfig: this.initializerContext.config.get().search, }); diff --git a/src/plugins/data/public/search/session/sessions_mgmt/components/actions/delete_button.tsx b/src/plugins/data/public/search/session/sessions_mgmt/components/actions/delete_button.tsx index 46f7698fe589f..e56d5844ca611 100644 --- a/src/plugins/data/public/search/session/sessions_mgmt/components/actions/delete_button.tsx +++ b/src/plugins/data/public/search/session/sessions_mgmt/components/actions/delete_button.tsx @@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import React, { useState } from 'react'; import { CoreStart } from '@kbn/core/public'; -import { toMountPoint } from '@kbn/kibana-react-plugin/public'; +import { toMountPoint } from '@kbn/react-kibana-mount'; import { SearchSessionsMgmtAPI } from '../../lib/api'; import { IClickActionDescriptor } from '..'; import { OnActionDismiss } from './types'; @@ -74,7 +74,7 @@ export const createDeleteActionDescriptor = ( const ref = core.overlays.openModal( toMountPoint( ref?.close()} searchSession={uiSession} api={api} />, - { theme$: core.theme.theme$ } + core ) ); await ref.onClose; diff --git a/src/plugins/data/public/search/session/sessions_mgmt/components/actions/extend_button.tsx b/src/plugins/data/public/search/session/sessions_mgmt/components/actions/extend_button.tsx index 4b955e7bf93a3..2a715ce601a34 100644 --- a/src/plugins/data/public/search/session/sessions_mgmt/components/actions/extend_button.tsx +++ b/src/plugins/data/public/search/session/sessions_mgmt/components/actions/extend_button.tsx @@ -12,7 +12,7 @@ import { FormattedMessage } from '@kbn/i18n-react'; import React, { useState } from 'react'; import moment from 'moment'; import { CoreStart } from '@kbn/core/public'; -import { toMountPoint } from '@kbn/kibana-react-plugin/public'; +import { toMountPoint } from '@kbn/react-kibana-mount'; import { SearchSessionsMgmtAPI } from '../../lib/api'; import { IClickActionDescriptor } from '..'; import { OnActionDismiss } from './types'; @@ -81,7 +81,7 @@ export const createExtendActionDescriptor = ( const ref = core.overlays.openModal( toMountPoint( ref?.close()} searchSession={uiSession} api={api} />, - { theme$: core.theme.theme$ } + core ) ); await ref.onClose; diff --git a/src/plugins/data/public/search/session/sessions_mgmt/components/actions/inspect_button.tsx b/src/plugins/data/public/search/session/sessions_mgmt/components/actions/inspect_button.tsx index baa652e9cfabd..fcbc6ec3c7b4d 100644 --- a/src/plugins/data/public/search/session/sessions_mgmt/components/actions/inspect_button.tsx +++ b/src/plugins/data/public/search/session/sessions_mgmt/components/actions/inspect_button.tsx @@ -10,7 +10,8 @@ import { EuiFlyoutBody, EuiFlyoutHeader, EuiSpacer, EuiText, EuiTitle } from '@e import { FormattedMessage } from '@kbn/i18n-react'; import React, { Fragment } from 'react'; import { CoreStart } from '@kbn/core/public'; -import { createKibanaReactContext, toMountPoint } from '@kbn/kibana-react-plugin/public'; +import { createKibanaReactContext } from '@kbn/kibana-react-plugin/public'; +import { toMountPoint } from '@kbn/react-kibana-mount'; import { CodeEditor } from '@kbn/code-editor'; import { UISession } from '../../types'; import { IClickActionDescriptor } from '..'; @@ -123,9 +124,7 @@ export const createInspectActionDescriptor = ( searchSession={uiSession} /> ); - const overlay = core.overlays.openFlyout( - toMountPoint(flyoutWrapper, { theme$: core.theme.theme$ }) - ); + const overlay = core.overlays.openFlyout(toMountPoint(flyoutWrapper, core)); await overlay.onClose; }, }); diff --git a/src/plugins/data/public/search/session/sessions_mgmt/components/actions/rename_button.tsx b/src/plugins/data/public/search/session/sessions_mgmt/components/actions/rename_button.tsx index 318acab7ee745..e3c740ec36a7b 100644 --- a/src/plugins/data/public/search/session/sessions_mgmt/components/actions/rename_button.tsx +++ b/src/plugins/data/public/search/session/sessions_mgmt/components/actions/rename_button.tsx @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import React, { useState } from 'react'; import { CoreStart } from '@kbn/core/public'; -import { toMountPoint } from '@kbn/kibana-react-plugin/public'; +import { toMountPoint } from '@kbn/react-kibana-mount'; import { SearchSessionsMgmtAPI } from '../../lib/api'; import { IClickActionDescriptor } from '..'; import { OnActionDismiss } from './types'; @@ -112,7 +112,7 @@ export const createRenameActionDescriptor = ( const ref = core.overlays.openModal( toMountPoint( ref?.close()} api={api} searchSession={uiSession} />, - { theme$: core.theme.theme$ } + core ) ); await ref.onClose;