Skip to content

Commit

Permalink
Expose injectMetadata service temporarily (elastic#47319)
Browse files Browse the repository at this point in the history
* expose injectMetadata until config service provided

* add functional test

* update types

* fix tests. injectMetadata is a part of plugin contract

* add comment about injectedVars API
  • Loading branch information
mshustov committed Oct 5, 2019
1 parent 5ee979f commit 843a8f1
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ core: {
notifications: NotificationsStart;
overlays: OverlayStart;
uiSettings: UiSettingsClientContract;
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export interface AppMountContext

| Property | Type | Description |
| --- | --- | --- |
| [core](./kibana-plugin-public.appmountcontext.core.md) | <code>{</code><br/><code> application: Pick&lt;ApplicationStart, 'capabilities' &#124; 'navigateToApp'&gt;;</code><br/><code> chrome: ChromeStart;</code><br/><code> docLinks: DocLinksStart;</code><br/><code> http: HttpStart;</code><br/><code> i18n: I18nStart;</code><br/><code> notifications: NotificationsStart;</code><br/><code> overlays: OverlayStart;</code><br/><code> uiSettings: UiSettingsClientContract;</code><br/><code> }</code> | Core service APIs available to mounted applications. |
| [core](./kibana-plugin-public.appmountcontext.core.md) | <code>{</code><br/><code> application: Pick&lt;ApplicationStart, 'capabilities' &#124; 'navigateToApp'&gt;;</code><br/><code> chrome: ChromeStart;</code><br/><code> docLinks: DocLinksStart;</code><br/><code> http: HttpStart;</code><br/><code> i18n: I18nStart;</code><br/><code> notifications: NotificationsStart;</code><br/><code> overlays: OverlayStart;</code><br/><code> uiSettings: UiSettingsClientContract;</code><br/><code> injectedMetadata: {</code><br/><code> getInjectedVar: (name: string, defaultValue?: any) =&gt; unknown;</code><br/><code> };</code><br/><code> }</code> | Core service APIs available to mounted applications. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [CoreSetup](./kibana-plugin-public.coresetup.md) &gt; [injectedMetadata](./kibana-plugin-public.coresetup.injectedmetadata.md)

## CoreSetup.injectedMetadata property

> Warning: This API is now obsolete.
>
>
exposed temporarily until https://github.com/elastic/kibana/issues/41990 done use \*only\* to retrieve config values. There is no way to set injected values in the new platform. Use the legacy platform API instead.

<b>Signature:</b>

```typescript
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface CoreSetup
| [context](./kibana-plugin-public.coresetup.context.md) | <code>ContextSetup</code> | [ContextSetup](./kibana-plugin-public.contextsetup.md) |
| [fatalErrors](./kibana-plugin-public.coresetup.fatalerrors.md) | <code>FatalErrorsSetup</code> | [FatalErrorsSetup](./kibana-plugin-public.fatalerrorssetup.md) |
| [http](./kibana-plugin-public.coresetup.http.md) | <code>HttpSetup</code> | [HttpSetup](./kibana-plugin-public.httpsetup.md) |
| [injectedMetadata](./kibana-plugin-public.coresetup.injectedmetadata.md) | <code>{</code><br/><code> getInjectedVar: (name: string, defaultValue?: any) =&gt; unknown;</code><br/><code> }</code> | exposed temporarily until https://github.com/elastic/kibana/issues/41990 done use \*only\* to retrieve config values. There is no way to set injected values in the new platform. Use the legacy platform API instead. |
| [notifications](./kibana-plugin-public.coresetup.notifications.md) | <code>NotificationsSetup</code> | [NotificationsSetup](./kibana-plugin-public.notificationssetup.md) |
| [uiSettings](./kibana-plugin-public.coresetup.uisettings.md) | <code>UiSettingsClientContract</code> | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) |

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- 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; [injectedMetadata](./kibana-plugin-public.corestart.injectedmetadata.md)

## CoreStart.injectedMetadata property

> Warning: This API is now obsolete.
>
>
exposed temporarily until https://github.com/elastic/kibana/issues/41990 done use \*only\* to retrieve config values. There is no way to set injected values in the new platform. Use the legacy platform API instead.

<b>Signature:</b>

```typescript
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface CoreStart
| [docLinks](./kibana-plugin-public.corestart.doclinks.md) | <code>DocLinksStart</code> | [DocLinksStart](./kibana-plugin-public.doclinksstart.md) |
| [http](./kibana-plugin-public.corestart.http.md) | <code>HttpStart</code> | [HttpStart](./kibana-plugin-public.httpstart.md) |
| [i18n](./kibana-plugin-public.corestart.i18n.md) | <code>I18nStart</code> | [I18nStart](./kibana-plugin-public.i18nstart.md) |
| [injectedMetadata](./kibana-plugin-public.corestart.injectedmetadata.md) | <code>{</code><br/><code> getInjectedVar: (name: string, defaultValue?: any) =&gt; unknown;</code><br/><code> }</code> | exposed temporarily until https://github.com/elastic/kibana/issues/41990 done use \*only\* to retrieve config values. There is no way to set injected values in the new platform. Use the legacy platform API instead. |
| [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) |
| [savedObjects](./kibana-plugin-public.corestart.savedobjects.md) | <code>SavedObjectsStart</code> | [SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) |
Expand Down
9 changes: 9 additions & 0 deletions src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ export interface AppMountContext {
overlays: OverlayStart;
/** {@link UiSettingsClient} */
uiSettings: UiSettingsClientContract;
/**
* exposed temporarily until https://github.com/elastic/kibana/issues/41990 done
* use *only* to retrieve config values. There is no way to set injected values
* in the new platform. Use the legacy platform API instead.
* @deprecated
* */
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
};
}

Expand Down
1 change: 1 addition & 0 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class CoreSystem {
notifications,
overlays,
uiSettings,
injectedMetadata: pick(injectedMetadata, ['getInjectedVar']),
}));

const core: InternalCoreStart = {
Expand Down
18 changes: 18 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ export interface CoreSetup {
notifications: NotificationsSetup;
/** {@link UiSettingsClient} */
uiSettings: UiSettingsClientContract;
/**
* exposed temporarily until https://github.com/elastic/kibana/issues/41990 done
* use *only* to retrieve config values. There is no way to set injected values
* in the new platform. Use the legacy platform API instead.
* @deprecated
* */
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
}

/**
Expand Down Expand Up @@ -176,6 +185,15 @@ export interface CoreStart {
overlays: OverlayStart;
/** {@link UiSettingsClient} */
uiSettings: UiSettingsClientContract;
/**
* exposed temporarily until https://github.com/elastic/kibana/issues/41990 done
* use *only* to retrieve config values. There is no way to set injected values
* in the new platform. Use the legacy platform API instead.
* @deprecated
* */
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/core/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { overlayServiceMock } from './overlays/overlay_service.mock';
import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
import { savedObjectsMock } from './saved_objects/saved_objects_service.mock';
import { contextServiceMock } from './context/context_service.mock';
import { injectedMetadataServiceMock } from './injected_metadata/injected_metadata_service.mock';

export { chromeServiceMock } from './chrome/chrome_service.mock';
export { docLinksServiceMock } from './doc_links/doc_links_service.mock';
Expand All @@ -48,6 +49,9 @@ function createCoreSetupMock() {
http: httpServiceMock.createSetupContract(),
notifications: notificationServiceMock.createSetupContract(),
uiSettings: uiSettingsServiceMock.createSetupContract(),
injectedMetadata: {
getInjectedVar: injectedMetadataServiceMock.createSetupContract().getInjectedVar,
},
};

return mock;
Expand All @@ -64,6 +68,9 @@ function createCoreStartMock() {
overlays: overlayServiceMock.createStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract(),
savedObjects: savedObjectsMock.createStartContract(),
injectedMetadata: {
getInjectedVar: injectedMetadataServiceMock.createStartContract().getInjectedVar,
},
};

return mock;
Expand Down
6 changes: 6 additions & 0 deletions src/core/public/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export function createPluginSetupContext<
http: deps.http,
notifications: deps.notifications,
uiSettings: deps.uiSettings,
injectedMetadata: {
getInjectedVar: deps.injectedMetadata.getInjectedVar,
},
};
}

Expand Down Expand Up @@ -125,5 +128,8 @@ export function createPluginStartContext<
overlays: deps.overlays,
uiSettings: deps.uiSettings,
savedObjects: deps.savedObjects,
injectedMetadata: {
getInjectedVar: deps.injectedMetadata.getInjectedVar,
},
};
}
10 changes: 5 additions & 5 deletions src/core/public/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { omit } from 'lodash';
import { omit, pick } from 'lodash';

import {
MockedPluginInitializer,
Expand Down Expand Up @@ -76,12 +76,12 @@ beforeEach(() => {
context: contextServiceMock.createSetupContract(),
fatalErrors: fatalErrorsServiceMock.createSetupContract(),
http: httpServiceMock.createSetupContract(),
injectedMetadata: injectedMetadataServiceMock.createSetupContract(),
injectedMetadata: pick(injectedMetadataServiceMock.createStartContract(), 'getInjectedVar'),
notifications: notificationServiceMock.createSetupContract(),
uiSettings: uiSettingsServiceMock.createSetupContract(),
};
mockSetupContext = {
...omit(mockSetupDeps, 'injectedMetadata'),
...mockSetupDeps,
application: expect.any(Object),
};
mockStartDeps = {
Expand All @@ -90,14 +90,14 @@ beforeEach(() => {
http: httpServiceMock.createStartContract(),
chrome: chromeServiceMock.createStartContract(),
i18n: i18nServiceMock.createStartContract(),
injectedMetadata: injectedMetadataServiceMock.createStartContract(),
injectedMetadata: pick(injectedMetadataServiceMock.createStartContract(), 'getInjectedVar'),
notifications: notificationServiceMock.createStartContract(),
overlays: overlayServiceMock.createStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract(),
savedObjects: savedObjectsMock.createStartContract(),
};
mockStartContext = {
...omit(mockStartDeps, 'injectedMetadata'),
...mockStartDeps,
application: expect.any(Object),
chrome: omit(mockStartDeps.chrome, 'getComponent'),
};
Expand Down
11 changes: 11 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export interface AppMountContext {
notifications: NotificationsStart;
overlays: OverlayStart;
uiSettings: UiSettingsClientContract;
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
};
}

Expand Down Expand Up @@ -235,6 +238,10 @@ export interface CoreSetup {
fatalErrors: FatalErrorsSetup;
// (undocumented)
http: HttpSetup;
// @deprecated
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
// (undocumented)
notifications: NotificationsSetup;
// (undocumented)
Expand All @@ -253,6 +260,10 @@ export interface CoreStart {
http: HttpStart;
// (undocumented)
i18n: I18nStart;
// @deprecated
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
// (undocumented)
notifications: NotificationsStart;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { CorePluginAPluginSetup } from '../../core_plugin_a/public/plugin';
declare global {
interface Window {
corePluginB?: string;
hasAccessToInjectedMetadata?: boolean;
}
}

Expand All @@ -34,6 +35,7 @@ export class CorePluginBPlugin
implements Plugin<CorePluginBPluginSetup, CorePluginBPluginStart, CorePluginBDeps> {
public setup(core: CoreSetup, deps: CorePluginBDeps) {
window.corePluginB = `Plugin A said: ${deps.core_plugin_a.getGreeting()}`;
window.hasAccessToInjectedMetadata = 'getInjectedVar' in core.injectedMetadata;

core.application.register({
id: 'bar',
Expand Down
24 changes: 18 additions & 6 deletions test/plugin_functional/test_suites/core_plugins/ui_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@ export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['common']);
const browser = getService('browser');

describe('ui plugin loading', function describeIndexTests() {
before(async () => {
await PageObjects.common.navigateToApp('settings');
describe('ui plugins', function () {
describe('loading', function describeIndexTests() {
before(async () => {
await PageObjects.common.navigateToApp('settings');
});

it('should attach string to window.corePluginB', async () => {
const corePluginB = await browser.execute('return window.corePluginB');
expect(corePluginB).to.equal(`Plugin A said: Hello from Plugin A!`);
});
});
describe('have injectedMetadata service provided', function describeIndexTests() {
before(async () => {
await PageObjects.common.navigateToApp('bar');
});

it('should attach string to window.corePluginB', async () => {
const corePluginB = await browser.execute('return window.corePluginB');
expect(corePluginB).to.equal(`Plugin A said: Hello from Plugin A!`);
it('should attach string to window.corePluginB', async () => {
const hasAccessToInjectedMetadata = await browser.execute('return window.hasAccessToInjectedMetadata');
expect(hasAccessToInjectedMetadata).to.equal(true);
});
});
});
}

0 comments on commit 843a8f1

Please sign in to comment.