Skip to content

Commit

Permalink
Np kibana plugin home feature catalogue (#50838)
Browse files Browse the repository at this point in the history
* Moves feature_catalogue services into the home plugin public folder.
  • Loading branch information
TinaHeiligers authored Nov 19, 2019
1 parent 295f1df commit e46f977
Show file tree
Hide file tree
Showing 32 changed files with 151 additions and 71 deletions.
4 changes: 2 additions & 2 deletions src/core/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ import { setup, start } from '../core_plugins/visualizations/public/legacy';
| `ui/embeddable` | `embeddables` | still in progress |
| `ui/filter_manager` | `data.filter` | -- |
| `ui/index_patterns` | `data.indexPatterns` | still in progress |
| `ui/registry/feature_catalogue | `feature_catalogue.register` | Must add `feature_catalogue` as a dependency in your kibana.json. |
| `ui/registry/feature_catalogue` | `home.featureCatalogue.register` | Must add `home` as a dependency in your kibana.json. |
| `ui/registry/vis_types` | `visualizations.types` | -- |
| `ui/vis` | `visualizations.types` | -- |
| `ui/share` | `share` | `showShareContextMenu` is now called `toggleShareContextMenu`, `ShareContextMenuExtensionsRegistryProvider` is now called `register` |
Expand Down Expand Up @@ -1182,7 +1182,7 @@ This table shows where these uiExports have moved to in the New Platform. In mos
| `fieldFormatEditors` | | |
| `fieldFormats` | | |
| `hacks` | n/a | Just run the code in your plugin's `start` method. |
| `home` | [`plugins.feature_catalogue.register`](./src/plugins/feature_catalogue) | Must add `feature_catalogue` as a dependency in your kibana.json. |
| `home` | [`plugins.home.featureCatalogue.register`](./src/plugins/home/public/feature_catalogue) | Must add `home` as a dependency in your kibana.json. |
| `indexManagement` | | Should be an API on the indexManagement plugin. |
| `injectDefaultVars` | n/a | Plugins will only be able to "whitelist" config values for the frontend. See [#41990](https://github.com/elastic/kibana/issues/41990) |
| `inspectorViews` | | Should be an API on the data (?) plugin. |
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/console/np_ready/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import { I18nContext } from 'ui/i18n';

export interface XPluginSet {
devTools: DevToolsSetup;
feature_catalogue: FeatureCatalogueSetup;
home: HomePublicPluginSetup;
__LEGACY: {
I18nContext: any;
};
}

import { plugin } from '.';
import { DevToolsSetup } from '../../../../../plugins/dev_tools/public';
import { FeatureCatalogueSetup } from '../../../../../plugins/feature_catalogue/public';
import { HomePublicPluginSetup } from '../../../../../plugins/home/public';

const pluginInstance = plugin({} as any);

Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/console/np_ready/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export class ConsoleUIPlugin implements Plugin<any, any> {
const {
__LEGACY: { I18nContext },
devTools,
feature_catalogue,
home,
} = pluginSet;

feature_catalogue.register({
home.featureCatalogue.register({
id: 'console',
title: i18n.translate('console.devToolsTitle', {
defaultMessage: 'Console',
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/kibana/public/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ let copiedLegacyCatalogue = false;
const Private = injector.get<IPrivate>('Private');
// Merge legacy registry with new registry
(Private(FeatureCatalogueRegistryProvider as any) as any).inTitleOrder.map(
npSetup.plugins.feature_catalogue.register
npSetup.plugins.home.featureCatalogue.register
);
copiedLegacyCatalogue = true;
}
return npStart.plugins.feature_catalogue.get();
return npStart.plugins.home.featureCatalogue.get();
},
getAngularDependencies,
localApplicationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
UiSettingsState,
} from 'kibana/public';
import { UiStatsMetricType } from '@kbn/analytics';
import { FeatureCatalogueEntry } from '../../../../../plugins/feature_catalogue/public';
import { FeatureCatalogueEntry } from '../../../../../plugins/home/public';

export interface HomeKibanaServices {
indexPatternService: any;
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/home/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { UiStatsMetricType } from '@kbn/analytics';
import { DataStart } from '../../../data/public';
import { LocalApplicationService } from '../local_application_service';
import { setServices } from './kibana_services';
import { FeatureCatalogueEntry } from '../../../../../plugins/feature_catalogue/public';
import { FeatureCatalogueEntry } from '../../../../../plugins/home/public';

export interface LegacyAngularInjectedDependencies {
telemetryOptInProvider: any;
Expand Down
9 changes: 3 additions & 6 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ import {
} from '../../../../plugins/inspector/public';
import { EuiUtilsStart } from '../../../../plugins/eui_utils/public';
import { DevToolsSetup, DevToolsStart } from '../../../../plugins/dev_tools/public';
import {
FeatureCatalogueSetup,
FeatureCatalogueStart,
} from '../../../../plugins/feature_catalogue/public';
import { HomePublicPluginSetup, HomePublicPluginStart } from '../../../../plugins/home/public';
import { SharePluginSetup, SharePluginStart } from '../../../../plugins/share/public';

export interface PluginsSetup {
data: ReturnType<DataPlugin['setup']>;
embeddable: EmbeddableSetup;
expressions: ReturnType<ExpressionsPlugin['setup']>;
feature_catalogue: FeatureCatalogueSetup;
home: HomePublicPluginSetup;
inspector: InspectorSetup;
uiActions: IUiActionsSetup;
share: SharePluginSetup;
Expand All @@ -51,7 +48,7 @@ export interface PluginsStart {
embeddable: EmbeddableStart;
eui_utils: EuiUtilsStart;
expressions: ReturnType<ExpressionsPlugin['start']>;
feature_catalogue: FeatureCatalogueStart;
home: HomePublicPluginStart;
inspector: InspectorStart;
uiActions: IUiActionsStart;
share: SharePluginStart;
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/ui/public/registry/feature_catalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { uiRegistry } from './_registry';
import { capabilities } from '../capabilities';
export { FeatureCatalogueCategory } from '../../../../plugins/feature_catalogue/public';
export { FeatureCatalogueCategory } from '../../../../plugins/home/public';

export const FeatureCatalogueRegistryProvider = uiRegistry({
name: 'featureCatalogue',
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/feature_catalogue/kibana.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Feature catalogue plugin
# home plugin
Moves the legacy `ui/registry/feature_catalogue` module for registering "features" that should be shown in the home page's feature catalogue to a service within a "home" plugin. The feature catalogue refered to here should not be confused with the "feature" plugin for registering features used to derive UI capabilities for feature controls.

# Feature catalogue (public service)

Replaces the legacy `ui/registry/feature_catalogue` module for registering "features" that should be showed in the home
page's feature catalogue. This should not be confused with the "feature" plugin for registering features used to derive
Expand All @@ -9,15 +12,15 @@ UI capabilities for feature controls.
```ts
// For legacy plugins
import { npSetup } from 'ui/new_platform';
npSetup.plugins.feature_catalogue.register(/* same details here */);
npSetup.plugins.home.featureCatalogue.register(/* same details here */);

// For new plugins: first add 'feature_catalogue` to the list of `optionalPlugins`
// For new plugins: first add 'home` to the list of `optionalPlugins`
// in your kibana.json file. Then access the plugin directly in `setup`:

class MyPlugin {
setup(core, plugins) {
if (plugins.feature_catalogue) {
plugins.feature_catalogue.register(/* same details here. */);
if (plugins.home) {
plugins.home.featureCatalgoue.register(/* same details here. */);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/home/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"id": "home",
"version": "kibana",
"server": true,
"ui": false
"ui": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
* under the License.
*/

export { FeatureCatalogueSetup, FeatureCatalogueStart } from './plugin';
export {
FeatureCatalogueSetup,
FeatureCatalogueStart,
HomePublicPluginSetup,
HomePublicPluginStart,
} from './plugin';
export { FeatureCatalogueEntry, FeatureCatalogueCategory } from './services';
import { FeatureCataloguePlugin } from './plugin';
import { HomePublicPlugin } from './plugin';

export const plugin = () => new FeatureCataloguePlugin();
export const plugin = () => new HomePublicPlugin();
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { featureCatalogueRegistryMock } from './services/feature_catalogue_registry.mock';
import { featureCatalogueRegistryMock } from './services/feature_catalogue/feature_catalogue_registry.mock';

export const registryMock = featureCatalogueRegistryMock.create();
jest.doMock('./services', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@
*/

import { registryMock } from './plugin.test.mocks';
import { FeatureCataloguePlugin } from './plugin';
import { HomePublicPlugin } from './plugin';

describe('FeatureCataloguePlugin', () => {
describe('HomePublicPlugin', () => {
beforeEach(() => {
registryMock.setup.mockClear();
registryMock.start.mockClear();
});

describe('setup', () => {
test('wires up and returns registry', async () => {
const setup = await new FeatureCataloguePlugin().setup();
expect(registryMock.setup).toHaveBeenCalledWith();
expect(setup.register).toBeDefined();
const setup = await new HomePublicPlugin().setup();
expect(setup).toHaveProperty('featureCatalogue');
expect(setup.featureCatalogue).toHaveProperty('register');
});
});

describe('start', () => {
test('wires up and returns registry', async () => {
const service = new FeatureCataloguePlugin();
const service = new HomePublicPlugin();
await service.setup();
const core = { application: { capabilities: { catalogue: {} } } } as any;
const start = await service.start(core);
expect(registryMock.start).toHaveBeenCalledWith({
capabilities: core.application.capabilities,
});
expect(start.get).toBeDefined();
expect(start.featureCatalogue.get).toBeDefined();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ import {
FeatureCatalogueRegistryStart,
} from './services';

export class FeatureCataloguePlugin
implements Plugin<FeatureCatalogueSetup, FeatureCatalogueStart> {
export class HomePublicPlugin implements Plugin<HomePublicPluginSetup, HomePublicPluginStart> {
private readonly featuresCatalogueRegistry = new FeatureCatalogueRegistry();

public async setup() {
return {
...this.featuresCatalogueRegistry.setup(),
featureCatalogue: { ...this.featuresCatalogueRegistry.setup() },
};
}

public async start(core: CoreStart) {
return {
...this.featuresCatalogueRegistry.start({
capabilities: core.application.capabilities,
}),
featureCatalogue: {
...this.featuresCatalogueRegistry.start({
capabilities: core.application.capabilities,
}),
},
};
}
}
Expand All @@ -48,3 +49,13 @@ export type FeatureCatalogueSetup = FeatureCatalogueRegistrySetup;

/** @public */
export type FeatureCatalogueStart = FeatureCatalogueRegistryStart;

/** @public */
export interface HomePublicPluginSetup {
featureCatalogue: FeatureCatalogueSetup;
}

/** @public */
export interface HomePublicPluginStart {
featureCatalogue: FeatureCatalogueStart;
}
26 changes: 26 additions & 0 deletions src/plugins/home/public/services/feature_catalogue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export {
FeatureCatalogueCategory,
FeatureCatalogueEntry,
FeatureCatalogueRegistry,
FeatureCatalogueRegistrySetup,
FeatureCatalogueRegistryStart,
} from './feature_catalogue_registry';
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export * from './feature_catalogue_registry';
export * from './feature_catalogue';
6 changes: 3 additions & 3 deletions src/plugins/home/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

export { HomePluginSetup, HomePluginStart } from './plugin';
export { HomeServerPluginSetup, HomeServerPluginStart } from './plugin';
export { TutorialProvider } from './services';
import { HomePlugin } from './plugin';
import { HomeServerPlugin } from './plugin';

export const plugin = () => new HomePlugin();
export const plugin = () => new HomeServerPlugin();
2 changes: 1 addition & 1 deletion src/plugins/home/server/plugin.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { tutorialsRegistryMock } from './services/tutorials_registry.mock';
import { tutorialsRegistryMock } from './services/tutorials/tutorials_registry.mock';

export const registryMock = tutorialsRegistryMock.create();
jest.doMock('./services', () => ({
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/home/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/

import { registryMock } from './plugin.test.mocks';
import { HomePlugin } from './plugin';
import { HomeServerPlugin } from './plugin';
import { coreMock } from '../../../core/server/mocks';
import { CoreSetup } from '../../../core/server';

type MockedKeys<T> = { [P in keyof T]: jest.Mocked<T[P]> };

describe('HomePlugin', () => {
describe('HomeServerPlugin', () => {
beforeEach(() => {
registryMock.setup.mockClear();
registryMock.start.mockClear();
Expand All @@ -34,7 +34,7 @@ describe('HomePlugin', () => {
const mockCoreSetup: MockedKeys<CoreSetup> = coreMock.createSetup();

test('wires up and returns registerTutorial and addScopedTutorialContextFactory', () => {
const setup = new HomePlugin().setup(mockCoreSetup);
const setup = new HomeServerPlugin().setup(mockCoreSetup);
expect(setup).toHaveProperty('tutorials');
expect(setup.tutorials).toHaveProperty('registerTutorial');
expect(setup.tutorials).toHaveProperty('addScopedTutorialContextFactory');
Expand All @@ -43,7 +43,7 @@ describe('HomePlugin', () => {

describe('start', () => {
test('is defined', () => {
const start = new HomePlugin().start();
const start = new HomeServerPlugin().start();
expect(start).toBeDefined();
expect(start).toHaveProperty('tutorials');
});
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/home/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { CoreSetup, Plugin } from 'src/core/server';
import { TutorialsRegistry, TutorialsRegistrySetup, TutorialsRegistryStart } from './services';

export class HomePlugin implements Plugin<HomePluginSetup, HomePluginStart> {
export class HomeServerPlugin implements Plugin<HomeServerPluginSetup, HomeServerPluginStart> {
private readonly tutorialsRegistry = new TutorialsRegistry();

public setup(core: CoreSetup) {
Expand All @@ -36,11 +36,11 @@ export class HomePlugin implements Plugin<HomePluginSetup, HomePluginStart> {
}

/** @public */
export interface HomePluginSetup {
export interface HomeServerPluginSetup {
tutorials: TutorialsRegistrySetup;
}

/** @public */
export interface HomePluginStart {
export interface HomeServerPluginStart {
tutorials: TutorialsRegistryStart;
}
Loading

0 comments on commit e46f977

Please sign in to comment.