Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ui/registry/feature_catalogue to New Platform plugin #48818

Merged
merged 6 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1132,13 +1132,14 @@ import { setup, start } from '../core_plugins/visualizations/public/legacy';
| `import 'ui/filter_bar'` | `import { FilterBar } from '../data/public'` | `import '../data/public/legacy` should be called to load legacy directives |
| `import 'ui/query_bar'` | `import { QueryBar, QueryBarInput } from '../data/public'` | Directives are deprecated. |
| `import 'ui/search_bar'` | `import { SearchBar } from '../data/public'` | Directive is deprecated. |
| `import 'ui/kbn_top_nav'` | `import { TopNavMenu } from '../navigation/public'` | Directive is still available in `ui/kbn_top_nav`. |
| `import 'ui/kbn_top_nav'` | `import { TopNavMenu } from '../navigation/public'` | Directive is still available in `ui/kbn_top_nav`. |
| `ui/saved_objects/components/saved_object_finder` | `import { SavedObjectFinder } from '../kibana_react/public'` | |
| `core_plugins/interpreter` | `data.expressions` | still in progress |
| `ui/courier` | `data.search` | still in progress |
| `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/vis_types` | `visualizations.types` | -- |
| `ui/vis` | `visualizations.types` | -- |
| `ui/vis/vis_factory` | `visualizations.types` | -- |
Expand Down Expand Up @@ -1180,7 +1181,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` | | Should be an API on the home plugin. |
| `home` | [`plugins.feature_catalogue.register`](./src/plugins/feature_catalogue) | Must add `feature_catalogue` 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
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getRoute() {
return {
template,
resolve: {
directories: () => getServices().getFeatureCatalogueRegistryProvider().then(catalogue => catalogue.inTitleOrder)
directories: () => getServices().getFeatureCatalogueEntries()
},
controller($scope, $route) {
const { chrome, addBasePath } = getServices();
Expand Down
10 changes: 7 additions & 3 deletions src/legacy/core_plugins/kibana/public/home/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { uiModules as modules } from 'ui/modules';
import routes from 'ui/routes';
import { npStart } from 'ui/new_platform';
import { npSetup, npStart } from 'ui/new_platform';
import { IPrivate } from 'ui/private';
import { FeatureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue';
import { createUiStatsReporter, METRIC_TYPE } from '../../../ui_metric/public';
Expand Down Expand Up @@ -55,10 +55,14 @@ export function getServices() {
indexPatternService: data.indexPatterns.indexPatterns,
shouldShowTelemetryOptIn,
telemetryOptInProvider,
getFeatureCatalogueRegistryProvider: async () => {
getFeatureCatalogueEntries: async () => {
const injector = await chrome.dangerouslyGetActiveInjector();
const Private = injector.get<IPrivate>('Private');
return Private(FeatureCatalogueRegistryProvider as any);
// Merge legacy registry with new registry
(Private(FeatureCatalogueRegistryProvider as any) as any).inTitleOrder.map(
npSetup.plugins.feature_catalogue.register
);
return npStart.plugins.feature_catalogue.get();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flash1293 Any issues with doing this here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all, that's fine 👍

},

trackUiMetric: createUiStatsReporter('Kibana_home'),
Expand Down
6 changes: 6 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ import {
Start as InspectorStart,
} from '../../../../plugins/inspector/public';
import { EuiUtilsStart } from '../../../../plugins/eui_utils/public';
import {
FeatureCatalogueSetup,
FeatureCatalogueStart,
} from '../../../../plugins/feature_catalogue/public';

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

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

export const FeatureCatalogueRegistryProvider = uiRegistry({
name: 'featureCatalogue',
Expand All @@ -30,9 +31,3 @@ export const FeatureCatalogueRegistryProvider = uiRegistry({
return !isDisabledViaCapabilities && Object.keys(featureCatalogItem).length > 0;
}
});

export const FeatureCatalogueCategory = {
ADMIN: 'admin',
DATA: 'data',
OTHER: 'other'
};
5 changes: 5 additions & 0 deletions src/plugins/feature_catalogue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Feature catalogue plugin

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then probably we should rename either?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be more clear once this registry moves into a "home" plugin with the actual UI. I opted not to name this plugin "home" right now since it may not be split out until 8.x and I thought that would be confusing in the meantime.

UI capabilities for feature controls.
joshdover marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions src/plugins/feature_catalogue/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "feature_catalogue",
"version": "kibana",
"server": false,
"ui": true
}
24 changes: 24 additions & 0 deletions src/plugins/feature_catalogue/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { FeatureCatalogueSetup, FeatureCatalogueStart } from './plugin';
export { FeatureCatalogueEntry, FeatureCatalogueCategory } from './services';
import { FeatureCataloguePlugin } from './plugin';

export const plugin = () => new FeatureCataloguePlugin();
25 changes: 25 additions & 0 deletions src/plugins/feature_catalogue/public/plugin.test.mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

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

export const registryMock = featureCatalogueRegistryMock.create();
jest.doMock('./services', () => ({
FeatureCatalogueRegistry: jest.fn(() => registryMock),
}));
49 changes: 49 additions & 0 deletions src/plugins/feature_catalogue/public/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.
*/

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

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

describe('setup', () => {
test('wires up and returns registry', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: not sure those are really useful tests if TS enforces the contract

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can go either way here, but I prefer some coverage here over nothing.

const setup = await new FeatureCataloguePlugin().setup();
expect(registryMock.setup).toHaveBeenCalledWith();
expect(setup.register).toBeDefined();
});
});

describe('start', () => {
test('wires up and returns registry', async () => {
const service = new FeatureCataloguePlugin();
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();
});
});
});
50 changes: 50 additions & 0 deletions src/plugins/feature_catalogue/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.
*/

import { CoreStart, Plugin } from 'src/core/public';
import {
FeatureCatalogueRegistry,
FeatureCatalogueRegistrySetup,
FeatureCatalogueRegistryStart,
} from './services';

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

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

public async start(core: CoreStart) {
return {
...this.featuresCatalogueRegistry.start({
capabilities: core.application.capabilities,
}),
};
}
}

/** @public */
export type FeatureCatalogueSetup = FeatureCatalogueRegistrySetup;

/** @public */
export type FeatureCatalogueStart = FeatureCatalogueRegistryStart;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.
*/

import {
FeatureCatalogueRegistrySetup,
FeatureCatalogueRegistryStart,
FeatureCatalogueRegistry,
} from './feature_catalogue_registry';

const createSetupMock = (): jest.Mocked<FeatureCatalogueRegistrySetup> => {
const setup = {
register: jest.fn(),
};
return setup;
};

const createStartMock = (): jest.Mocked<FeatureCatalogueRegistryStart> => {
const start = {
get: jest.fn(),
};
return start;
};

const createMock = (): jest.Mocked<PublicMethodsOf<FeatureCatalogueRegistry>> => {
const service = {
setup: jest.fn(),
start: jest.fn(),
};
service.setup.mockImplementation(createSetupMock);
service.start.mockImplementation(createStartMock);
return service;
};

export const featureCatalogueRegistryMock = {
createSetup: createSetupMock,
createStart: createStartMock,
create: createMock,
};
Loading