uiSettings in #start() life-cycle (#39054) (#39179)

* feat: 🎸 add uiSettings service in "start" Core

* test: 💍 add test for uiSettings#start() lifecycle

* fix: 🐛 add uiSettings to plugin context

* docs: ✏️ update Core API docs

* fix: 🐛 fix TypeScript type check errors
This commit is contained in:
Vadim Dalecky 2019-06-19 13:49:51 +02:00 committed by GitHub
parent 900f48cc5f
commit 7f8b424e2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 66 additions and 2 deletions

View file

@ -22,4 +22,5 @@ export interface CoreStart
| [i18n](./kibana-plugin-public.corestart.i18n.md) | <code>I18nStart</code> | [I18nStart](./kibana-plugin-public.i18nstart.md) |
| [notifications](./kibana-plugin-public.corestart.notifications.md) | <code>NotificationsStart</code> | [NotificationsStart](./kibana-plugin-public.notificationsstart.md) |
| [overlays](./kibana-plugin-public.corestart.overlays.md) | <code>OverlayStart</code> | [OverlayStart](./kibana-plugin-public.overlaystart.md) |
| [uiSettings](./kibana-plugin-public.corestart.uisettings.md) | <code>UiSettingsStart</code> | [UiSettingsStart](./kibana-plugin-public.uisettingsstart.md) |

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [CoreStart](./kibana-plugin-public.corestart.md) &gt; [uiSettings](./kibana-plugin-public.corestart.uisettings.md)
## CoreStart.uiSettings property
[UiSettingsStart](./kibana-plugin-public.uisettingsstart.md)
<b>Signature:</b>
```typescript
uiSettings: UiSettingsStart;
```

View file

@ -57,4 +57,5 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [RecursiveReadonly](./kibana-plugin-public.recursivereadonly.md) | |
| [ToastInput](./kibana-plugin-public.toastinput.md) | |
| [UiSettingsSetup](./kibana-plugin-public.uisettingssetup.md) | |
| [UiSettingsStart](./kibana-plugin-public.uisettingsstart.md) | |

View file

@ -0,0 +1,12 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [UiSettingsStart](./kibana-plugin-public.uisettingsstart.md)
## UiSettingsStart type
<b>Signature:</b>
```typescript
export declare type UiSettingsStart = UiSettingsClient;
```

View file

@ -210,6 +210,11 @@ describe('#start()', () => {
expect(MockApplicationService.start).toHaveBeenCalledTimes(1);
});
it('calls uiSettings#start()', async () => {
await startCore();
expect(MockUiSettingsService.start).toHaveBeenCalledTimes(1);
});
it('calls i18n#start()', async () => {
await startCore();
expect(MockI18nService.start).toHaveBeenCalledTimes(1);

View file

@ -176,6 +176,7 @@ export class CoreSystem {
injectedMetadata,
notifications,
});
const uiSettings = await this.uiSettings.start();
const core: InternalCoreStart = {
application,
@ -185,6 +186,7 @@ export class CoreSystem {
injectedMetadata,
notifications,
overlays,
uiSettings,
};
const plugins = await this.plugins.start(core);

View file

@ -57,7 +57,7 @@ import {
} from './notifications';
import { OverlayRef, OverlayStart } from './overlays';
import { Plugin, PluginInitializer, PluginInitializerContext } from './plugins';
import { UiSettingsClient, UiSettingsSetup, UiSettingsState } from './ui_settings';
import { UiSettingsClient, UiSettingsSetup, UiSettingsStart, UiSettingsState } from './ui_settings';
import { ApplicationSetup, Capabilities, ApplicationStart } from './application';
/** @interal */
@ -106,6 +106,8 @@ export interface CoreStart {
notifications: NotificationsStart;
/** {@link OverlayStart} */
overlays: OverlayStart;
/** {@link UiSettingsStart} */
uiSettings: UiSettingsStart;
}
/** @internal */
@ -152,4 +154,5 @@ export {
UiSettingsClient,
UiSettingsState,
UiSettingsSetup,
UiSettingsStart,
};

View file

@ -90,6 +90,7 @@ const i18nStart = i18nServiceMock.createStartContract();
const injectedMetadataStart = injectedMetadataServiceMock.createStartContract();
const notificationsStart = notificationServiceMock.createStartContract();
const overlayStart = overlayServiceMock.createStartContract();
const uiSettingsStart = uiSettingsServiceMock.createStartContract();
const defaultStartDeps = {
core: {
@ -100,6 +101,7 @@ const defaultStartDeps = {
injectedMetadata: injectedMetadataStart,
notifications: notificationsStart,
overlays: overlayStart,
uiSettings: uiSettingsStart,
},
targetDomElement: document.createElement('div'),
plugins: {},

View file

@ -93,5 +93,6 @@ export function createPluginStartContext<TSetup, TStart, TPluginsSetup, TPlugins
i18n: deps.i18n,
notifications: deps.notifications,
overlays: deps.overlays,
uiSettings: deps.uiSettings,
};
}

View file

@ -87,6 +87,7 @@ beforeEach(() => {
injectedMetadata: injectedMetadataServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
overlays: overlayServiceMock.createStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract() as jest.Mocked<UiSettingsClient>,
};
mockStartContext = {
...omit(mockStartDeps, 'injectedMetadata'),

View file

@ -127,6 +127,8 @@ export interface CoreStart {
notifications: NotificationsStart;
// (undocumented)
overlays: OverlayStart;
// (undocumented)
uiSettings: UiSettingsStart;
}
// @internal
@ -395,6 +397,9 @@ export class UiSettingsClient {
// @public (undocumented)
export type UiSettingsSetup = UiSettingsClient;
// @public (undocumented)
export type UiSettingsStart = UiSettingsClient;
// @public (undocumented)
export interface UiSettingsState {
// Warning: (ae-forgotten-export) The symbol "InjectedUiSettingsDefault" needs to be exported by the entry point index.d.ts

View file

@ -17,6 +17,6 @@
* under the License.
*/
export { UiSettingsService, UiSettingsSetup } from './ui_settings_service';
export { UiSettingsService, UiSettingsSetup, UiSettingsStart } from './ui_settings_service';
export { UiSettingsClient } from './ui_settings_client';
export { UiSettingsState } from './types';

View file

@ -43,6 +43,7 @@ type UiSettingsServiceContract = PublicMethodsOf<UiSettingsService>;
const createMock = () => {
const mocked: jest.Mocked<UiSettingsServiceContract> = {
setup: jest.fn(),
start: jest.fn(),
stop: jest.fn(),
};
@ -53,4 +54,5 @@ const createMock = () => {
export const uiSettingsServiceMock = {
create: createMock,
createSetupContract: createSetupContractMock,
createStartContract: createSetupContractMock,
};

View file

@ -54,6 +54,15 @@ describe('#setup', () => {
});
});
describe('#start', () => {
it('returns an instance of UiSettingsClient', () => {
const uiSettings = new UiSettingsService();
uiSettings.setup(defaultDeps);
const start = uiSettings.start();
expect(start).toBeInstanceOf(MockUiSettingsClient);
});
});
describe('#stop', () => {
it('runs fine if service never set up', () => {
const service = new UiSettingsService();

View file

@ -49,6 +49,10 @@ export class UiSettingsService {
return this.uiSettingsClient;
}
public start(): UiSettingsStart {
return this.uiSettingsClient!;
}
public stop() {
if (this.uiSettingsClient) {
this.uiSettingsClient.stop();
@ -62,3 +66,6 @@ export class UiSettingsService {
/** @public */
export type UiSettingsSetup = UiSettingsClient;
/** @public */
export type UiSettingsStart = UiSettingsClient;