);
@@ -27,13 +21,7 @@ test('it renders without blowing up', () => {
test('it renders children by default', () => {
const wrapper = mountWithIntl(
-
+
child 1
child 2
@@ -45,13 +33,7 @@ test('it renders children by default', () => {
test('it hides children when the "hide" link is clicked', () => {
const wrapper = mountWithIntl(
-
+
child 1
child 2
diff --git a/x-pack/legacy/plugins/spaces/public/management/edit_space/section_panel/section_panel.tsx b/x-pack/plugins/spaces/public/management/edit_space/section_panel/section_panel.tsx
similarity index 77%
rename from x-pack/legacy/plugins/spaces/public/management/edit_space/section_panel/section_panel.tsx
rename to x-pack/plugins/spaces/public/management/edit_space/section_panel/section_panel.tsx
index a205130d2d765..a0a6bc5a89d33 100644
--- a/x-pack/legacy/plugins/spaces/public/management/edit_space/section_panel/section_panel.tsx
+++ b/x-pack/plugins/spaces/public/management/edit_space/section_panel/section_panel.tsx
@@ -14,7 +14,7 @@ import {
EuiTitle,
IconType,
} from '@elastic/eui';
-import { InjectedIntl } from '@kbn/i18n/react';
+import { i18n } from '@kbn/i18n';
import React, { Component, Fragment, ReactNode } from 'react';
interface Props {
@@ -22,7 +22,6 @@ interface Props {
title: string | ReactNode;
description: string;
collapsible: boolean;
- intl: InjectedIntl;
initiallyCollapsed?: boolean;
}
@@ -52,38 +51,31 @@ export class SectionPanel extends Component {
}
public getTitle = () => {
- const showLinkText = this.props.intl.formatMessage({
- id: 'xpack.spaces.management.collapsiblePanel.showLinkText',
+ const showLinkText = i18n.translate('xpack.spaces.management.collapsiblePanel.showLinkText', {
defaultMessage: 'show',
});
- const hideLinkText = this.props.intl.formatMessage({
- id: 'xpack.spaces.management.collapsiblePanel.hideLinkText',
+ const hideLinkText = i18n.translate('xpack.spaces.management.collapsiblePanel.hideLinkText', {
defaultMessage: 'hide',
});
- const showLinkDescription = this.props.intl.formatMessage(
+ const showLinkDescription = i18n.translate(
+ 'xpack.spaces.management.collapsiblePanel.showLinkDescription',
{
- id: 'xpack.spaces.management.collapsiblePanel.showLinkDescription',
defaultMessage: 'show {title}',
- },
- {
- title: this.props.description,
+ values: { title: this.props.description },
}
);
- const hideLinkDescription = this.props.intl.formatMessage(
+ const hideLinkDescription = i18n.translate(
+ 'xpack.spaces.management.collapsiblePanel.hideLinkDescription',
{
- id: 'xpack.spaces.management.collapsiblePanel.hideLinkDescription',
defaultMessage: 'hide {title}',
- },
- {
- title: this.props.description,
+ values: { title: this.props.description },
}
);
return (
- // @ts-ignore
diff --git a/x-pack/legacy/plugins/spaces/public/management/index.ts b/x-pack/plugins/spaces/public/management/index.ts
similarity index 100%
rename from x-pack/legacy/plugins/spaces/public/management/index.ts
rename to x-pack/plugins/spaces/public/management/index.ts
diff --git a/x-pack/legacy/plugins/spaces/public/management/lib/feature_utils.test.ts b/x-pack/plugins/spaces/public/management/lib/feature_utils.test.ts
similarity index 95%
rename from x-pack/legacy/plugins/spaces/public/management/lib/feature_utils.test.ts
rename to x-pack/plugins/spaces/public/management/lib/feature_utils.test.ts
index ce874956d0ef2..a3360969fb3f2 100644
--- a/x-pack/legacy/plugins/spaces/public/management/lib/feature_utils.test.ts
+++ b/x-pack/plugins/spaces/public/management/lib/feature_utils.test.ts
@@ -5,7 +5,7 @@
*/
import { getEnabledFeatures } from './feature_utils';
-import { Feature } from '../../../../../../plugins/features/public';
+import { Feature } from '../../../../features/public';
const buildFeatures = () =>
[
diff --git a/x-pack/legacy/plugins/spaces/public/management/lib/feature_utils.ts b/x-pack/plugins/spaces/public/management/lib/feature_utils.ts
similarity index 74%
rename from x-pack/legacy/plugins/spaces/public/management/lib/feature_utils.ts
rename to x-pack/plugins/spaces/public/management/lib/feature_utils.ts
index ff1688637ef73..a1b64eb954403 100644
--- a/x-pack/legacy/plugins/spaces/public/management/lib/feature_utils.ts
+++ b/x-pack/plugins/spaces/public/management/lib/feature_utils.ts
@@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { Feature } from '../../../../../../plugins/features/common';
+import { Feature } from '../../../../features/common';
-import { Space } from '../../../../../../plugins/spaces/common/model/space';
+import { Space } from '../..';
export function getEnabledFeatures(features: Feature[], space: Partial) {
return features.filter(feature => !(space.disabledFeatures || []).includes(feature.id));
diff --git a/x-pack/legacy/plugins/spaces/public/management/lib/index.ts b/x-pack/plugins/spaces/public/management/lib/index.ts
similarity index 100%
rename from x-pack/legacy/plugins/spaces/public/management/lib/index.ts
rename to x-pack/plugins/spaces/public/management/lib/index.ts
diff --git a/x-pack/legacy/plugins/spaces/public/management/lib/space_identifier_utils.test.ts b/x-pack/plugins/spaces/public/management/lib/space_identifier_utils.test.ts
similarity index 100%
rename from x-pack/legacy/plugins/spaces/public/management/lib/space_identifier_utils.test.ts
rename to x-pack/plugins/spaces/public/management/lib/space_identifier_utils.test.ts
diff --git a/x-pack/legacy/plugins/spaces/public/management/lib/space_identifier_utils.ts b/x-pack/plugins/spaces/public/management/lib/space_identifier_utils.ts
similarity index 100%
rename from x-pack/legacy/plugins/spaces/public/management/lib/space_identifier_utils.ts
rename to x-pack/plugins/spaces/public/management/lib/space_identifier_utils.ts
diff --git a/x-pack/legacy/plugins/spaces/public/management/lib/validate_space.test.ts b/x-pack/plugins/spaces/public/management/lib/validate_space.test.ts
similarity index 100%
rename from x-pack/legacy/plugins/spaces/public/management/lib/validate_space.test.ts
rename to x-pack/plugins/spaces/public/management/lib/validate_space.test.ts
diff --git a/x-pack/legacy/plugins/spaces/public/management/lib/validate_space.ts b/x-pack/plugins/spaces/public/management/lib/validate_space.ts
similarity index 100%
rename from x-pack/legacy/plugins/spaces/public/management/lib/validate_space.ts
rename to x-pack/plugins/spaces/public/management/lib/validate_space.ts
diff --git a/x-pack/plugins/spaces/public/management/management_service.test.ts b/x-pack/plugins/spaces/public/management/management_service.test.ts
new file mode 100644
index 0000000000000..d4c6bdaea2776
--- /dev/null
+++ b/x-pack/plugins/spaces/public/management/management_service.test.ts
@@ -0,0 +1,138 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { ManagementService } from '.';
+import { coreMock } from 'src/core/public/mocks';
+import { spacesManagerMock } from '../spaces_manager/mocks';
+import { managementPluginMock } from '../../../../../src/plugins/management/public/mocks';
+import { ManagementSection } from 'src/plugins/management/public';
+import { Capabilities } from 'kibana/public';
+
+describe('ManagementService', () => {
+ describe('#setup', () => {
+ it('registers the spaces management page under the kibana section', () => {
+ const mockKibanaSection = ({
+ registerApp: jest.fn(),
+ } as unknown) as ManagementSection;
+ const deps = {
+ management: managementPluginMock.createSetupContract(),
+ getStartServices: coreMock.createSetup().getStartServices,
+ spacesManager: spacesManagerMock.create(),
+ };
+
+ deps.management.sections.getSection.mockReturnValue(mockKibanaSection);
+
+ const service = new ManagementService();
+ service.setup(deps);
+
+ expect(deps.management.sections.getSection).toHaveBeenCalledTimes(1);
+ expect(deps.management.sections.getSection).toHaveBeenCalledWith('kibana');
+
+ expect(mockKibanaSection.registerApp).toHaveBeenCalledTimes(1);
+ expect(mockKibanaSection.registerApp).toHaveBeenCalledWith({
+ id: 'spaces',
+ title: 'Spaces',
+ order: 10,
+ mount: expect.any(Function),
+ });
+ });
+
+ it('will not crash if the kibana section is missing', () => {
+ const deps = {
+ management: managementPluginMock.createSetupContract(),
+ getStartServices: coreMock.createSetup().getStartServices,
+ spacesManager: spacesManagerMock.create(),
+ };
+
+ const service = new ManagementService();
+ service.setup(deps);
+ });
+ });
+
+ describe('#start', () => {
+ it('disables the spaces management page if the user is not authorized', () => {
+ const mockSpacesManagementPage = { disable: jest.fn() };
+ const mockKibanaSection = ({
+ registerApp: jest.fn().mockReturnValue(mockSpacesManagementPage),
+ } as unknown) as ManagementSection;
+
+ const deps = {
+ management: managementPluginMock.createSetupContract(),
+ getStartServices: coreMock.createSetup().getStartServices,
+ spacesManager: spacesManagerMock.create(),
+ };
+
+ deps.management.sections.getSection.mockImplementation(id => {
+ if (id === 'kibana') return mockKibanaSection;
+ throw new Error(`unexpected getSection call: ${id}`);
+ });
+
+ const service = new ManagementService();
+ service.setup(deps);
+
+ const capabilities = ({ spaces: { manage: false } } as unknown) as Capabilities;
+ service.start({ capabilities });
+
+ expect(mockKibanaSection.registerApp).toHaveBeenCalledTimes(1);
+ expect(mockSpacesManagementPage.disable).toHaveBeenCalledTimes(1);
+ });
+
+ it('does not disable the spaces management page if the user is authorized', () => {
+ const mockSpacesManagementPage = { disable: jest.fn() };
+ const mockKibanaSection = ({
+ registerApp: jest.fn().mockReturnValue(mockSpacesManagementPage),
+ } as unknown) as ManagementSection;
+
+ const deps = {
+ management: managementPluginMock.createSetupContract(),
+ getStartServices: coreMock.createSetup().getStartServices,
+ spacesManager: spacesManagerMock.create(),
+ };
+
+ deps.management.sections.getSection.mockImplementation(id => {
+ if (id === 'kibana') return mockKibanaSection;
+ throw new Error(`unexpected getSection call: ${id}`);
+ });
+
+ const service = new ManagementService();
+ service.setup(deps);
+
+ const capabilities = ({ spaces: { manage: true } } as unknown) as Capabilities;
+ service.start({ capabilities });
+
+ expect(mockKibanaSection.registerApp).toHaveBeenCalledTimes(1);
+ expect(mockSpacesManagementPage.disable).toHaveBeenCalledTimes(0);
+ });
+ });
+
+ describe('#stop', () => {
+ it('disables the spaces management page', () => {
+ const mockSpacesManagementPage = { disable: jest.fn() };
+ const mockKibanaSection = ({
+ registerApp: jest.fn().mockReturnValue(mockSpacesManagementPage),
+ } as unknown) as ManagementSection;
+
+ const deps = {
+ management: managementPluginMock.createSetupContract(),
+ getStartServices: coreMock.createSetup().getStartServices,
+ spacesManager: spacesManagerMock.create(),
+ };
+
+ deps.management.sections.getSection.mockImplementation(id => {
+ if (id === 'kibana') return mockKibanaSection;
+ throw new Error(`unexpected getSection call: ${id}`);
+ });
+
+ const service = new ManagementService();
+ service.setup(deps);
+
+ service.stop();
+
+ expect(mockKibanaSection.registerApp).toHaveBeenCalledTimes(1);
+ expect(mockSpacesManagementPage.disable).toHaveBeenCalledTimes(1);
+ });
+ });
+});
diff --git a/x-pack/plugins/spaces/public/management/management_service.tsx b/x-pack/plugins/spaces/public/management/management_service.tsx
new file mode 100644
index 0000000000000..c81a3497762a5
--- /dev/null
+++ b/x-pack/plugins/spaces/public/management/management_service.tsx
@@ -0,0 +1,51 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { ManagementSetup, ManagementApp } from 'src/plugins/management/public';
+import { CoreSetup, Capabilities } from 'src/core/public';
+import { SecurityLicense } from '../../../security/public';
+import { SpacesManager } from '../spaces_manager';
+import { PluginsStart } from '../plugin';
+import { spacesManagementApp } from './spaces_management_app';
+
+interface SetupDeps {
+ management: ManagementSetup;
+ getStartServices: CoreSetup['getStartServices'];
+ spacesManager: SpacesManager;
+ securityLicense?: SecurityLicense;
+}
+
+interface StartDeps {
+ capabilities: Capabilities;
+}
+export class ManagementService {
+ private registeredSpacesManagementApp?: ManagementApp;
+
+ public setup({ getStartServices, management, spacesManager, securityLicense }: SetupDeps) {
+ const kibanaSection = management.sections.getSection('kibana');
+ if (kibanaSection) {
+ this.registeredSpacesManagementApp = kibanaSection.registerApp(
+ spacesManagementApp.create({ getStartServices, spacesManager, securityLicense })
+ );
+ }
+ }
+
+ public start({ capabilities }: StartDeps) {
+ if (!capabilities.spaces.manage) {
+ this.disableSpacesApp();
+ }
+ }
+
+ public stop() {
+ this.disableSpacesApp();
+ }
+
+ private disableSpacesApp() {
+ if (this.registeredSpacesManagementApp) {
+ this.registeredSpacesManagementApp.disable();
+ }
+ }
+}
diff --git a/x-pack/legacy/plugins/spaces/public/management/spaces_grid/__snapshots__/spaces_grid_pages.test.tsx.snap b/x-pack/plugins/spaces/public/management/spaces_grid/__snapshots__/spaces_grid_pages.test.tsx.snap
similarity index 99%
rename from x-pack/legacy/plugins/spaces/public/management/spaces_grid/__snapshots__/spaces_grid_pages.test.tsx.snap
rename to x-pack/plugins/spaces/public/management/spaces_grid/__snapshots__/spaces_grid_pages.test.tsx.snap
index 02dbca28c7b66..aa6db7e22fd5d 100644
--- a/x-pack/legacy/plugins/spaces/public/management/spaces_grid/__snapshots__/spaces_grid_pages.test.tsx.snap
+++ b/x-pack/plugins/spaces/public/management/spaces_grid/__snapshots__/spaces_grid_pages.test.tsx.snap
@@ -39,7 +39,7 @@ exports[`SpacesGridPage renders as expected 1`] = `
>
{
+export class SpacesGridPage extends Component {
constructor(props: Props) {
super(props);
this.state = {
@@ -72,15 +73,13 @@ class SpacesGridPageUI extends Component {
return (