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

Reorganizing spaces client-side plugin #53644

Merged
merged 7 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 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 @@ -148,6 +148,8 @@ export const npStart = {
legacy: {
getSection: () => ({
register: sinon.fake(),
deregister: sinon.fake(),
hasItem: sinon.fake(),
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { FormattedMessage, InjectedIntl } from '@kbn/i18n/react';
import React, { Component, Fragment } from 'react';
import { Space } from '../../../../../../../../../spaces/common/model/space';
import { SpaceAvatar } from '../../../../../../../../../spaces/public/components';
import { SpaceAvatar } from '../../../../../../../../../spaces/public/space_avatar';
import { Feature } from '../../../../../../../../../../../plugins/features/public';
import { FeaturesPrivileges, Role } from '../../../../../../../../common/model';
import { CalculatedPrivilege } from '../../../../../../../lib/kibana_privilege_calculator';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { FormattedMessage, InjectedIntl } from '@kbn/i18n/react';
import _ from 'lodash';
import React, { Component } from 'react';
import { getSpaceColor } from '../../../../../../../../../spaces/public/lib/space_attributes';
import { getSpaceColor } from '../../../../../../../../../spaces/public/space_avatar';
import { Space } from '../../../../../../../../../spaces/common/model/space';
import {
FeaturesPrivileges,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EuiComboBox, EuiComboBoxOptionProps, EuiHealth, EuiHighlight } from '@e
import { InjectedIntl } from '@kbn/i18n/react';
import React, { Component } from 'react';
import { Space } from '../../../../../../../../../spaces/common/model/space';
import { getSpaceColor } from '../../../../../../../../../spaces/public/lib/space_attributes';
import { getSpaceColor } from '../../../../../../../../../spaces/public/space_avatar';

const spaceToOption = (space?: Space, currentSelection?: 'global' | 'spaces') => {
if (!space) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
} from '@elastic/eui';
import { FormattedMessage, InjectedIntl } from '@kbn/i18n/react';
import React, { Component } from 'react';
import { SPACE_SEARCH_COUNT_THRESHOLD } from '../../../../../../../spaces/common/constants';
import { Space } from '../../../../../../../spaces/common/model/space';
import { SpaceAvatar } from '../../../../../../../spaces/public/components';
import { SpaceAvatar } from '../../../../../../../spaces/public/space_avatar';
import { SPACE_SEARCH_COUNT_THRESHOLD } from '../../../../../../../../../plugins/spaces/common/constants';
import { Space } from '../../../../../../../../../plugins/spaces/common/model/space';

interface Props {
spaces: Space[];
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ export const spaces = (kibana: Record<string, any>) =>

uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
managementSections: ['plugins/spaces/views/management'],
managementSections: [],
apps: [
{
id: 'space_selector',
title: 'Spaces',
main: 'plugins/spaces/views/space_selector',
main: 'plugins/spaces/space_selector',
url: 'space_selector',
hidden: true,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 { AdvancedSettingsService } from './advanced_settings_service';
jest.mock('ui/management', () => {
return {
PAGE_TITLE_COMPONENT: 'page_title_component',
PAGE_SUBTITLE_COMPONENT: 'page_subtitle_component',
};
});

describe('Advanced Settings Service', () => {
describe('#setup', () => {
it('registers space-aware components to augment the advanced settings screen', () => {
const deps = {
getActiveSpace: jest.fn().mockResolvedValue({ id: 'foo', name: 'foo-space' }),
registerSettingsComponent: jest.fn(),
};

const advancedSettingsService = new AdvancedSettingsService();
advancedSettingsService.setup(deps);

expect(deps.registerSettingsComponent).toHaveBeenCalledTimes(2);
expect(deps.registerSettingsComponent).toHaveBeenCalledWith(
'page_title_component',
expect.any(Function),
true
);

expect(deps.registerSettingsComponent).toHaveBeenCalledWith(
'page_subtitle_component',
expect.any(Function),
true
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 React from 'react';
import { PAGE_TITLE_COMPONENT, PAGE_SUBTITLE_COMPONENT } from 'ui/management';
import { Space } from '../../common/model/space';
import { AdvancedSettingsTitle, AdvancedSettingsSubtitle } from './components';

interface SetupDeps {
getActiveSpace: () => Promise<Space>;
registerSettingsComponent: (
id: string,
component: string | React.FC<any>,
allowOverride: boolean
) => void;
}

export class AdvancedSettingsService {
public setup({ getActiveSpace, registerSettingsComponent }: SetupDeps) {
const PageTitle = () => <AdvancedSettingsTitle getActiveSpace={getActiveSpace} />;
const SubTitle = () => <AdvancedSettingsSubtitle getActiveSpace={getActiveSpace} />;

registerSettingsComponent(PAGE_TITLE_COMPONENT, PageTitle, true);
registerSettingsComponent(PAGE_SUBTITLE_COMPONENT, SubTitle, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { EuiCallOut, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment, useState, useEffect } from 'react';
import { Space } from '../../../../../common/model/space';
import { Space } from '../../../../common/model/space';

interface Props {
getActiveSpace: () => Promise<Space>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
import { AdvancedSettingsTitle } from './advanced_settings_title';
import { SpaceAvatar } from '../../../../components';
import { SpaceAvatar } from '../../../space_avatar';
import { act } from '@testing-library/react';

describe('AdvancedSettingsTitle', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import { EuiFlexGroup, EuiFlexItem, EuiTitle } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { useState, useEffect } from 'react';
import { Space } from '../../../../../common/model/space';
import { SpaceAvatar } from '../../../../components';
import { Space } from '../../../../../../../plugins/spaces/common/model/space';
import { SpaceAvatar } from '../../../space_avatar';

interface Props {
getActiveSpace: () => Promise<Space>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export { AdvancedSettingsSubtitle } from './advanced_settings_subtitle';
export { AdvancedSettingsTitle } from './advanced_settings_title';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export { AdvancedSettingsService } from './advanced_settings_service';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './components/index';
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import React from 'react';
import { EuiLoadingSpinner, EuiText, EuiIconTip } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import {
SummarizedCopyToSpaceResult,
SummarizedSavedObjectResult,
} from '../../../../lib/copy_saved_objects_to_space';
import { SummarizedCopyToSpaceResult, SummarizedSavedObjectResult } from '..';

interface Props {
summarizedCopyResult: SummarizedCopyToSpaceResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import React from 'react';
import { EuiLoadingSpinner, EuiIconTip } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { Space } from '../../../../../common/model/space';
import { SummarizedCopyToSpaceResult } from '../../../../lib/copy_saved_objects_to_space';
import { Space } from '../../../common/model/space';
import { SummarizedCopyToSpaceResult } from '..';

interface Props {
space: Space;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
import React from 'react';
import Boom from 'boom';
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
import { mockManagementPlugin } from '../../../../../../../../../src/legacy/core_plugins/management/public/np_ready/mocks';
import { mockManagementPlugin } from '../../../../../../../src/legacy/core_plugins/management/public/np_ready/mocks';
import { CopySavedObjectsToSpaceFlyout } from './copy_to_space_flyout';
import { CopyToSpaceForm } from './copy_to_space_form';
import { EuiLoadingSpinner, EuiEmptyPrompt } from '@elastic/eui';
import { Space } from '../../../../../common/model/space';
import { Space } from '../../../common/model/space';
import { findTestSubject } from 'test_utils/find_test_subject';
import { SelectableSpacesControl } from './selectable_spaces_control';
import { act } from '@testing-library/react';
import { ProcessingCopyToSpace } from './processing_copy_to_space';
import { spacesManagerMock } from '../../../../lib/mocks';
import { SpacesManager } from '../../../../lib';
import { spacesManagerMock } from '../../spaces_manager/mocks';
import { SpacesManager } from '../../spaces_manager';
import { ToastNotifications } from 'ui/notify/toasts/toast_notifications';

jest.mock('../../../../../../../../../src/legacy/core_plugins/management/public/legacy', () => ({
jest.mock('../../../../../../../src/legacy/core_plugins/management/public/legacy', () => ({
setup: mockManagementPlugin.createSetupContract(),
start: mockManagementPlugin.createStartContract(),
}));
Expand Down Expand Up @@ -404,6 +404,7 @@ describe('CopyToSpaceFlyout', () => {
id: 'my-viz',
error: {
type: 'missing_references',
blocking: [],
references: [{ type: 'index-pattern', id: 'missing-index-pattern' }],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import { mapValues } from 'lodash';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { ToastNotifications } from 'ui/notify/toasts/toast_notifications';
import { SavedObjectsManagementRecord } from '../../../../../../../../../src/legacy/core_plugins/management/public';
import { SavedObjectsManagementRecord } from '../../../../../../../src/legacy/core_plugins/management/public';
import {
ProcessedImportResponse,
processImportResponse,
} from '../../../../../../../../../src/legacy/core_plugins/management/public';
import { Space } from '../../../../../common/model/space';
import { SpacesManager } from '../../../../lib';
} from '../../../../../../../src/legacy/core_plugins/management/public';
import { Space } from '../../../common/model/space';
import { SpacesManager } from '../../spaces_manager';
import { ProcessingCopyToSpace } from './processing_copy_to_space';
import { CopyToSpaceFlyoutFooter } from './copy_to_space_flyout_footer';
import { CopyToSpaceForm } from './copy_to_space_form';
import { CopyOptions, ImportRetry } from '../../../../lib/copy_saved_objects_to_space/types';
import { CopyOptions, ImportRetry } from '../types';

interface Props {
onClose: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import React, { Fragment } from 'react';
import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiStat, EuiHorizontalRule } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { ProcessedImportResponse } from '../../../../../../../../../src/legacy/core_plugins/management/public';
import { ImportRetry } from '../../../../lib/copy_saved_objects_to_space/types';
import { ProcessedImportResponse } from '../../../../../../../src/legacy/core_plugins/management/public';
import { ImportRetry } from '../types';

interface Props {
copyInProgress: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
EuiListGroupItem,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { CopyOptions } from '../../../../lib/copy_saved_objects_to_space/types';
import { Space } from '../../../../../common/model/space';
import { CopyOptions } from '../types';
import { Space } from '../../../common/model/space';
import { SelectableSpacesControl } from './selectable_spaces_control';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
EuiHorizontalRule,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { SavedObjectsManagementRecord } from '../../../../../../../../../src/legacy/core_plugins/management/public';
import { ProcessedImportResponse } from '../../../../../../../../../src/legacy/core_plugins/management/public';
import { summarizeCopyResult } from '../../../../lib/copy_saved_objects_to_space';
import { Space } from '../../../../../common/model/space';
import { CopyOptions, ImportRetry } from '../../../../lib/copy_saved_objects_to_space/types';
import { SavedObjectsManagementRecord } from '../../../../../../../src/legacy/core_plugins/management/public';
import { ProcessedImportResponse } from '../../../../../../../src/legacy/core_plugins/management/public';
import { Space } from '../../../common/model/space';
import { CopyOptions, ImportRetry } from '../types';
import { SpaceResult } from './space_result';
import { summarizeCopyResult } from '..';

interface Props {
savedObject: SavedObjectsManagementRecord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import React, { Fragment, useState } from 'react';
import { EuiSelectable, EuiLoadingSpinner } from '@elastic/eui';
import { SpaceAvatar } from '../../../../components';
import { Space } from '../../../../../common/model/space';
import { SpaceAvatar } from '../../space_avatar';
import { Space } from '../../../common/model/space';

interface Props {
spaces: Space[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import React from 'react';
import { EuiAccordion, EuiFlexGroup, EuiFlexItem, EuiText, EuiSpacer } from '@elastic/eui';
import { SavedObjectsManagementRecord } from '../../../../../../../../../src/legacy/core_plugins/management/public';
import { SummarizedCopyToSpaceResult } from '../../../../lib/copy_saved_objects_to_space';
import { SpaceAvatar } from '../../../../components';
import { Space } from '../../../../../common/model/space';
import { SavedObjectsManagementRecord } from '../../../../../../../src/legacy/core_plugins/management/public';
import { SummarizedCopyToSpaceResult } from '../index';
import { SpaceAvatar } from '../../space_avatar';
import { Space } from '../../../common/model/space';
import { CopyStatusSummaryIndicator } from './copy_status_summary_indicator';
import { SpaceCopyResultDetails } from './space_result_details';
import { ImportRetry } from '../../../../lib/copy_saved_objects_to_space/types';
import { ImportRetry } from '../types';

interface Props {
savedObject: SavedObjectsManagementRecord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/

import React from 'react';
import { SummarizedCopyToSpaceResult } from 'plugins/spaces/lib/copy_saved_objects_to_space';
import { EuiText, EuiFlexGroup, EuiFlexItem, EuiButtonEmpty } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { SavedObjectsManagementRecord } from '../../../../../../../../../src/legacy/core_plugins/management/public';
import { Space } from '../../../../../common/model/space';
import { SummarizedCopyToSpaceResult } from '../index';
import { SavedObjectsManagementRecord } from '../../../../../../../src/legacy/core_plugins/management/public';
import { Space } from '../../../common/model/space';
import { CopyStatusIndicator } from './copy_status_indicator';
import { ImportRetry } from '../../../../lib/copy_saved_objects_to_space/types';
import { ImportRetry } from '../types';

interface Props {
savedObject: SavedObjectsManagementRecord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { toastNotifications } from 'ui/notify';
import {
SavedObjectsManagementAction,
SavedObjectsManagementRecord,
} from '../../../../../../../src/legacy/core_plugins/management/public';
import { CopySavedObjectsToSpaceFlyout } from '../../views/management/components/copy_saved_objects_to_space';
} from '../../../../../../src/legacy/core_plugins/management/public';
import { CopySavedObjectsToSpaceFlyout } from './components';
import { SpacesManager } from '../spaces_manager';

export class CopyToSpaceSavedObjectsManagementAction extends SavedObjectsManagementAction {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 } from 'src/legacy/core_plugins/management/public';
import { CopyToSpaceSavedObjectsManagementAction } from './copy_saved_objects_to_space_action';
import { spacesManagerMock } from '../spaces_manager/mocks';
import { CopySavedObjectsToSpaceService } from '.';

describe('CopySavedObjectsToSpaceService', () => {
describe('#setup', () => {
it('registers the CopyToSpaceSavedObjectsManagementAction', () => {
const deps = {
spacesManager: spacesManagerMock.create(),
// we don't have a proper NP mock for this yet
managementSetup: ({
savedObjects: {
registry: {
has: jest.fn().mockReturnValue(false),
register: jest.fn(),
},
},
} as unknown) as ManagementSetup,
};

const service = new CopySavedObjectsToSpaceService();
service.setup(deps);

expect(deps.managementSetup.savedObjects.registry.register).toHaveBeenCalledTimes(1);
expect(deps.managementSetup.savedObjects.registry.register).toHaveBeenCalledWith(
expect.any(CopyToSpaceSavedObjectsManagementAction)
);
});
});
});
Loading