Skip to content

Commit

Permalink
move management registry to new platform (#53020)
Browse files Browse the repository at this point in the history
* move management registry to new platform
  • Loading branch information
mattkime authored Dec 17, 2019
1 parent 18b5cf9 commit 2d36b21
Show file tree
Hide file tree
Showing 28 changed files with 220 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
5 changes: 3 additions & 2 deletions src/legacy/ui/public/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions src/legacy/ui/public/new_platform/__mocks__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -45,6 +46,7 @@ export const pluginsMock = {
inspector: inspectorPluginMock.createStartContract(),
expressions: expressionsPluginMock.createStartContract(),
uiActions: uiActionsPluginMock.createStartContract(),
management: managementPluginMock.createStartContract(),
}),
};

Expand Down
7 changes: 7 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ export const npStart = {
chrome: {},
},
plugins: {
management: {
legacy: {
getSection: () => ({
register: sinon.fake(),
}),
},
},
embeddable: {
getEmbeddableFactory: sinon.fake(),
getEmbeddableFactories: sinon.fake(),
Expand Down
2 changes: 2 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -67,6 +68,7 @@ export interface PluginsStart {
dev_tools: DevToolsStart;
kibana_legacy: KibanaLegacyStart;
share: SharePluginStart;
management: ManagementStart;
}

export const npSetup = {
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/management/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "management",
"version": "kibana",
"server": false,
"ui": true,
"requiredPlugins": []
}
27 changes: 27 additions & 0 deletions src/plugins/management/public/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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({
Expand All @@ -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;
Expand Down Expand Up @@ -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`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -81,7 +78,7 @@ describe('ManagementSection', () => {
let section;

beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
});

it('returns a ManagementSection', () => {
Expand Down Expand Up @@ -129,7 +126,7 @@ describe('ManagementSection', () => {
let section;

beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
section.register('about');
});

Expand Down Expand Up @@ -160,7 +157,7 @@ describe('ManagementSection', () => {
let section;

beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
section.register('about');
});

Expand All @@ -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 });
Expand Down Expand Up @@ -217,7 +214,7 @@ describe('ManagementSection', () => {
let section;

beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
});

it('hide sets visible to false', () => {
Expand All @@ -236,7 +233,7 @@ describe('ManagementSection', () => {
let section;

beforeEach(() => {
section = new ManagementSection('kibana');
section = new ManagementSection('kibana', {}, capabilitiesMock);
});

it('disable sets disabled to true', () => {
Expand All @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Loading

0 comments on commit 2d36b21

Please sign in to comment.