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

Reorganize Management apps into Ingest, Data, Alerts and Insights, Security, Kibana, and Stack groups #65796

Merged
merged 31 commits into from May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
465d813
Reorganize Management apps into Ingest, Data, Insights and Alerting, …
cjcenizal May 7, 2020
a66a7e0
Fix TS error in beats due to missing visible option.
cjcenizal May 8, 2020
7cc3490
Update snapshots.
cjcenizal May 8, 2020
25cb6ac
Remove support for icon.
cjcenizal May 9, 2020
f93aba0
Create ManagementSectionId enum and remove ability to register additi…
cjcenizal May 9, 2020
a9fdf54
Merge branch 'master' into reorg/management-apps
cjcenizal May 9, 2020
d3f557e
Return Index Patterns to Kibana section.
cjcenizal May 9, 2020
5c6d09e
Rename Beats Central Management to Beats Management in nav.
cjcenizal May 9, 2020
6ceed19
Add tooltips to sections.
cjcenizal May 10, 2020
3aa1d8f
Throw error if retrieved managementSection is missing.
cjcenizal May 12, 2020
b1771a1
Merge branch 'master' into reorg/management-apps
cjcenizal May 12, 2020
b4b5b64
Fix types to specify that a retrieved ManagementSection cannot be und…
cjcenizal May 12, 2020
accc91e
Add test to verify that the management service will throw an error if…
cjcenizal May 12, 2020
9d97c23
Revert name change to Beats Central Management.
cjcenizal May 12, 2020
af06fc5
Fixed management nav on narrow screens.
cjcenizal May 12, 2020
29fa95e
Merge branch 'master' into reorg/management-apps
cjcenizal May 12, 2020
3e38251
Remove undefined export. Fix Security and Spaces unit tests.
cjcenizal May 12, 2020
cde5d36
Update paths to apps in functional tests config.
cjcenizal May 12, 2020
d14f15f
Fix plugin functional test.
cjcenizal May 13, 2020
cd6fa5e
Fix TS errors.
cjcenizal May 14, 2020
f1ddf84
Change kibana/triggersActions paths to insightsAndAlerting/triggersAc…
cjcenizal May 14, 2020
1cf0af1
Merge branch 'master' into reorg/management-apps
cjcenizal May 14, 2020
265373e
Fix spaces snapshot.
cjcenizal May 14, 2020
68c61fa
Fix management plugin functional tests.
cjcenizal May 14, 2020
64cda1a
Fix i18n.
cjcenizal May 14, 2020
58b6e10
Fix reporting tests.
cjcenizal May 14, 2020
68c0eb4
Fix broken links and update snapshots.
cjcenizal May 15, 2020
dfccfa5
Fix watcher links.
cjcenizal May 15, 2020
3554533
Fix broken license management link.
cjcenizal May 15, 2020
79bcbb7
Merge branch 'master' into reorg/management-apps
cjcenizal May 15, 2020
69762fd
Merge branch 'master' into reorg/management-apps
cjcenizal May 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,6 +18,7 @@
*/

import { management } from 'ui/management';
import { ManagementSectionId } from '../../../../../../../plugins/management/public';
import './create_index_pattern_wizard';
import './edit_index_pattern';
import uiRoutes from 'ui/routes';
Expand Down Expand Up @@ -163,10 +164,10 @@ uiModules
};
});

management.getSection('kibana').register('index_patterns', {
management.getSection(ManagementSectionId.Data).register('index_patterns', {
display: i18n.translate('kbn.management.indexPattern.sectionsHeader', {
defaultMessage: 'Index Patterns',
}),
order: 0,
order: 1,
url: '#/management/kibana/index_patterns/',
});
7 changes: 2 additions & 5 deletions src/plugins/advanced_settings/public/plugin.ts
Expand Up @@ -18,7 +18,7 @@
*/
import { i18n } from '@kbn/i18n';
import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { ManagementApp } from '../../management/public';
import { ManagementApp, ManagementSectionId } from '../../management/public';
import { ComponentRegistry } from './component_registry';
import { AdvancedSettingsSetup, AdvancedSettingsStart, AdvancedSettingsPluginSetup } from './types';

Expand All @@ -32,10 +32,7 @@ export class AdvancedSettingsPlugin
implements Plugin<AdvancedSettingsSetup, AdvancedSettingsStart, AdvancedSettingsPluginSetup> {
private managementApp?: ManagementApp;
public setup(core: CoreSetup, { management }: AdvancedSettingsPluginSetup) {
const kibanaSection = management.sections.getSection('kibana');
if (!kibanaSection) {
throw new Error('`kibana` management section not found.');
}
const kibanaSection = management.sections.getSection(ManagementSectionId.Kibana);

this.managementApp = kibanaSection.registerApp({
id: 'settings',
Expand Down
1 change: 1 addition & 0 deletions src/plugins/management/public/index.ts
Expand Up @@ -28,6 +28,7 @@ export {
ManagementSetup,
ManagementStart,
RegisterManagementApp,
ManagementSectionId,
RegisterManagementAppArgs,
ManagementAppMountParams,
} from './types';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/management/public/legacy/index.js
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

export { LegacyManagementAdapter } from './sections_register';
export { LegacyManagementAdapter, sections } from './sections_register';
export { LegacyManagementSection } from './section';
31 changes: 7 additions & 24 deletions src/plugins/management/public/legacy/sections_register.js
Expand Up @@ -17,8 +17,9 @@
* under the License.
*/

import { LegacyManagementSection } from './section';
import { i18n } from '@kbn/i18n';
import { LegacyManagementSection } from './section';
import { managementSections } from '../management_section';

export class LegacyManagementAdapter {
main = undefined;
Expand All @@ -33,29 +34,11 @@ export class LegacyManagementAdapter {
capabilities
);

this.main.register('data', {
display: i18n.translate('management.connectDataDisplayName', {
defaultMessage: 'Connect Data',
}),
order: 0,
});

this.main.register('elasticsearch', {
display: 'Elasticsearch',
order: 20,
icon: 'logoElasticsearch',
});

this.main.register('kibana', {
display: 'Kibana',
order: 30,
icon: 'logoKibana',
});

this.main.register('logstash', {
display: 'Logstash',
order: 30,
icon: 'logoLogstash',
managementSections.forEach(({ id, title }, idx) => {
this.main.register(id, {
display: title,
order: idx,
});
});

return this.main;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/management/public/management_section.test.ts
Expand Up @@ -18,6 +18,7 @@
*/

import { ManagementSection } from './management_section';
import { ManagementSectionId } from './types';
// @ts-ignore
import { LegacyManagementSection } from './legacy';
import { coreMock } from '../../../core/public/mocks';
Expand All @@ -27,7 +28,7 @@ function createSection(registerLegacyApp: () => void) {
const getLegacySection = () => legacySection;
const getManagementSections: () => ManagementSection[] = () => [];

const testSectionConfig = { id: 'test-section', title: 'Test Section' };
const testSectionConfig = { id: ManagementSectionId.Data, title: 'Test Section' };
return new ManagementSection(
testSectionConfig,
getManagementSections,
Expand Down
31 changes: 29 additions & 2 deletions src/plugins/management/public/management_section.ts
Expand Up @@ -17,15 +17,42 @@
* under the License.
*/

import { CreateSection, RegisterManagementAppArgs } from './types';
import { CreateSection, RegisterManagementAppArgs, ManagementSectionId } from './types';
import { KibanaLegacySetup } from '../../kibana_legacy/public';
import { StartServicesAccessor } from '../../../core/public';
// @ts-ignore
import { LegacyManagementSection } from './legacy';
import { ManagementApp } from './management_app';

export const managementSections = [
{
id: ManagementSectionId.Ingest,
title: 'Ingest',
},
{
id: ManagementSectionId.Data,
title: 'Data',
},
{
id: ManagementSectionId.InsightsAndAlerting,
title: 'Insights and Alerting',
},
{
id: ManagementSectionId.Security,
title: 'Security',
},
{
id: ManagementSectionId.Kibana,
title: 'Kibana',
},
{
id: ManagementSectionId.Stack,
title: 'Stack',
},
];

export class ManagementSection {
public readonly id: string = '';
public readonly id: ManagementSectionId;
public readonly title: string = '';
public readonly apps: ManagementApp[] = [];
public readonly order: number;
Expand Down
31 changes: 8 additions & 23 deletions src/plugins/management/public/management_service.test.ts
Expand Up @@ -18,6 +18,7 @@
*/

import { ManagementService } from './management_service';
import { ManagementSectionId } from './types';
import { coreMock } from '../../../core/public/mocks';
import { npSetup } from '../../../legacy/ui/public/new_platform/__mocks__';

Expand All @@ -29,27 +30,11 @@ test('Provides default sections', () => {
() => {},
coreMock.createSetup().getStartServices
);
expect(service.getAllSections().length).toEqual(2);
expect(service.getSection('kibana')).not.toBeUndefined();
expect(service.getSection('elasticsearch')).not.toBeUndefined();
});

test('Register section, enable and disable', () => {
const service = new ManagementService().setup(
npSetup.plugins.kibanaLegacy,
() => {},
coreMock.createSetup().getStartServices
);
const testSection = service.register({ id: 'test-section', title: 'Test Section' });
expect(service.getSection('test-section')).not.toBeUndefined();

const testApp = testSection.registerApp({
id: 'test-app',
title: 'Test App',
mount: () => () => {},
});
expect(testSection.getApp('test-app')).not.toBeUndefined();
expect(service.getSectionsEnabled().length).toEqual(1);
testApp.disable();
expect(service.getSectionsEnabled().length).toEqual(0);
expect(service.getAllSections().length).toEqual(6);
expect(service.getSection(ManagementSectionId.Ingest)).toBeDefined();
expect(service.getSection(ManagementSectionId.Data)).toBeDefined();
expect(service.getSection(ManagementSectionId.InsightsAndAlerting)).toBeDefined();
expect(service.getSection(ManagementSectionId.Security)).toBeDefined();
expect(service.getSection(ManagementSectionId.Kibana)).toBeDefined();
expect(service.getSection(ManagementSectionId.Stack)).toBeDefined();
});
24 changes: 11 additions & 13 deletions src/plugins/management/public/management_service.ts
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

import { ManagementSection } from './management_section';
import { ManagementSection, managementSections } from './management_section';
import { KibanaLegacySetup } from '../../kibana_legacy/public';
// @ts-ignore
import { LegacyManagementSection } from './legacy';
import { CreateSection } from './types';
import { LegacyManagementSection, sections } from './legacy';
import { CreateSection, ManagementSectionId } from './types';
import { StartServicesAccessor, CoreStart } from '../../../core/public';

export class ManagementService {
Expand All @@ -48,8 +48,9 @@ export class ManagementService {
return newSection;
};
}
private getSection(sectionId: ManagementSection['id']) {
return this.sections.find(section => section.id === sectionId);

private getSection(sectionId: ManagementSectionId): ManagementSection {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does anybody have any suggestions on what I could do to convince TypeScript that this function will always return a ManagementSection, and not undefined? TS check shows this error everywhere this method is invoked:

 Object is possibly 'undefined'.

Copy link
Member

Choose a reason for hiding this comment

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

We could consider throwing if find returns undefined. That would give us both transpile-time and runtime guarantees

Copy link
Contributor

Choose a reason for hiding this comment

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

See my previous comment. I consider this a flaw in the API. I think throwing will work in the mean time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Matt! I updated the code to throw.

return this.sections.find(section => section.id === sectionId) as ManagementSection;
}

private getAllSections() {
Expand Down Expand Up @@ -79,16 +80,13 @@ export class ManagementService {
getStartServices
);

register({ id: 'kibana', title: 'Kibana', order: 30, euiIconType: 'logoKibana' });
register({
id: 'elasticsearch',
title: 'Elasticsearch',
order: 20,
euiIconType: 'logoElasticsearch',
});
managementSections.forEach(
({ id, title }: { id: ManagementSectionId; title: string }, idx: number) => {
register({ id, title, order: idx });
}
);

return {
register,
...this.sharedInterface,
};
}
Expand Down
1 change: 0 additions & 1 deletion src/plugins/management/public/mocks/index.ts
Expand Up @@ -30,7 +30,6 @@ const createManagementSectionMock = (): jest.Mocked<PublicMethodsOf<ManagementSe

const createSetupContract = (): DeeplyMockedKeys<ManagementSetup> => ({
sections: {
register: jest.fn(),
getSection: jest.fn().mockReturnValue(createManagementSectionMock()),
getAllSections: jest.fn().mockReturnValue([]),
},
Expand Down
31 changes: 29 additions & 2 deletions src/plugins/management/public/types.ts
Expand Up @@ -17,6 +17,25 @@
* under the License.
*/

/*
* 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 { IconType } from '@elastic/eui';
import { ManagementApp } from './management_app';
import { ManagementSection } from './management_section';
Expand All @@ -31,10 +50,18 @@ export interface ManagementStart {
legacy: any;
}

export enum ManagementSectionId {
Ingest = 'ingest',
Data = 'data',
InsightsAndAlerting = 'insightsAndAlerting',
Security = 'security',
Kibana = 'kibana',
Stack = 'stack',
}

interface SectionsServiceSetup {
getSection: (sectionId: ManagementSection['id']) => ManagementSection | undefined;
getAllSections: () => ManagementSection[];
register: RegisterSection;
}

interface SectionsServiceStart {
Expand All @@ -44,7 +71,7 @@ interface SectionsServiceStart {
}

export interface CreateSection {
id: string;
id: ManagementSectionId;
title: string;
order?: number;
euiIconType?: string; // takes precedence over `icon` property.
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/saved_objects_management/public/plugin.ts
Expand Up @@ -19,7 +19,7 @@

import { i18n } from '@kbn/i18n';
import { CoreSetup, CoreStart, Plugin } from 'src/core/public';
import { ManagementSetup } from '../../management/public';
import { ManagementSetup, ManagementSectionId } from '../../management/public';
import { DataPublicPluginStart } from '../../data/public';
import { DashboardStart } from '../../dashboard/public';
import { DiscoverStart } from '../../discover/public';
Expand Down Expand Up @@ -87,10 +87,7 @@ export class SavedObjectsManagementPlugin
category: FeatureCatalogueCategory.ADMIN,
});

const kibanaSection = management.sections.getSection('kibana');
if (!kibanaSection) {
throw new Error('`kibana` management section not found.');
}
const kibanaSection = management.sections.getSection(ManagementSectionId.Kibana);
kibanaSection.registerApp({
id: 'objects',
title: i18n.translate('savedObjectsManagement.managementSectionLabel', {
Expand Down
Expand Up @@ -9,4 +9,4 @@ export { INDEX_NAMES } from './index_names';
export { PLUGIN } from './plugin';
export { LICENSES, REQUIRED_LICENSES, REQUIRED_ROLES } from './security';
export { TABLE_CONFIG } from './table';
export const BASE_PATH = '/management/beats_management';
export const BASE_PATH = '/management/ingest/beats_management';
18 changes: 2 additions & 16 deletions x-pack/legacy/plugins/beats_management/public/index.tsx
Expand Up @@ -26,7 +26,7 @@ async function startApp(libs: FrontendLibs) {
BASE_PATH,
<ThemeProvider theme={{ eui: euiVars }}>
<I18nContext>
<HashRouter basename="/management/beats_management">
<HashRouter basename={BASE_PATH}>
<UnstatedProvider inject={[new BeatsContainer(libs), new TagsContainer(libs)]}>
<BreadcrumbProvider useGlobalBreadcrumbs={libs.framework.versionGreaterThen('6.7.0')}>
<Subscribe to={[BeatsContainer, TagsContainer]}>
Expand All @@ -52,21 +52,7 @@ async function startApp(libs: FrontendLibs) {
await libs.framework.waitUntilFrameworkReady();

if (libs.framework.licenseIsAtLeast('standard')) {
libs.framework.registerManagementSection({
id: 'beats',
name: i18n.translate('xpack.beatsManagement.centralManagementSectionLabel', {
defaultMessage: 'Beats',
}),
iconName: 'logoBeats',
});

libs.framework.registerManagementUI({
sectionId: 'beats',
name: i18n.translate('xpack.beatsManagement.centralManagementLinkLabel', {
defaultMessage: 'Central Management',
}),
basePath: BASE_PATH,
});
libs.framework.registerManagementSection();
}
}

Expand Down
Expand Up @@ -21,19 +21,7 @@ export interface FrameworkAdapter {
component: React.ReactElement<any>,
toController: 'management' | 'self'
): void;
registerManagementSection(settings: {
id?: string;
name: string;
iconName: string;
order?: number;
}): void;
registerManagementUI(settings: {
sectionId?: string;
name: string;
basePath: string;
visable?: boolean;
order?: number;
}): void;
registerManagementSection(): void;
}

export const RuntimeFrameworkInfo = t.type({
Expand Down