From ce528431d9ccbe58869fcacaee91dc7a71a83c75 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 13 Dec 2019 12:25:58 -0600 Subject: [PATCH 01/11] move management registry to new platform --- src/legacy/ui/public/management/index.js | 4 +- .../ui/public/management/section.test.js | 288 ------------------ src/plugins/management/kibana.json | 7 + src/plugins/management/public/index.ts | 25 ++ src/plugins/management/public/legacy/index.js | 20 ++ .../management/public/legacy}/section.js | 11 +- .../public/legacy}/sections_register.js | 56 ++-- src/plugins/management/public/plugin.ts | 34 +++ src/plugins/management/public/types.ts | 22 ++ 9 files changed, 147 insertions(+), 320 deletions(-) delete mode 100644 src/legacy/ui/public/management/section.test.js create mode 100644 src/plugins/management/kibana.json create mode 100644 src/plugins/management/public/index.ts create mode 100644 src/plugins/management/public/legacy/index.js rename src/{legacy/ui/public/management => plugins/management/public/legacy}/section.js (91%) rename src/{legacy/ui/public/management => plugins/management/public/legacy}/sections_register.js (54%) create mode 100644 src/plugins/management/public/plugin.ts create mode 100644 src/plugins/management/public/types.ts diff --git a/src/legacy/ui/public/management/index.js b/src/legacy/ui/public/management/index.js index 3da03cd9d70b7..f10c942fd9a32 100644 --- a/src/legacy/ui/public/management/index.js +++ b/src/legacy/ui/public/management/index.js @@ -26,6 +26,8 @@ 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; diff --git a/src/legacy/ui/public/management/section.test.js b/src/legacy/ui/public/management/section.test.js deleted file mode 100644 index e6363f2e164b4..0000000000000 --- a/src/legacy/ui/public/management/section.test.js +++ /dev/null @@ -1,288 +0,0 @@ -/* - * 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. - */ -jest.mock('ui/capabilities', () => ({ - capabilities: { - get: () => ({ - navLinks: {}, - management: { - kibana: { - sampleFeature1: true, - sampleFeature2: false, - }, - }, - }), - }, -})); - -import { ManagementSection } from './section'; -import { IndexedArray } from '../indexed_array'; - -describe('ManagementSection', () => { - describe('constructor', () => { - it('defaults display to id', () => { - const section = new ManagementSection('kibana'); - expect(section.display).toBe('kibana'); - }); - - it('defaults visible to true', () => { - const section = new ManagementSection('kibana'); - expect(section.visible).toBe(true); - }); - - it('defaults disabled to false', () => { - const section = new ManagementSection('kibana'); - expect(section.disabled).toBe(false); - }); - - it('defaults tooltip to empty string', () => { - const section = new ManagementSection('kibana'); - expect(section.tooltip).toBe(''); - }); - - it('defaults url to empty string', () => { - const section = new ManagementSection('kibana'); - expect(section.url).toBe(''); - }); - - it('exposes items', () => { - const section = new ManagementSection('kibana'); - expect(section.items).toHaveLength(0); - }); - - it('exposes visibleItems', () => { - const section = new ManagementSection('kibana'); - expect(section.visibleItems).toHaveLength(0); - }); - - it('assigns all options', () => { - const section = new ManagementSection('kibana', { description: 'test', url: 'foobar' }); - expect(section.description).toBe('test'); - expect(section.url).toBe('foobar'); - }); - }); - - describe('register', () => { - let section; - - beforeEach(() => { - section = new ManagementSection('kibana'); - }); - - it('returns a ManagementSection', () => { - expect(section.register('about')).toBeInstanceOf(ManagementSection); - }); - - it('provides a reference to the parent', () => { - expect(section.register('about').parent).toBe(section); - }); - - it('adds item', function () { - section.register('about', { description: 'test' }); - - expect(section.items).toHaveLength(1); - expect(section.items[0]).toBeInstanceOf(ManagementSection); - expect(section.items[0].id).toBe('about'); - }); - - it('can only register a section once', () => { - let threwException = false; - section.register('about'); - - try { - section.register('about'); - } catch (e) { - threwException = e.message.indexOf('is already registered') > -1; - } - - expect(threwException).toBe(true); - }); - - it('calls listener when item added', () => { - let listerCalled = false; - const listenerFn = () => { - listerCalled = true; - }; - - section.addListener(listenerFn); - section.register('about'); - expect(listerCalled).toBe(true); - }); - }); - - describe('deregister', () => { - let section; - - beforeEach(() => { - section = new ManagementSection('kibana'); - section.register('about'); - }); - - it('deregisters an existing section', () => { - section.deregister('about'); - expect(section.items).toHaveLength(0); - }); - - it('allows deregistering a section more than once', () => { - section.deregister('about'); - section.deregister('about'); - expect(section.items).toHaveLength(0); - }); - - it('calls listener when item added', () => { - let listerCalled = false; - const listenerFn = () => { - listerCalled = true; - }; - - section.addListener(listenerFn); - section.deregister('about'); - expect(listerCalled).toBe(true); - }); - }); - - describe('getSection', () => { - let section; - - beforeEach(() => { - section = new ManagementSection('kibana'); - section.register('about'); - }); - - it('returns registered section', () => { - expect(section.getSection('about')).toBeInstanceOf(ManagementSection); - }); - - it('returns undefined if un-registered', () => { - expect(section.getSection('unknown')).not.toBeDefined(); - }); - - it('returns sub-sections specified via a /-separated path', () => { - section.getSection('about').register('time'); - expect(section.getSection('about/time')).toBeInstanceOf(ManagementSection); - expect(section.getSection('about/time')).toBe(section.getSection('about').getSection('time')); - }); - - it('returns undefined if a sub-section along a /-separated path does not exist', () => { - expect(section.getSection('about/damn/time')).toBe(undefined); - }); - }); - - describe('items', () => { - let section; - - beforeEach(() => { - section = new ManagementSection('kibana'); - - section.register('three', { order: 3 }); - section.register('one', { order: 1 }); - section.register('two', { order: 2 }); - }); - - it('is an indexed array', () => { - expect(section.items).toBeInstanceOf(IndexedArray); - }); - - it('is indexed on id', () => { - const keys = Object.keys(section.items.byId).sort(); - expect(section.items.byId).toBeInstanceOf(Object); - - expect(keys).toEqual(['one', 'three', 'two']); - }); - - it('can be ordered', () => { - const ids = section.items.inOrder.map(i => { - return i.id; - }); - expect(ids).toEqual(['one', 'two', 'three']); - }); - }); - - describe('visible', () => { - let section; - - beforeEach(() => { - section = new ManagementSection('kibana'); - }); - - it('hide sets visible to false', () => { - section.hide(); - expect(section.visible).toBe(false); - }); - - it('show sets visible to true', () => { - section.hide(); - section.show(); - expect(section.visible).toBe(true); - }); - }); - - describe('disabled', () => { - let section; - - beforeEach(() => { - section = new ManagementSection('kibana'); - }); - - it('disable sets disabled to true', () => { - section.disable(); - expect(section.disabled).toBe(true); - }); - - it('enable sets disabled to false', () => { - section.enable(); - expect(section.disabled).toBe(false); - }); - }); - - describe('visibleItems', () => { - let section; - - beforeEach(() => { - section = new ManagementSection('kibana'); - - section.register('three', { order: 3 }); - section.register('one', { order: 1 }); - section.register('two', { order: 2 }); - }); - - it('maintains the order', () => { - const ids = section.visibleItems.map(i => { - return i.id; - }); - expect(ids).toEqual(['one', 'two', 'three']); - }); - - it('does not include hidden items', () => { - section.getSection('two').hide(); - - const ids = section.visibleItems.map(i => { - return i.id; - }); - expect(ids).toEqual(['one', 'three']); - }); - - it('does not include visible items hidden via uiCapabilities', () => { - section.register('sampleFeature2', { order: 4, visible: true }); - const ids = section.visibleItems.map(i => { - return i.id; - }); - expect(ids).toEqual(['one', 'two', 'three']); - }); - }); -}); diff --git a/src/plugins/management/kibana.json b/src/plugins/management/kibana.json new file mode 100644 index 0000000000000..755a387afbd05 --- /dev/null +++ b/src/plugins/management/kibana.json @@ -0,0 +1,7 @@ +{ + "id": "management", + "version": "kibana", + "server": false, + "ui": true, + "requiredPlugins": [] +} diff --git a/src/plugins/management/public/index.ts b/src/plugins/management/public/index.ts new file mode 100644 index 0000000000000..2eac2d4b0bd42 --- /dev/null +++ b/src/plugins/management/public/index.ts @@ -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 { PluginInitializerContext } from 'kibana/public'; +import { ManagementPlugin } from './plugin'; + +export function plugin(initializerContext: PluginInitializerContext) { + return new ManagementPlugin(); +} diff --git a/src/plugins/management/public/legacy/index.js b/src/plugins/management/public/legacy/index.js new file mode 100644 index 0000000000000..63b9d2c6b27d7 --- /dev/null +++ b/src/plugins/management/public/legacy/index.js @@ -0,0 +1,20 @@ +/* + * 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 { management } from './sections_register'; diff --git a/src/legacy/ui/public/management/section.js b/src/plugins/management/public/legacy/section.js similarity index 91% rename from src/legacy/ui/public/management/section.js rename to src/plugins/management/public/legacy/section.js index b6952695cd910..fc5be81ad56fb 100644 --- a/src/legacy/ui/public/management/section.js +++ b/src/plugins/management/public/legacy/section.js @@ -18,8 +18,8 @@ */ import { assign } from 'lodash'; -import { IndexedArray } from '../indexed_array'; -import { capabilities } from '../capabilities'; +import { IndexedArray } from '../../../../legacy/ui/public/indexed_array'; +// import { capabilities } from '../capabilities'; const listeners = []; @@ -37,7 +37,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 +49,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 +84,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`); diff --git a/src/legacy/ui/public/management/sections_register.js b/src/plugins/management/public/legacy/sections_register.js similarity index 54% rename from src/legacy/ui/public/management/sections_register.js rename to src/plugins/management/public/legacy/sections_register.js index a63fd390ea3ca..de55b5f20b0bc 100644 --- a/src/legacy/ui/public/management/sections_register.js +++ b/src/plugins/management/public/legacy/sections_register.js @@ -20,33 +20,37 @@ 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('common.ui.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('common.ui.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; +}; diff --git a/src/plugins/management/public/plugin.ts b/src/plugins/management/public/plugin.ts new file mode 100644 index 0000000000000..a0d64315a071b --- /dev/null +++ b/src/plugins/management/public/plugin.ts @@ -0,0 +1,34 @@ +/* + * 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'; +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), + }; + } +} diff --git a/src/plugins/management/public/types.ts b/src/plugins/management/public/types.ts new file mode 100644 index 0000000000000..4dfd8021f651c --- /dev/null +++ b/src/plugins/management/public/types.ts @@ -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: unknown; +} From 6d5b360761493f434e6216d06b4234440ec388a4 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 13 Dec 2019 17:02:44 -0600 Subject: [PATCH 02/11] fix typescript, fix a jest test or two --- .../ui/public/management/__tests__/index.js | 29 -- .../public/new_platform/__mocks__/helpers.ts | 2 + .../ui/public/new_platform/new_platform.ts | 2 + src/plugins/management/public/index.ts | 2 + .../management/public/legacy/section.js | 1 - .../management/public/legacy/section.test.js | 288 ++++++++++++++++++ src/plugins/management/public/plugin.ts | 1 + 7 files changed, 295 insertions(+), 30 deletions(-) delete mode 100644 src/legacy/ui/public/management/__tests__/index.js create mode 100644 src/plugins/management/public/legacy/section.test.js diff --git a/src/legacy/ui/public/management/__tests__/index.js b/src/legacy/ui/public/management/__tests__/index.js deleted file mode 100644 index 6c794b3c189f0..0000000000000 --- a/src/legacy/ui/public/management/__tests__/index.js +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 expect from '@kbn/expect'; - -import { management } from '..'; -import { ManagementSection } from '../section'; - -describe('Management', () => { - it('provides ManagementSection', () => { - expect(management).to.be.a(ManagementSection); - }); -}); diff --git a/src/legacy/ui/public/new_platform/__mocks__/helpers.ts b/src/legacy/ui/public/new_platform/__mocks__/helpers.ts index 5c7f7be060374..15ff1361e4da4 100644 --- a/src/legacy/ui/public/new_platform/__mocks__/helpers.ts +++ b/src/legacy/ui/public/new_platform/__mocks__/helpers.ts @@ -24,6 +24,7 @@ import { embeddablePluginMock } from '../../../../../plugins/embeddable/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'; /* eslint-enable @kbn/eslint/no-restricted-paths */ export const pluginsMock = { @@ -40,6 +41,7 @@ export const pluginsMock = { inspector: inspectorPluginMock.createStartContract(), expressions: expressionsPluginMock.createStartContract(), uiActions: uiActionsPluginMock.createStartContract(), + management: managementPluginMock.createStartContract(), }), }; diff --git a/src/legacy/ui/public/new_platform/new_platform.ts b/src/legacy/ui/public/new_platform/new_platform.ts index d80d11e1b1bdd..2f84b1aa09cce 100644 --- a/src/legacy/ui/public/new_platform/new_platform.ts +++ b/src/legacy/ui/public/new_platform/new_platform.ts @@ -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'; export interface PluginsSetup { data: ReturnType; @@ -56,6 +57,7 @@ export interface PluginsStart { dev_tools: DevToolsStart; kibana_legacy: KibanaLegacyStart; share: SharePluginStart; + management: ManagementStart; } export const npSetup = { diff --git a/src/plugins/management/public/index.ts b/src/plugins/management/public/index.ts index 2eac2d4b0bd42..ee3866c734f19 100644 --- a/src/plugins/management/public/index.ts +++ b/src/plugins/management/public/index.ts @@ -23,3 +23,5 @@ import { ManagementPlugin } from './plugin'; export function plugin(initializerContext: PluginInitializerContext) { return new ManagementPlugin(); } + +export { ManagementStart } from './types'; diff --git a/src/plugins/management/public/legacy/section.js b/src/plugins/management/public/legacy/section.js index fc5be81ad56fb..f269e3fe295b7 100644 --- a/src/plugins/management/public/legacy/section.js +++ b/src/plugins/management/public/legacy/section.js @@ -19,7 +19,6 @@ import { assign } from 'lodash'; import { IndexedArray } from '../../../../legacy/ui/public/indexed_array'; -// import { capabilities } from '../capabilities'; const listeners = []; diff --git a/src/plugins/management/public/legacy/section.test.js b/src/plugins/management/public/legacy/section.test.js new file mode 100644 index 0000000000000..c9fa3eebe354e --- /dev/null +++ b/src/plugins/management/public/legacy/section.test.js @@ -0,0 +1,288 @@ +/* + * 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. + */ +jest.mock('ui/capabilities', () => ({ + capabilities: { + get: () => ({ + navLinks: {}, + management: { + kibana: { + sampleFeature1: true, + sampleFeature2: false, + }, + }, + }), + }, +})); + +import { ManagementSection } from './section'; +import { IndexedArray } from '../../../../legacy/ui/public/indexed_array'; + +describe('ManagementSection', () => { + describe('constructor', () => { + it('defaults display to id', () => { + const section = new ManagementSection('kibana'); + expect(section.display).toBe('kibana'); + }); + + it('defaults visible to true', () => { + const section = new ManagementSection('kibana'); + expect(section.visible).toBe(true); + }); + + it('defaults disabled to false', () => { + const section = new ManagementSection('kibana'); + expect(section.disabled).toBe(false); + }); + + it('defaults tooltip to empty string', () => { + const section = new ManagementSection('kibana'); + expect(section.tooltip).toBe(''); + }); + + it('defaults url to empty string', () => { + const section = new ManagementSection('kibana'); + expect(section.url).toBe(''); + }); + + it('exposes items', () => { + const section = new ManagementSection('kibana'); + expect(section.items).toHaveLength(0); + }); + + it('exposes visibleItems', () => { + const section = new ManagementSection('kibana'); + expect(section.visibleItems).toHaveLength(0); + }); + + it('assigns all options', () => { + const section = new ManagementSection('kibana', { description: 'test', url: 'foobar' }); + expect(section.description).toBe('test'); + expect(section.url).toBe('foobar'); + }); + }); + + describe('register', () => { + let section; + + beforeEach(() => { + section = new ManagementSection('kibana'); + }); + + it('returns a ManagementSection', () => { + expect(section.register('about')).toBeInstanceOf(ManagementSection); + }); + + it('provides a reference to the parent', () => { + expect(section.register('about').parent).toBe(section); + }); + + it('adds item', function () { + section.register('about', { description: 'test' }); + + expect(section.items).toHaveLength(1); + expect(section.items[0]).toBeInstanceOf(ManagementSection); + expect(section.items[0].id).toBe('about'); + }); + + it('can only register a section once', () => { + let threwException = false; + section.register('about'); + + try { + section.register('about'); + } catch (e) { + threwException = e.message.indexOf('is already registered') > -1; + } + + expect(threwException).toBe(true); + }); + + it('calls listener when item added', () => { + let listerCalled = false; + const listenerFn = () => { + listerCalled = true; + }; + + section.addListener(listenerFn); + section.register('about'); + expect(listerCalled).toBe(true); + }); + }); + + describe('deregister', () => { + let section; + + beforeEach(() => { + section = new ManagementSection('kibana'); + section.register('about'); + }); + + it('deregisters an existing section', () => { + section.deregister('about'); + expect(section.items).toHaveLength(0); + }); + + it('allows deregistering a section more than once', () => { + section.deregister('about'); + section.deregister('about'); + expect(section.items).toHaveLength(0); + }); + + it('calls listener when item added', () => { + let listerCalled = false; + const listenerFn = () => { + listerCalled = true; + }; + + section.addListener(listenerFn); + section.deregister('about'); + expect(listerCalled).toBe(true); + }); + }); + + describe('getSection', () => { + let section; + + beforeEach(() => { + section = new ManagementSection('kibana'); + section.register('about'); + }); + + it('returns registered section', () => { + expect(section.getSection('about')).toBeInstanceOf(ManagementSection); + }); + + it('returns undefined if un-registered', () => { + expect(section.getSection('unknown')).not.toBeDefined(); + }); + + it('returns sub-sections specified via a /-separated path', () => { + section.getSection('about').register('time'); + expect(section.getSection('about/time')).toBeInstanceOf(ManagementSection); + expect(section.getSection('about/time')).toBe(section.getSection('about').getSection('time')); + }); + + it('returns undefined if a sub-section along a /-separated path does not exist', () => { + expect(section.getSection('about/damn/time')).toBe(undefined); + }); + }); + + describe('items', () => { + let section; + + beforeEach(() => { + section = new ManagementSection('kibana'); + + section.register('three', { order: 3 }); + section.register('one', { order: 1 }); + section.register('two', { order: 2 }); + }); + + it('is an indexed array', () => { + expect(section.items).toBeInstanceOf(IndexedArray); + }); + + it('is indexed on id', () => { + const keys = Object.keys(section.items.byId).sort(); + expect(section.items.byId).toBeInstanceOf(Object); + + expect(keys).toEqual(['one', 'three', 'two']); + }); + + it('can be ordered', () => { + const ids = section.items.inOrder.map(i => { + return i.id; + }); + expect(ids).toEqual(['one', 'two', 'three']); + }); + }); + + describe('visible', () => { + let section; + + beforeEach(() => { + section = new ManagementSection('kibana'); + }); + + it('hide sets visible to false', () => { + section.hide(); + expect(section.visible).toBe(false); + }); + + it('show sets visible to true', () => { + section.hide(); + section.show(); + expect(section.visible).toBe(true); + }); + }); + + describe('disabled', () => { + let section; + + beforeEach(() => { + section = new ManagementSection('kibana'); + }); + + it('disable sets disabled to true', () => { + section.disable(); + expect(section.disabled).toBe(true); + }); + + it('enable sets disabled to false', () => { + section.enable(); + expect(section.disabled).toBe(false); + }); + }); + + describe('visibleItems', () => { + let section; + + beforeEach(() => { + section = new ManagementSection('kibana'); + + section.register('three', { order: 3 }); + section.register('one', { order: 1 }); + section.register('two', { order: 2 }); + }); + + it('maintains the order', () => { + const ids = section.visibleItems.map(i => { + return i.id; + }); + expect(ids).toEqual(['one', 'two', 'three']); + }); + + it('does not include hidden items', () => { + section.getSection('two').hide(); + + const ids = section.visibleItems.map(i => { + return i.id; + }); + expect(ids).toEqual(['one', 'three']); + }); + + it('does not include visible items hidden via uiCapabilities', () => { + section.register('sampleFeature2', { order: 4, visible: true }); + const ids = section.visibleItems.map(i => { + return i.id; + }); + expect(ids).toEqual(['one', 'two', 'three']); + }); + }); +}); diff --git a/src/plugins/management/public/plugin.ts b/src/plugins/management/public/plugin.ts index a0d64315a071b..bc1f3ff531a3a 100644 --- a/src/plugins/management/public/plugin.ts +++ b/src/plugins/management/public/plugin.ts @@ -19,6 +19,7 @@ import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { ManagementStart } from './types'; +// @ts-ignorets-ignore import { management } from './legacy'; export class ManagementPlugin implements Plugin<{}, ManagementStart> { From e656b0a164c5c52be11b78d1b86fef16b9fbb020 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 13 Dec 2019 17:05:33 -0600 Subject: [PATCH 03/11] add mocks --- src/plugins/management/public/mocks/index.ts | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/plugins/management/public/mocks/index.ts diff --git a/src/plugins/management/public/mocks/index.ts b/src/plugins/management/public/mocks/index.ts new file mode 100644 index 0000000000000..cc56928e8e529 --- /dev/null +++ b/src/plugins/management/public/mocks/index.ts @@ -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, +}; From d9e84dcc6fa8a2908020510d249152d61e476e8c Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 13 Dec 2019 20:56:16 -0600 Subject: [PATCH 04/11] i18n fix --- .i18nrc.json | 2 +- src/plugins/management/public/legacy/sections_register.js | 4 ++-- x-pack/plugins/translations/translations/ja-JP.json | 4 ++-- x-pack/plugins/translations/translations/zh-CN.json | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.i18nrc.json b/.i18nrc.json index a1c49ae03f359..f8c8f67a074d1 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -17,7 +17,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", diff --git a/src/plugins/management/public/legacy/sections_register.js b/src/plugins/management/public/legacy/sections_register.js index de55b5f20b0bc..4b3c91975942e 100644 --- a/src/plugins/management/public/legacy/sections_register.js +++ b/src/plugins/management/public/legacy/sections_register.js @@ -22,13 +22,13 @@ import { i18n } from '@kbn/i18n'; export const management = (capabilities) => { const main = new ManagementSection('management', { - display: i18n.translate('common.ui.management.displayName', { + display: i18n.translate('management.displayName', { defaultMessage: 'Management', }), }, capabilities); main.register('data', { - display: i18n.translate('common.ui.management.connectDataDisplayName', { + display: i18n.translate('management.connectDataDisplayName', { defaultMessage: 'Connect Data', }), order: 0, diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index d6e72583e4d2e..6ef598191f943 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -461,8 +461,8 @@ "common.ui.legacyBrowserMessage": "この Kibana インストレーションは、現在ご使用のブラウザが満たしていない厳格なセキュリティ要件が有効になっています。", "common.ui.legacyBrowserTitle": "ブラウザをアップグレードしてください", "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}", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 0f0a45ea19417..ed772b795ff31 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -461,8 +461,8 @@ "common.ui.legacyBrowserMessage": "此 Kibana 安装启用了当前浏览器未满足的严格安全要求。", "common.ui.legacyBrowserTitle": "请升级您的浏览器", "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}", @@ -12813,4 +12813,4 @@ "xpack.licensing.welcomeBanner.licenseIsExpiredDescription.updateYourLicenseLinkText": "更新您的许可", "xpack.licensing.welcomeBanner.licenseIsExpiredTitle": "您的{licenseType}许可已过期" } -} \ No newline at end of file +} From fce62f00a7ae85557f390b153e7ce092103acb55 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 13 Dec 2019 21:20:51 -0600 Subject: [PATCH 05/11] mock ui/new_platform in a number tests --- .../plugins/license_management/__jest__/start_trial.test.js | 1 + .../license_management/__jest__/telemetry_opt_in.test.js | 4 +--- .../license_management/__jest__/upload_license.test.tsx | 2 ++ .../__jest__/client_integration/remote_clusters_add.test.js | 2 ++ .../__jest__/client_integration/remote_clusters_edit.test.js | 1 + .../__jest__/client_integration/remote_clusters_list.test.js | 2 ++ .../rollup/public/crud_app/sections/job_list/job_list.test.js | 1 + .../snapshot_restore/__jest__/client_integration/home.test.ts | 1 + .../__jest__/client_integration/policy_edit.test.ts | 2 ++ .../__jest__/client_integration/repository_add.test.ts | 2 ++ .../__jest__/client_integration/repository_edit.test.ts | 2 ++ 11 files changed, 17 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/license_management/__jest__/start_trial.test.js b/x-pack/legacy/plugins/license_management/__jest__/start_trial.test.js index 903be98f225f2..eedb85016de40 100644 --- a/x-pack/legacy/plugins/license_management/__jest__/start_trial.test.js +++ b/x-pack/legacy/plugins/license_management/__jest__/start_trial.test.js @@ -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', () => { diff --git a/x-pack/legacy/plugins/license_management/__jest__/telemetry_opt_in.test.js b/x-pack/legacy/plugins/license_management/__jest__/telemetry_opt_in.test.js index 70edc67b449bb..9b08b6883b1c3 100644 --- a/x-pack/legacy/plugins/license_management/__jest__/telemetry_opt_in.test.js +++ b/x-pack/legacy/plugins/license_management/__jest__/telemetry_opt_in.test.js @@ -8,9 +8,7 @@ import { setTelemetryEnabled, setTelemetryOptInService } from '../public/np_read 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); diff --git a/x-pack/legacy/plugins/license_management/__jest__/upload_license.test.tsx b/x-pack/legacy/plugins/license_management/__jest__/upload_license.test.tsx index b852daf78ca15..ca9b5b0db9ca1 100644 --- a/x-pack/legacy/plugins/license_management/__jest__/upload_license.test.tsx +++ b/x-pack/legacy/plugins/license_management/__jest__/upload_license.test.tsx @@ -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'; diff --git a/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_add.test.js b/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_add.test.js index ec9ec87cd2823..f6d0a111d8e05 100644 --- a/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_add.test.js +++ b/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_add.test.js @@ -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', () => { diff --git a/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_edit.test.js b/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_edit.test.js index c4ac689b7ddc0..7cb80e48b196a 100644 --- a/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_edit.test.js +++ b/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_edit.test.js @@ -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'; diff --git a/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_list.test.js b/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_list.test.js index d8f690813dc12..d10eb0b0b1ced 100644 --- a/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_list.test.js +++ b/x-pack/legacy/plugins/remote_clusters/__jest__/client_integration/remote_clusters_list.test.js @@ -9,6 +9,8 @@ import { pageHelpers, setupEnvironment, nextTick, getRandomString, findTestSubje import { getRouter } from '../../public/app/services'; import { getRemoteClusterMock } from '../../fixtures/remote_cluster'; +jest.mock('ui/new_platform'); + const { setup } = pageHelpers.remoteClustersList; describe('', () => { diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js index aabe240af0e6b..07486484d528a 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js @@ -8,6 +8,7 @@ import { registerTestBed } from '../../../../../../../test_utils'; import { rollupJobsStore } from '../../store'; import { JobList } from './job_list'; +jest.mock('ui/new_platform'); jest.mock('ui/chrome', () => ({ addBasePath: () => {}, breadcrumbs: { set: () => {} }, diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts index effab0fcadf4d..69b5ca9e2b68f 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts @@ -21,6 +21,7 @@ import moment from 'moment-timezone'; const { setup } = pageHelpers.home; +jest.mock('ui/new_platform'); jest.mock('ui/i18n', () => { const I18nContext = ({ children }: any) => children; return { I18nContext }; diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_edit.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_edit.test.ts index e14a080137c60..1222697956ffb 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_edit.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_edit.test.ts @@ -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; diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_add.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_add.test.ts index df250159c7f69..1f70755d5fd85 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_add.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_add.test.ts @@ -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']; diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_edit.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_edit.test.ts index ef74482fc9de7..cca81c0e74285 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_edit.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_edit.test.ts @@ -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; From 3e3eac22686719ac4b3e009b2a018a04c1813742 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 13 Dec 2019 22:24:50 -0600 Subject: [PATCH 06/11] fix mocks for management api --- .../public/components/telemetry_form.test.js | 2 + .../management/public/legacy/section.test.js | 49 ++++++++----------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/legacy/core_plugins/telemetry/public/components/telemetry_form.test.js b/src/legacy/core_plugins/telemetry/public/components/telemetry_form.test.js index 836fbc5d914de..98dad3c7a1577 100644 --- a/src/legacy/core_plugins/telemetry/public/components/telemetry_form.test.js +++ b/src/legacy/core_plugins/telemetry/public/components/telemetry_form.test.js @@ -23,6 +23,8 @@ import { shallowWithIntl } from 'test_utils/enzyme_helpers'; import { TelemetryForm } from './telemetry_form'; import { TelemetryOptInProvider } from '../services'; +jest.mock('ui/new_platform'); + const buildTelemetryOptInProvider = () => { const mockHttp = { post: jest.fn() diff --git a/src/plugins/management/public/legacy/section.test.js b/src/plugins/management/public/legacy/section.test.js index c9fa3eebe354e..6a66ed7d2d402 100644 --- a/src/plugins/management/public/legacy/section.test.js +++ b/src/plugins/management/public/legacy/section.test.js @@ -16,62 +16,55 @@ * 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 '../../../../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 +74,7 @@ describe('ManagementSection', () => { let section; beforeEach(() => { - section = new ManagementSection('kibana'); + section = new ManagementSection('kibana', {}, capabilitiesMock); }); it('returns a ManagementSection', () => { @@ -129,7 +122,7 @@ describe('ManagementSection', () => { let section; beforeEach(() => { - section = new ManagementSection('kibana'); + section = new ManagementSection('kibana', {}, capabilitiesMock); section.register('about'); }); @@ -160,7 +153,7 @@ describe('ManagementSection', () => { let section; beforeEach(() => { - section = new ManagementSection('kibana'); + section = new ManagementSection('kibana', {}, capabilitiesMock); section.register('about'); }); @@ -187,7 +180,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 +210,7 @@ describe('ManagementSection', () => { let section; beforeEach(() => { - section = new ManagementSection('kibana'); + section = new ManagementSection('kibana', {}, capabilitiesMock); }); it('hide sets visible to false', () => { @@ -236,7 +229,7 @@ describe('ManagementSection', () => { let section; beforeEach(() => { - section = new ManagementSection('kibana'); + section = new ManagementSection('kibana', {}, capabilitiesMock); }); it('disable sets disabled to true', () => { @@ -254,7 +247,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 }); From 31305e044b4aafba86f730edb1526538a135d996 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 13 Dec 2019 23:35:52 -0600 Subject: [PATCH 07/11] fix telemetry test --- .../core_plugins/telemetry/public/components/telemetry_form.js | 2 +- .../telemetry/public/components/telemetry_form.test.js | 2 -- src/legacy/ui/public/management/index.js | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/telemetry/public/components/telemetry_form.js b/src/legacy/core_plugins/telemetry/public/components/telemetry_form.js index f6012a271cde5..1ccecc6324205 100644 --- a/src/legacy/core_plugins/telemetry/public/components/telemetry_form.js +++ b/src/legacy/core_plugins/telemetry/public/components/telemetry_form.js @@ -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'; diff --git a/src/legacy/core_plugins/telemetry/public/components/telemetry_form.test.js b/src/legacy/core_plugins/telemetry/public/components/telemetry_form.test.js index 98dad3c7a1577..836fbc5d914de 100644 --- a/src/legacy/core_plugins/telemetry/public/components/telemetry_form.test.js +++ b/src/legacy/core_plugins/telemetry/public/components/telemetry_form.test.js @@ -23,8 +23,6 @@ import { shallowWithIntl } from 'test_utils/enzyme_helpers'; import { TelemetryForm } from './telemetry_form'; import { TelemetryOptInProvider } from '../services'; -jest.mock('ui/new_platform'); - const buildTelemetryOptInProvider = () => { const mockHttp = { post: jest.fn() diff --git a/src/legacy/ui/public/management/index.js b/src/legacy/ui/public/management/index.js index f10c942fd9a32..7b1d31666775f 100644 --- a/src/legacy/ui/public/management/index.js +++ b/src/legacy/ui/public/management/index.js @@ -25,7 +25,6 @@ export { 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 { SidebarNav } from './components'; export { MANAGEMENT_BREADCRUMB } from './breadcrumbs'; From 1abbe0aa79f1f04c59a5f9d2db39e39938739ecf Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sat, 14 Dec 2019 13:17:28 -0600 Subject: [PATCH 08/11] fix test --- src/plugins/management/public/legacy/section.test.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/management/public/legacy/section.test.js b/src/plugins/management/public/legacy/section.test.js index c8461c3fe05c8..61bafd298afb3 100644 --- a/src/plugins/management/public/legacy/section.test.js +++ b/src/plugins/management/public/legacy/section.test.js @@ -23,7 +23,7 @@ import { IndexedArray } from '../../../../legacy/ui/public/indexed_array'; const capabilitiesMock = { management: { kibana: { sampleFeature2: false }, - } + }, }; describe('ManagementSection', () => { @@ -64,7 +64,11 @@ describe('ManagementSection', () => { }); it('assigns all options', () => { - const section = new ManagementSection('kibana', { description: 'test', url: 'foobar' }, capabilitiesMock); + const section = new ManagementSection( + 'kibana', + { description: 'test', url: 'foobar' }, + capabilitiesMock + ); expect(section.description).toBe('test'); expect(section.url).toBe('foobar'); }); From 1f38a12c75954e59614bb6feef3816491b012225 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 17 Dec 2019 07:51:19 -0600 Subject: [PATCH 09/11] eslint fix --- .../public/legacy/sections_register.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugins/management/public/legacy/sections_register.js b/src/plugins/management/public/legacy/sections_register.js index 4b3c91975942e..888b2c5bc3aeb 100644 --- a/src/plugins/management/public/legacy/sections_register.js +++ b/src/plugins/management/public/legacy/sections_register.js @@ -20,12 +20,16 @@ import { ManagementSection } from './section'; import { i18n } from '@kbn/i18n'; -export const management = (capabilities) => { - const main = new ManagementSection('management', { - display: i18n.translate('management.displayName', { - defaultMessage: 'Management', - }), - }, capabilities); +export const management = capabilities => { + const main = new ManagementSection( + 'management', + { + display: i18n.translate('management.displayName', { + defaultMessage: 'Management', + }), + }, + capabilities + ); main.register('data', { display: i18n.translate('management.connectDataDisplayName', { From 92a336c64487c9adac6c28542d9897c2f1c3c2d9 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 17 Dec 2019 09:27:44 -0600 Subject: [PATCH 10/11] fix karma tests --- .../ui/public/new_platform/new_platform.karma_mock.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index 20a7e0d5dde8d..3b2a77cefb730 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -137,6 +137,13 @@ export const npStart = { chrome: {}, }, plugins: { + management: { + legacy: { + getSection: () => ({ + register: sinon.fake(), + }), + }, + }, embeddable: { getEmbeddableFactory: sinon.fake(), getEmbeddableFactories: sinon.fake(), From 75e4616d0fa2cb6d745aff84bce620d5997df3c9 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 17 Dec 2019 10:52:06 -0600 Subject: [PATCH 11/11] ts fixes --- src/plugins/management/public/plugin.ts | 2 +- src/plugins/management/public/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/management/public/plugin.ts b/src/plugins/management/public/plugin.ts index bc1f3ff531a3a..c65dfd1dc7bb4 100644 --- a/src/plugins/management/public/plugin.ts +++ b/src/plugins/management/public/plugin.ts @@ -19,7 +19,7 @@ import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { ManagementStart } from './types'; -// @ts-ignorets-ignore +// @ts-ignore import { management } from './legacy'; export class ManagementPlugin implements Plugin<{}, ManagementStart> { diff --git a/src/plugins/management/public/types.ts b/src/plugins/management/public/types.ts index 4dfd8021f651c..6ca1faf338c39 100644 --- a/src/plugins/management/public/types.ts +++ b/src/plugins/management/public/types.ts @@ -18,5 +18,5 @@ */ export interface ManagementStart { - legacy: unknown; + legacy: any; }