Skip to content

Commit

Permalink
[Data/Visualizations] Remove usage of deprecated modules for mounting…
Browse files Browse the repository at this point in the history
… React (elastic#182044)

## Summary

Partially addresses elastic/kibana-team#805

These changes come up from searching in the code and finding where
certain kinds of deprecated AppEx-SharedUX modules are imported.
**Reviewers: Please interact with critical paths through the UI
components touched in this PR, ESPECIALLY in terms of testing dark mode
and i18n.**

This PR focuses on code shared between **Data-Discovery and
Visualizations** teams.

<img width="1107" alt="image"
src="https://github.com/elastic/kibana/assets/908371/c0d2ce08-ac35-45a7-8192-0b2256fceb0e">

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
  • Loading branch information
tsullivan authored May 6, 2024
1 parent e2807c3 commit 1193b09
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,7 +44,6 @@ import { SearchSessionIncompleteWarning } from './search_session_incomplete_warn
import { getMockSearchConfig } from '../../../config.mock';

let searchInterceptor: SearchInterceptor;
let mockCoreSetup: MockedKeys<CoreSetup>;
let bfetchSetup: jest.Mocked<BfetchPublicSetup>;
let fetchMock: jest.Mock<any>;

Expand Down Expand Up @@ -87,6 +86,7 @@ function mockFetchImplementation(responses: any[]) {
}

describe('SearchInterceptor', () => {
let mockCoreSetup: MockedKeys<CoreSetup>;
let mockCoreStart: MockedKeys<CoreStart>;
let sessionService: jest.Mocked<ISessionService>;
let sessionState$: BehaviorSubject<SearchSessionState>;
Expand Down Expand Up @@ -139,7 +139,6 @@ describe('SearchInterceptor', () => {
http: mockCoreSetup.http,
executionContext: mockCoreSetup.executionContext,
session: sessionService,
theme: themeServiceMock.createSetupContract(),
searchConfig: getMockSearchConfig({}),
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -84,7 +86,6 @@ export interface SearchInterceptorDeps {
toasts: ToastsSetup;
usageCollector?: SearchUsageCollector;
session: ISessionService;
theme: ThemeServiceSetup;
searchConfig: SearchConfigSchema;
}

Expand Down Expand Up @@ -117,15 +118,27 @@ export class SearchInterceptor {
>;
private inspector!: InspectorStart;

/*
* Services for toMountPoint
* @internal
*/
private startRenderServices!: {
analytics: Pick<AnalyticsServiceStart, 'reportEvent'>;
i18n: I18nStart;
theme: Pick<ThemeServiceStart, 'theme$'>;
};

/*
* @internal
*/
constructor(private readonly deps: SearchInterceptorDeps) {
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;
});

Expand Down Expand Up @@ -288,7 +301,7 @@ export class SearchInterceptor {
const search = () => {
const [{ isSearchStored }, afterPoll] = searchTracker?.beforePoll() ?? [
{ isSearchStored: false },
({ isSearchStored: boolean }) => {},
() => {},
];
return this.runSearch(
{ id, ...request },
Expand Down Expand Up @@ -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),
});
};

Expand All @@ -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,
Expand Down Expand Up @@ -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, {
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/data/public/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
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 });
Expand All @@ -137,7 +137,6 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
startServices: getStartServices(),
usageCollector: this.usageCollector!,
session: this.sessionService,
theme,
searchConfig: this.initializerContext.config.get().search,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,7 +74,7 @@ export const createDeleteActionDescriptor = (
const ref = core.overlays.openModal(
toMountPoint(
<DeleteConfirm onActionDismiss={() => ref?.close()} searchSession={uiSession} api={api} />,
{ theme$: core.theme.theme$ }
core
)
);
await ref.onClose;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -81,7 +81,7 @@ export const createExtendActionDescriptor = (
const ref = core.overlays.openModal(
toMountPoint(
<ExtendConfirm onActionDismiss={() => ref?.close()} searchSession={uiSession} api={api} />,
{ theme$: core.theme.theme$ }
core
)
);
await ref.onClose;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '..';
Expand Down Expand Up @@ -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;
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -112,7 +112,7 @@ export const createRenameActionDescriptor = (
const ref = core.overlays.openModal(
toMountPoint(
<RenameDialog onActionDismiss={() => ref?.close()} api={api} searchSession={uiSession} />,
{ theme$: core.theme.theme$ }
core
)
);
await ref.onClose;
Expand Down

0 comments on commit 1193b09

Please sign in to comment.