Skip to content

Commit 4f8f832

Browse files
committed
Move getUiApi call to security start and pass core instead of getStartServices
1 parent 62aab12 commit 4f8f832

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

x-pack/plugins/security/public/plugin.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { SecurityNavControlService } from './nav_control';
2929
import { SecurityCheckupService } from './security_checkup';
3030
import { SessionExpired, SessionTimeout, UnauthorizedResponseHttpInterceptor } from './session';
3131
import { getUiApi } from './ui_api';
32-
import type { UiApi } from './ui_api';
3332

3433
export interface PluginSetupDependencies {
3534
licensing: LicensingPluginSetup;
@@ -62,7 +61,6 @@ export class SecurityPlugin
6261
private readonly securityCheckupService = new SecurityCheckupService();
6362
private authc!: AuthenticationServiceSetup;
6463
private readonly config: ConfigType;
65-
private uiApi!: UiApi;
6664

6765
constructor(private readonly initializerContext: PluginInitializerContext) {
6866
this.config = this.initializerContext.config.get<ConfigType>();
@@ -100,10 +98,6 @@ export class SecurityPlugin
10098
logoutUrl,
10199
});
102100

103-
this.uiApi = getUiApi({
104-
getStartServices: core.getStartServices,
105-
});
106-
107101
accountManagementApp.create({
108102
authc: this.authc,
109103
application: core.application,
@@ -154,7 +148,7 @@ export class SecurityPlugin
154148
}
155149

156150
return {
157-
uiApi: this.uiApi,
151+
uiApi: getUiApi({ core }),
158152
navControlService: this.navControlService.start({ core }),
159153
authc: this.authc as AuthenticationServiceStart,
160154
};

x-pack/plugins/security/public/ui_api/components.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@
88
import type { FC, PropsWithChildren, PropsWithRef } from 'react';
99
import React from 'react';
1010

11-
import type { StartServicesAccessor } from 'src/core/public';
11+
import type { CoreStart } from 'src/core/public';
1212

1313
import { getChangePasswordComponent } from '../account_management/change_password/change_password_async';
1414
import { getPersonalInfoComponent } from '../account_management/personal_info/personal_info_async';
15-
import type { PluginStartDependencies } from '../plugin';
1615
import { LazyWrapper } from './lazy_wrapper';
1716

1817
export interface GetComponentsOptions {
19-
getStartServices: StartServicesAccessor<PluginStartDependencies>;
18+
core: CoreStart;
2019
}
2120

22-
export const getComponents = ({ getStartServices }: GetComponentsOptions) => {
21+
export const getComponents = ({ core }: GetComponentsOptions) => {
2322
/**
2423
* Returns a function that creates a lazy-loading version of a component.
2524
*/
2625
function wrapLazy<T>(fn: () => Promise<FC<T>>) {
2726
return (props: JSX.IntrinsicAttributes & PropsWithRef<PropsWithChildren<T>>) => (
28-
<LazyWrapper fn={fn} getStartServices={getStartServices} props={props} />
27+
<LazyWrapper fn={fn} core={core} props={props} />
2928
);
3029
}
3130

x-pack/plugins/security/public/ui_api/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77

88
import type { ReactElement } from 'react';
99

10-
import type { StartServicesAccessor } from 'src/core/public';
10+
import type { CoreStart } from 'src/core/public';
1111

1212
import type { ChangePasswordProps } from '../account_management/change_password';
1313
import type { PersonalInfoProps } from '../account_management/personal_info';
1414
import { UserAPIClient } from '../management';
15-
import type { PluginStartDependencies } from '../plugin';
1615
import { getComponents } from './components';
1716

1817
interface GetUiApiOptions {
19-
getStartServices: StartServicesAccessor<PluginStartDependencies>;
18+
core: CoreStart;
2019
}
2120

2221
type LazyComponentFn<T> = (props: T) => ReactElement;
@@ -29,8 +28,8 @@ export interface UiApi {
2928
UserAPIClient: typeof UserAPIClient;
3029
}
3130

32-
export const getUiApi = ({ getStartServices }: GetUiApiOptions): UiApi => {
33-
const components = getComponents({ getStartServices });
31+
export const getUiApi = ({ core }: GetUiApiOptions): UiApi => {
32+
const components = getComponents({ core });
3433

3534
return {
3635
components,

x-pack/plugins/security/public/ui_api/lazy_wrapper.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@
77

88
import type { FC, PropsWithChildren, PropsWithRef, ReactElement } from 'react';
99
import React, { lazy, useMemo } from 'react';
10-
import useAsync from 'react-use/lib/useAsync';
1110

12-
import type { StartServicesAccessor } from 'src/core/public';
11+
import type { CoreStart } from 'src/core/public';
1312

14-
import type { PluginStartDependencies } from '../plugin';
1513
import { SuspenseErrorBoundary } from '../suspense_error_boundary';
1614

1715
interface InternalProps<T> {
1816
fn: () => Promise<FC<T>>;
19-
getStartServices: StartServicesAccessor<PluginStartDependencies>;
17+
core: CoreStart;
2018
props: JSX.IntrinsicAttributes & PropsWithRef<PropsWithChildren<T>>;
2119
}
2220

2321
export const LazyWrapper: <T>(props: InternalProps<T>) => ReactElement | null = ({
2422
fn,
25-
getStartServices,
23+
core,
2624
props,
2725
}) => {
28-
const { value: startServices = [{ notifications: undefined }] } = useAsync(getStartServices);
29-
const [{ notifications }] = startServices;
26+
const { notifications } = core;
3027

3128
const LazyComponent = useMemo(() => lazy(() => fn().then((x) => ({ default: x }))), [fn]);
3229

0 commit comments

Comments
 (0)