move management registry to new platform (#53020) (#54058)

* move management registry to new platform
This commit is contained in:
Matthew Kime 2020-01-06 16:16:04 -06:00 committed by GitHub
parent 64cbe80549
commit 7913df496c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 219 additions and 84 deletions

View file

@ -22,7 +22,7 @@
"kbn": "src/legacy/core_plugins/kibana",
"kbnDocViews": "src/legacy/core_plugins/kbn_doc_views",
"kbnVislibVisTypes": "src/legacy/core_plugins/kbn_vislib_vis_types",
"management": "src/legacy/core_plugins/management",
"management": ["src/legacy/core_plugins/management", "src/plugins/management"],
"kibana_react": "src/legacy/core_plugins/kibana_react",
"kibana-react": "src/plugins/kibana_react",
"kibana_utils": "src/plugins/kibana_utils",

View file

@ -31,7 +31,7 @@ import {
} from '@elastic/eui';
import { PRIVACY_STATEMENT_URL } from '../../common/constants';
import { OptInExampleFlyout } from './opt_in_details_component';
import { Field } from 'ui/management';
import { Field } from '../../../kibana/public/management/sections/settings/components/field/field';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';

View file

@ -23,7 +23,8 @@ export {
PAGE_FOOTER_COMPONENT,
} from '../../../core_plugins/kibana/public/management/sections/settings/components/default_component_registry';
export { registerSettingsComponent } from '../../../core_plugins/kibana/public/management/sections/settings/components/component_registry';
export { Field } from '../../../core_plugins/kibana/public/management/sections/settings/components/field/field';
export { management } from './sections_register';
export { SidebarNav } from './components';
export { MANAGEMENT_BREADCRUMB } from './breadcrumbs';
import { npStart } from 'ui/new_platform';
export const management = npStart.plugins.management.legacy;

View file

@ -25,6 +25,7 @@ import { navigationPluginMock } from '../../../../../plugins/navigation/public/m
import { expressionsPluginMock } from '../../../../../plugins/expressions/public/mocks';
import { inspectorPluginMock } from '../../../../../plugins/inspector/public/mocks';
import { uiActionsPluginMock } from '../../../../../plugins/ui_actions/public/mocks';
import { managementPluginMock } from '../../../../../plugins/management/public/mocks';
import { usageCollectionPluginMock } from '../../../../../plugins/usage_collection/public/mocks';
/* eslint-enable @kbn/eslint/no-restricted-paths */
@ -45,6 +46,7 @@ export const pluginsMock = {
inspector: inspectorPluginMock.createStartContract(),
expressions: expressionsPluginMock.createStartContract(),
uiActions: uiActionsPluginMock.createStartContract(),
management: managementPluginMock.createStartContract(),
}),
};

View file

@ -144,6 +144,13 @@ export const npStart = {
chrome: {},
},
plugins: {
management: {
legacy: {
getSection: () => ({
register: sinon.fake(),
}),
},
},
embeddable: {
getEmbeddableFactory: sinon.fake(),
getEmbeddableFactories: sinon.fake(),

View file

@ -32,6 +32,7 @@ import { DevToolsSetup, DevToolsStart } from '../../../../plugins/dev_tools/publ
import { KibanaLegacySetup, KibanaLegacyStart } from '../../../../plugins/kibana_legacy/public';
import { HomePublicPluginSetup, HomePublicPluginStart } from '../../../../plugins/home/public';
import { SharePluginSetup, SharePluginStart } from '../../../../plugins/share/public';
import { ManagementStart } from '../../../../plugins/management/public';
import { BfetchPublicSetup, BfetchPublicStart } from '../../../../plugins/bfetch/public';
import { UsageCollectionSetup } from '../../../../plugins/usage_collection/public';
import {
@ -67,6 +68,7 @@ export interface PluginsStart {
dev_tools: DevToolsStart;
kibana_legacy: KibanaLegacyStart;
share: SharePluginStart;
management: ManagementStart;
}
export const npSetup = {

View file

@ -0,0 +1,7 @@
{
"id": "management",
"version": "kibana",
"server": false,
"ui": true,
"requiredPlugins": []
}

View file

@ -0,0 +1,27 @@
/*
* 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 { PluginInitializerContext } from 'kibana/public';
import { ManagementPlugin } from './plugin';
export function plugin(initializerContext: PluginInitializerContext) {
return new ManagementPlugin();
}
export { ManagementStart } from './types';

View file

@ -17,13 +17,4 @@
* under the License.
*/
import expect from '@kbn/expect';
import { management } from '..';
import { ManagementSection } from '../section';
describe('Management', () => {
it('provides ManagementSection', () => {
expect(management).to.be.a(ManagementSection);
});
});
export { management } from './sections_register';

View file

@ -18,8 +18,7 @@
*/
import { assign } from 'lodash';
import { IndexedArray } from '../indexed_array';
import { capabilities } from '../capabilities';
import { IndexedArray } from '../../../../legacy/ui/public/indexed_array';
const listeners = [];
@ -37,7 +36,7 @@ export class ManagementSection {
* @returns {ManagementSection}
*/
constructor(id, options = {}) {
constructor(id, options = {}, capabilities) {
this.display = id;
this.id = id;
this.items = new IndexedArray({
@ -49,13 +48,14 @@ export class ManagementSection {
this.tooltip = '';
this.icon = '';
this.url = '';
this.capabilities = capabilities;
assign(this, options);
}
get visibleItems() {
return this.items.inOrder.filter(item => {
const capabilityManagementSection = capabilities.get().management[this.id];
const capabilityManagementSection = this.capabilities.management[this.id];
const itemCapability = capabilityManagementSection
? capabilityManagementSection[item.id]
: null;
@ -83,7 +83,7 @@ export class ManagementSection {
*/
register(id, options = {}) {
const item = new ManagementSection(id, assign(options, { parent: this }));
const item = new ManagementSection(id, assign(options, { parent: this }), this.capabilities);
if (this.hasItem(id)) {
throw new Error(`'${id}' is already registered`);

View file

@ -16,62 +16,59 @@
* specific language governing permissions and limitations
* under the License.
*/
jest.mock('ui/capabilities', () => ({
capabilities: {
get: () => ({
navLinks: {},
management: {
kibana: {
sampleFeature1: true,
sampleFeature2: false,
},
},
}),
},
}));
import { ManagementSection } from './section';
import { IndexedArray } from '../indexed_array';
import { IndexedArray } from '../../../../legacy/ui/public/indexed_array';
const capabilitiesMock = {
management: {
kibana: { sampleFeature2: false },
},
};
describe('ManagementSection', () => {
describe('constructor', () => {
it('defaults display to id', () => {
const section = new ManagementSection('kibana');
const section = new ManagementSection('kibana', {}, capabilitiesMock);
expect(section.display).toBe('kibana');
});
it('defaults visible to true', () => {
const section = new ManagementSection('kibana');
const section = new ManagementSection('kibana', {}, capabilitiesMock);
expect(section.visible).toBe(true);
});
it('defaults disabled to false', () => {
const section = new ManagementSection('kibana');
const section = new ManagementSection('kibana', {}, capabilitiesMock);
expect(section.disabled).toBe(false);
});
it('defaults tooltip to empty string', () => {
const section = new ManagementSection('kibana');
const section = new ManagementSection('kibana', {}, capabilitiesMock);
expect(section.tooltip).toBe('');
});
it('defaults url to empty string', () => {
const section = new ManagementSection('kibana');
const section = new ManagementSection('kibana', {}, capabilitiesMock);
expect(section.url).toBe('');
});
it('exposes items', () => {
const section = new ManagementSection('kibana');
const section = new ManagementSection('kibana', {}, capabilitiesMock);
expect(section.items).toHaveLength(0);
});
it('exposes visibleItems', () => {
const section = new ManagementSection('kibana');
const section = new ManagementSection('kibana', {}, capabilitiesMock);
expect(section.visibleItems).toHaveLength(0);
});
it('assigns all options', () => {
const section = new ManagementSection('kibana', { description: 'test', url: 'foobar' });
const section = new ManagementSection(
'kibana',
{ description: 'test', url: 'foobar' },
capabilitiesMock
);
expect(section.description).toBe('test');
expect(section.url).toBe('foobar');
});
@ -81,7 +78,7 @@ describe('ManagementSection', () => {
let section;
beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
});
it('returns a ManagementSection', () => {
@ -129,7 +126,7 @@ describe('ManagementSection', () => {
let section;
beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
section.register('about');
});
@ -160,7 +157,7 @@ describe('ManagementSection', () => {
let section;
beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
section.register('about');
});
@ -187,7 +184,7 @@ describe('ManagementSection', () => {
let section;
beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
section.register('three', { order: 3 });
section.register('one', { order: 1 });
@ -217,7 +214,7 @@ describe('ManagementSection', () => {
let section;
beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
});
it('hide sets visible to false', () => {
@ -236,7 +233,7 @@ describe('ManagementSection', () => {
let section;
beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
});
it('disable sets disabled to true', () => {
@ -254,7 +251,7 @@ describe('ManagementSection', () => {
let section;
beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
section.register('three', { order: 3 });
section.register('one', { order: 1 });

View file

@ -20,33 +20,41 @@
import { ManagementSection } from './section';
import { i18n } from '@kbn/i18n';
export const management = new ManagementSection('management', {
display: i18n.translate('common.ui.management.displayName', {
defaultMessage: 'Management',
}),
});
export const management = capabilities => {
const main = new ManagementSection(
'management',
{
display: i18n.translate('management.displayName', {
defaultMessage: 'Management',
}),
},
capabilities
);
management.register('data', {
display: i18n.translate('common.ui.management.connectDataDisplayName', {
defaultMessage: 'Connect Data',
}),
order: 0,
});
main.register('data', {
display: i18n.translate('management.connectDataDisplayName', {
defaultMessage: 'Connect Data',
}),
order: 0,
});
management.register('elasticsearch', {
display: 'Elasticsearch',
order: 20,
icon: 'logoElasticsearch',
});
main.register('elasticsearch', {
display: 'Elasticsearch',
order: 20,
icon: 'logoElasticsearch',
});
management.register('kibana', {
display: 'Kibana',
order: 30,
icon: 'logoKibana',
});
main.register('kibana', {
display: 'Kibana',
order: 30,
icon: 'logoKibana',
});
management.register('logstash', {
display: 'Logstash',
order: 30,
icon: 'logoLogstash',
});
main.register('logstash', {
display: 'Logstash',
order: 30,
icon: 'logoLogstash',
});
return main;
};

View file

@ -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.
*/
const createStartContract = () => ({
legacy: {},
});
export const managementPluginMock = {
createStartContract,
};

View file

@ -0,0 +1,35 @@
/*
* 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 { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { ManagementStart } from './types';
// @ts-ignore
import { management } from './legacy';
export class ManagementPlugin implements Plugin<{}, ManagementStart> {
public setup(core: CoreSetup) {
return {};
}
public start(core: CoreStart) {
return {
legacy: management(core.application.capabilities),
};
}
}

View file

@ -0,0 +1,22 @@
/*
* 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 interface ManagementStart {
legacy: any;
}

View file

@ -6,6 +6,7 @@
import { StartTrial } from '../public/np_ready/application/sections/license_dashboard/start_trial';
import { createMockLicense, getComponent } from './util';
jest.mock('ui/new_platform');
jest.mock(`@elastic/eui/lib/components/form/form_row/make_id`, () => () => `generated-id`);
describe('StartTrial component when trial is allowed', () => {

View file

@ -11,9 +11,7 @@ import {
import { TelemetryOptIn } from '../public/np_ready/application/components/telemetry_opt_in';
import { mountWithIntl } from '../../../../test_utils/enzyme_helpers';
jest.mock('ui/capabilities', () => ({
get: jest.fn(),
}));
jest.mock('ui/new_platform');
setTelemetryEnabled(true);

View file

@ -9,6 +9,8 @@ import { mountWithIntl } from '../../../../test_utils/enzyme_helpers';
import React from 'react';
import { Provider } from 'react-redux';
jest.mock('ui/new_platform');
// @ts-ignore
import { uploadLicense } from '../public/np_ready/application/store/actions/upload_license';

View file

@ -7,6 +7,8 @@
import { pageHelpers, nextTick, setupEnvironment } from './helpers';
import { NON_ALPHA_NUMERIC_CHARS, ACCENTED_CHARS } from './helpers/constants';
jest.mock('ui/new_platform');
const { setup } = pageHelpers.remoteClustersAdd;
describe('Create Remote cluster', () => {

View file

@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
jest.mock('ui/new_platform');
import { RemoteClusterForm } from '../../public/app/sections/components/remote_cluster_form';
import { pageHelpers, setupEnvironment, nextTick } from './helpers';
import { REMOTE_CLUSTER_EDIT, REMOTE_CLUSTER_EDIT_NAME } from './helpers/constants';

View file

@ -15,6 +15,8 @@ import {
import { getRouter } from '../../public/app/services';
import { getRemoteClusterMock } from '../../fixtures/remote_cluster';
jest.mock('ui/new_platform');
const { setup } = pageHelpers.remoteClustersList;
describe('<RemoteClusterList />', () => {

View file

@ -9,7 +9,6 @@ import { rollupJobsStore } from '../../store';
import { JobList } from './job_list';
jest.mock('ui/new_platform');
jest.mock('ui/chrome', () => ({
addBasePath: () => {},
breadcrumbs: { set: () => {} },

View file

@ -21,7 +21,6 @@ import { REPOSITORY_NAME } from './helpers/constant';
const { setup } = pageHelpers.home;
jest.mock('ui/new_platform');
jest.mock('ui/i18n', () => {
const I18nContext = ({ children }: any) => children;
return { I18nContext };

View file

@ -11,6 +11,8 @@ import { PolicyForm } from '../../public/app/components/policy_form';
import { PolicyFormTestBed } from './helpers/policy_form.helpers';
import { POLICY_EDIT } from './helpers/constant';
jest.mock('ui/new_platform');
const { setup } = pageHelpers.policyEdit;
const { setup: setupPolicyAdd } = pageHelpers.policyAdd;

View file

@ -11,6 +11,8 @@ import { RepositoryType } from '../../common/types';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { RepositoryAddTestBed } from './helpers/repository_add.helpers';
jest.mock('ui/new_platform');
const { setup } = pageHelpers.repositoryAdd;
const repositoryTypes = ['fs', 'url', 'source', 'azure', 'gcs', 's3', 'hdfs'];

View file

@ -12,6 +12,8 @@ import { RepositoryEditTestSubjects } from './helpers/repository_edit.helpers';
import { RepositoryAddTestSubjects } from './helpers/repository_add.helpers';
import { REPOSITORY_EDIT } from './helpers/constant';
jest.mock('ui/new_platform');
const { setup } = pageHelpers.repositoryEdit;
const { setup: setupRepositoryAdd } = pageHelpers.repositoryAdd;

View file

@ -441,8 +441,8 @@
"common.ui.flotCharts.tueLabel": "火",
"common.ui.flotCharts.wedLabel": "水",
"common.ui.management.breadcrumb": "管理",
"common.ui.management.connectDataDisplayName": "データに接続",
"common.ui.management.displayName": "管理",
"management.connectDataDisplayName": "データに接続",
"management.displayName": "管理",
"common.ui.management.nav.menu": "管理メニュー",
"common.ui.modals.cancelButtonLabel": "キャンセル",
"common.ui.notify.fatalError.errorStatusMessage": "エラー {errStatus} {errStatusText}: {errMessage}",

View file

@ -441,8 +441,8 @@
"common.ui.flotCharts.tueLabel": "周二",
"common.ui.flotCharts.wedLabel": "周三",
"common.ui.management.breadcrumb": "管理",
"common.ui.management.connectDataDisplayName": "连接数据",
"common.ui.management.displayName": "管理",
"management.connectDataDisplayName": "连接数据",
"management.displayName": "管理",
"common.ui.management.nav.menu": "管理菜单",
"common.ui.modals.cancelButtonLabel": "取消",
"common.ui.notify.fatalError.errorStatusMessage": "错误 {errStatus} {errStatusText}{errMessage}",
@ -12732,4 +12732,4 @@
"xpack.lens.xyVisualization.stackedBarLabel": "堆叠条形图",
"xpack.lens.xyVisualization.xyLabel": "XY"
}
}
}