Skip to content

Commit

Permalink
Add execution context support for management plugins (#128415)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Mar 31, 2022
1 parent 3073231 commit b00ca41
Show file tree
Hide file tree
Showing 47 changed files with 375 additions and 122 deletions.
3 changes: 2 additions & 1 deletion src/core/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import { savedObjectsServiceMock } from './saved_objects/saved_objects_service.m
import { injectedMetadataServiceMock } from './injected_metadata/injected_metadata_service.mock';
import { deprecationsServiceMock } from './deprecations/deprecations_service.mock';
import { themeServiceMock } from './theme/theme_service.mock';
import { executionContextServiceMock } from './execution_context/execution_context_service.mock';

export { chromeServiceMock } from './chrome/chrome_service.mock';
export { docLinksServiceMock } from './doc_links/doc_links_service.mock';
import { executionContextServiceMock } from './execution_context/execution_context_service.mock';
export { executionContextServiceMock } from './execution_context/execution_context_service.mock';
export { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
export { httpServiceMock } from './http/http_service.mock';
export { i18nServiceMock } from './i18n/i18n_service.mock';
Expand Down
33 changes: 29 additions & 4 deletions x-pack/plugins/cross_cluster_replication/public/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,48 @@ import {
ApplicationStart,
DocLinksStart,
CoreTheme,
ExecutionContextStart,
} from 'src/core/public';
import { KibanaThemeProvider } from '../shared_imports';
import { KibanaThemeProvider, useExecutionContext } from '../shared_imports';
import { init as initBreadcrumbs, SetBreadcrumbs } from './services/breadcrumbs';
import { init as initDocumentation } from './services/documentation_links';
import { App } from './app';
import { ccrStore } from './store';

const AppWithExecutionContext = ({
history,
executionContext,
getUrlForApp,
}: {
history: ScopedHistory;
getUrlForApp: ApplicationStart['getUrlForApp'];
executionContext: ExecutionContextStart;
}) => {
useExecutionContext(executionContext, {
type: 'application',
page: 'crossClusterReplication',
});

return <App history={history} getUrlForApp={getUrlForApp} />;
};

const renderApp = (
element: Element,
I18nContext: I18nStart['Context'],
history: ScopedHistory,
getUrlForApp: ApplicationStart['getUrlForApp'],
theme$: Observable<CoreTheme>
theme$: Observable<CoreTheme>,
executionContext: ExecutionContextStart
): UnmountCallback => {
render(
<I18nContext>
<KibanaThemeProvider theme$={theme$}>
<Provider store={ccrStore}>
<App history={history} getUrlForApp={getUrlForApp} />
<AppWithExecutionContext
history={history}
getUrlForApp={getUrlForApp}
executionContext={executionContext}
/>
</Provider>
</KibanaThemeProvider>
</I18nContext>,
Expand All @@ -53,6 +76,7 @@ export async function mountApp({
history,
getUrlForApp,
theme$,
executionContext,
}: {
element: Element;
setBreadcrumbs: SetBreadcrumbs;
Expand All @@ -61,11 +85,12 @@ export async function mountApp({
history: ScopedHistory;
getUrlForApp: ApplicationStart['getUrlForApp'];
theme$: Observable<CoreTheme>;
executionContext: ExecutionContextStart;
}): Promise<UnmountCallback> {
// Import and initialize additional services here instead of in plugin.ts to reduce the size of the
// initial bundle as much as possible.
initBreadcrumbs(setBreadcrumbs);
initDocumentation(docLinks);

return renderApp(element, I18nContext, history, getUrlForApp, theme$);
return renderApp(element, I18nContext, history, getUrlForApp, theme$, executionContext);
}
2 changes: 2 additions & 0 deletions x-pack/plugins/cross_cluster_replication/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class CrossClusterReplicationPlugin implements Plugin {
i18n: { Context: I18nContext },
docLinks,
application: { getUrlForApp },
executionContext,
} = coreStart;

docTitle.change(PLUGIN.TITLE);
Expand All @@ -62,6 +63,7 @@ export class CrossClusterReplicationPlugin implements Plugin {
history,
getUrlForApp,
theme$,
executionContext,
});

return () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export {
PageLoading,
} from '../../../../src/plugins/es_ui_shared/public';

export { KibanaThemeProvider } from '../../../../src/plugins/kibana_react/public';
export {
KibanaThemeProvider,
useExecutionContext,
} from '../../../../src/plugins/kibana_react/public';

export { APP_WRAPPER_CLASS } from '../../../../src/core/public';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { registerTestBed, TestBed, TestBedConfig } from '@kbn/test-jest-helpers';
import { docLinksServiceMock } from 'src/core/public/mocks';
import { docLinksServiceMock, executionContextServiceMock } from 'src/core/public/mocks';
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
import { createBreadcrumbsMock } from '../../../public/application/services/breadcrumbs.mock';
import { licensingMock } from '../../../../licensing/public/mocks';
Expand All @@ -23,6 +23,7 @@ const AppWithContext = (props: any) => {
breadcrumbService,
license: licensingMock.createLicense(),
docLinks: docLinksServiceMock.createStartContract(),
executionContext: executionContextServiceMock.createStartContract(),
}}
>
<App {...props} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ import { Router, Switch, Route, Redirect } from 'react-router-dom';
import { ScopedHistory } from 'kibana/public';
import { METRIC_TYPE } from '@kbn/analytics';

import { useKibana, useExecutionContext } from '../shared_imports';
import { UIM_APP_LOAD } from './constants';
import { EditPolicy } from './sections/edit_policy';
import { PolicyList } from './sections/policy_list';
import { trackUiMetric } from './services/ui_metric';
import { ROUTES } from './services/navigation';

export const App = ({ history }: { history: ScopedHistory }) => {
const {
services: { executionContext },
} = useKibana();

useEffect(() => trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD), []);

useExecutionContext(executionContext!, {
type: 'application',
page: 'indexLifecycleManagement',
});

return (
<Router history={history}>
<Switch>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
UnmountCallback,
CoreTheme,
} from 'src/core/public';
import { DocLinksStart } from 'kibana/public';
import { DocLinksStart, ExecutionContextStart } from 'kibana/public';

import {
CloudSetup,
Expand All @@ -37,6 +37,7 @@ export const renderApp = (
license: ILicense,
theme$: Observable<CoreTheme>,
docLinks: DocLinksStart,
executionContext: ExecutionContextStart,
cloud?: CloudSetup
): UnmountCallback => {
const { getUrlForApp } = application;
Expand All @@ -45,7 +46,14 @@ export const renderApp = (
<I18nContext>
<KibanaThemeProvider theme$={theme$}>
<KibanaContextProvider
services={{ cloud, breadcrumbService, license, getUrlForApp, docLinks }}
services={{
cloud,
breadcrumbService,
license,
getUrlForApp,
docLinks,
executionContext,
}}
>
<App history={history} />
</KibanaContextProvider>
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/index_lifecycle_management/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class IndexLifecycleManagementPlugin
i18n: { Context: I18nContext },
application,
docLinks,
executionContext,
} = coreStart;

const license = await licensing.license$.pipe(first()).toPromise();
Expand All @@ -74,6 +75,7 @@ export class IndexLifecycleManagementPlugin
license,
theme$,
docLinks,
executionContext,
cloud
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export {
KibanaContextProvider,
KibanaThemeProvider,
RedirectAppLinks,
useExecutionContext,
} from '../../../../src/plugins/kibana_react/public';

export { APP_WRAPPER_CLASS } from '../../../../src/core/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
notificationServiceMock,
docLinksServiceMock,
uiSettingsServiceMock,
executionContextServiceMock,
} from '../../../../../../src/core/public/mocks';
import { GlobalFlyout } from '../../../../../../src/plugins/es_ui_shared/public';
import { createKibanaReactContext } from '../../../../../../src/plugins/kibana_react/public';
Expand Down Expand Up @@ -48,7 +49,10 @@ setUiMetricService(services.uiMetricService);

const appDependencies = {
services,
core: { getUrlForApp: () => {} },
core: {
getUrlForApp: () => {},
executionContext: executionContextServiceMock.createStartContract(),
},
plugins: {},
} as any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ import { setExtensionsService } from '../../public/application/store/selectors/e
import { ExtensionsService } from '../../public/services';
import { kibanaVersion } from '../client_integration/helpers';

/* eslint-disable @kbn/eslint/no-restricted-paths */
import { notificationServiceMock } from '../../../../../src/core/public/notifications/notifications_service.mock';
import {
notificationServiceMock,
executionContextServiceMock,
} from '../../../../../src/core/public/mocks';

const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });

Expand Down Expand Up @@ -164,7 +166,14 @@ describe('index table', () => {

store = indexManagementStore(services);

const appDependencies = { services, core: {}, plugins: {} };
const appDependencies = {
services,
core: {
getUrlForApp: () => {},
executionContext: executionContextServiceMock.createStartContract(),
},
plugins: {},
};

component = (
<Provider store={store}>
Expand Down
15 changes: 12 additions & 3 deletions x-pack/plugins/index_management/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,29 @@ import { Router, Switch, Route, Redirect } from 'react-router-dom';
import { ScopedHistory } from 'kibana/public';

import { UIM_APP_LOAD } from '../../common/constants';
import { useExecutionContext } from '../shared_imports';
import { IndexManagementHome, homeSections } from './sections/home';
import { TemplateCreate } from './sections/template_create';
import { TemplateClone } from './sections/template_clone';
import { TemplateEdit } from './sections/template_edit';
import { useServices } from './app_context';
import { useAppContext } from './app_context';
import {
ComponentTemplateCreate,
ComponentTemplateEdit,
ComponentTemplateClone,
} from './components';

export const App = ({ history }: { history: ScopedHistory }) => {
const { uiMetricService } = useServices();
useEffect(() => uiMetricService.trackMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD), [uiMetricService]);
const { core, services } = useAppContext();
useEffect(
() => services.uiMetricService.trackMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD),
[services.uiMetricService]
);

useExecutionContext(core.executionContext, {
type: 'application',
page: 'indexManagement',
});

return (
<Router history={history}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ScopedHistory,
DocLinksStart,
IUiSettingsClient,
ExecutionContextStart,
} from 'src/core/public';
import { SharePluginStart } from 'src/plugins/share/public';

Expand All @@ -29,6 +30,7 @@ export interface AppDependencies {
core: {
fatalErrors: FatalErrorsStart;
getUrlForApp: ApplicationStart['getUrlForApp'];
executionContext: ExecutionContextStart;
};
plugins: {
usageCollection: UsageCollectionSetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
notificationServiceMock,
docLinksServiceMock,
applicationServiceMock,
executionContextServiceMock,
} from '../../../../../../../../../../src/core/public/mocks';

import { GlobalFlyout } from '../../../../../../../../../../src/plugins/es_ui_shared/public';
Expand All @@ -37,6 +38,7 @@ export const componentTemplatesDependencies = (httpSetup: HttpSetup) => ({
toasts: notificationServiceMock.createSetupContract().toasts,
setBreadcrumbs: () => {},
getUrlForApp: applicationServiceMock.createStartContract().getUrlForApp,
executionContext: executionContextServiceMock.createInternalStartContract(),
});

export const setupEnvironment = initHttpRequests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import React from 'react';
import { RouteComponentProps } from 'react-router-dom';

import { useExecutionContext } from '../shared_imports';
import { useComponentTemplatesContext } from '../component_templates_context';
import { ComponentTemplatesAuthProvider } from './auth_provider';
import { ComponentTemplatesWithPrivileges } from './with_privileges';
import { ComponentTemplateList } from './component_template_list';
Expand All @@ -24,6 +26,13 @@ export const ComponentTemplateListContainer: React.FunctionComponent<
},
history,
}) => {
const { executionContext } = useComponentTemplatesContext();

useExecutionContext(executionContext, {
type: 'application',
page: 'indexManagementComponentTemplatesTab',
});

return (
<ComponentTemplatesAuthProvider>
<ComponentTemplatesWithPrivileges>
Expand Down
Loading

0 comments on commit b00ca41

Please sign in to comment.