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

[7.x] Migrate savedObjectManagementActionRegistry to NP plugin (#60481) #61492

Merged
merged 1 commit into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"newsfeed": "src/plugins/newsfeed",
"regionMap": "src/legacy/core_plugins/region_map",
"savedObjects": "src/plugins/saved_objects",
"savedObjectsManagement": "src/plugins/saved_objects_management",
"server": "src/legacy/server",
"statusPage": "src/legacy/core_plugins/status_page",
"telemetry": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ import React from 'react';
import { shallowWithI18nProvider, mountWithI18nProvider } from 'test_utils/enzyme_helpers';
import { findTestSubject } from '@elastic/eui/lib/test';
import { keyCodes } from '@elastic/eui/lib/services';
import { mockManagementPlugin } from '../../../../../../../../../../management/public/np_ready/mocks';
import { npSetup as mockNpSetup } from '../../../../../../../../../../../ui/public/new_platform/__mocks__';

jest.mock('ui/kfetch', () => ({ kfetch: jest.fn() }));

jest.mock('ui/chrome', () => ({
addBasePath: () => '',
}));

jest.mock('../../../../../../../../../../management/public/legacy', () => ({
setup: mockManagementPlugin.createSetupContract(),
start: mockManagementPlugin.createStartContract(),
jest.mock('ui/new_platform', () => ({
npSetup: mockNpSetup,
}));

import { Table } from '../table';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import chrome from 'ui/chrome';
import { setup as managementSetup } from '../../../../../../../../../management/public/legacy';
import { npSetup } from 'ui/new_platform';
import React, { PureComponent, Fragment } from 'react';
import PropTypes from 'prop-types';

Expand Down Expand Up @@ -79,7 +79,7 @@ export class Table extends PureComponent {

constructor(props) {
super(props);
this.extraActions = managementSetup.savedObjects.registry.get();
this.extraActions = npSetup.plugins.savedObjectsManagement.actionRegistry.getAll();
}

onChange = ({ query, error }) => {
Expand Down
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/management/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export {
plugin,
IndexPatternCreationConfig,
IndexPatternListConfig,
SavedObjectsManagementAction,
SavedObjectsManagementRecord,
} from './np_ready';

export {
Expand Down
5 changes: 0 additions & 5 deletions src/legacy/core_plugins/management/public/np_ready/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,3 @@ export {
IndexPatternCreationConfig,
IndexPatternListConfig,
} from './services/index_pattern_management';

export {
SavedObjectsManagementAction,
SavedObjectsManagementRecord,
} from './services/saved_objects_management';
7 changes: 0 additions & 7 deletions src/legacy/core_plugins/management/public/np_ready/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ const createSetupContract = (): ManagementSetup => ({
areScriptedFieldsEnabled: jest.fn(),
} as any,
},
savedObjects: {
registry: {
register: jest.fn(),
has: jest.fn(),
get: jest.fn(() => []),
},
},
});

const createStartContract = (): ManagementStart => ({});
Expand Down
7 changes: 0 additions & 7 deletions src/legacy/core_plugins/management/public/np_ready/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from 'src/core/public';
import { HomePublicPluginSetup } from 'src/plugins/home/public';
import { IndexPatternManagementService, IndexPatternManagementSetup } from './services';
import {
SavedObjectsManagementService,
SavedObjectsManagementServiceSetup,
} from './services/saved_objects_management';

export interface ManagementPluginSetupDependencies {
home: HomePublicPluginSetup;
Expand All @@ -33,7 +29,6 @@ interface ManagementPluginStartDependencies {}

export interface ManagementSetup {
indexPattern: IndexPatternManagementSetup;
savedObjects: SavedObjectsManagementServiceSetup;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand All @@ -48,14 +43,12 @@ export class ManagementPlugin
ManagementPluginStartDependencies
> {
private readonly indexPattern = new IndexPatternManagementService();
private readonly savedObjects = new SavedObjectsManagementService();

constructor(initializerContext: PluginInitializerContext) {}

public setup(core: CoreSetup, { home }: ManagementPluginSetupDependencies) {
return {
indexPattern: this.indexPattern.setup({ httpClient: core.http, home }),
savedObjects: this.savedObjects.setup({ home }),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
*/

export * from './index_pattern_management';
export * from './saved_objects_management';

This file was deleted.

3 changes: 3 additions & 0 deletions src/legacy/ui/public/new_platform/__mocks__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { usageCollectionPluginMock } from '../../../../../plugins/usage_collecti
import { kibanaLegacyPluginMock } from '../../../../../plugins/kibana_legacy/public/mocks';
import { chartPluginMock } from '../../../../../plugins/charts/public/mocks';
import { advancedSettingsMock } from '../../../../../plugins/advanced_settings/public/mocks';
import { savedObjectsManagementPluginMock } from '../../../../../plugins/saved_objects_management/public/mocks';
/* eslint-enable @kbn/eslint/no-restricted-paths */

export const pluginsMock = {
Expand All @@ -44,6 +45,7 @@ export const pluginsMock = {
usageCollection: usageCollectionPluginMock.createSetupContract(),
advancedSettings: advancedSettingsMock.createSetupContract(),
kibanaLegacy: kibanaLegacyPluginMock.createSetupContract(),
savedObjectsManagement: savedObjectsManagementPluginMock.createSetupContract(),
}),
createStart: () => ({
data: dataPluginMock.createStartContract(),
Expand All @@ -56,6 +58,7 @@ export const pluginsMock = {
management: managementPluginMock.createStartContract(),
advancedSettings: advancedSettingsMock.createStartContract(),
kibanaLegacy: kibanaLegacyPluginMock.createStartContract(),
savedObjectsManagement: savedObjectsManagementPluginMock.createStartContract(),
}),
};

Expand Down
6 changes: 6 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ import {
} from '../../../../plugins/navigation/public';
import { VisTypeVegaSetup } from '../../../../plugins/vis_type_vega/public';
import { DiscoverSetup, DiscoverStart } from '../../../../plugins/discover/public';
import {
SavedObjectsManagementPluginSetup,
SavedObjectsManagementPluginStart,
} from '../../../../plugins/saved_objects_management/public';

export interface PluginsSetup {
bfetch: BfetchPublicSetup;
Expand All @@ -87,6 +91,7 @@ export interface PluginsSetup {
visTypeVega: VisTypeVegaSetup;
discover: DiscoverSetup;
telemetry?: TelemetryPluginSetup;
savedObjectsManagement: SavedObjectsManagementPluginSetup;
}

export interface PluginsStart {
Expand All @@ -106,6 +111,7 @@ export interface PluginsStart {
discover: DiscoverStart;
telemetry?: TelemetryPluginStart;
dashboard: DashboardStart;
savedObjectsManagement: SavedObjectsManagementPluginStart;
}

export const npSetup = {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/saved_objects_management/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"id": "savedObjectsManagement",
"version": "kibana",
"server": true,
"ui": false
"ui": true,
"requiredPlugins": ["home"]
}
32 changes: 32 additions & 0 deletions src/plugins/saved_objects_management/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { SavedObjectsManagementPlugin } from './plugin';

export { SavedObjectsManagementPluginSetup, SavedObjectsManagementPluginStart } from './plugin';
export {
ISavedObjectsManagementActionRegistry,
SavedObjectsManagementAction,
SavedObjectsManagementRecord,
} from './services';

export function plugin(initializerContext: PluginInitializerContext) {
return new SavedObjectsManagementPlugin();
}
39 changes: 39 additions & 0 deletions src/plugins/saved_objects_management/public/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 { actionRegistryMock } from './services/action_registry.mock';
import { SavedObjectsManagementPluginSetup, SavedObjectsManagementPluginStart } from './plugin';

const createSetupContractMock = (): jest.Mocked<SavedObjectsManagementPluginSetup> => {
const mock = {
actionRegistry: actionRegistryMock.create(),
};
return mock;
};

const createStartContractMock = (): jest.Mocked<SavedObjectsManagementPluginStart> => {
const mock = {};
return mock;
};

export const savedObjectsManagementPluginMock = {
createActionRegistry: actionRegistryMock.create,
createSetupContract: createSetupContractMock,
createStartContract: createStartContractMock,
};
47 changes: 47 additions & 0 deletions src/plugins/saved_objects_management/public/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 { coreMock } from '../../../core/public/mocks';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { homePluginMock } from '../../home/public/mocks';
import { SavedObjectsManagementPlugin } from './plugin';

describe('SavedObjectsManagementPlugin', () => {
let plugin: SavedObjectsManagementPlugin;

beforeEach(() => {
plugin = new SavedObjectsManagementPlugin();
});

describe('#setup', () => {
it('registers the saved_objects feature to the home plugin', async () => {
const coreSetup = coreMock.createSetup();
const homeSetup = homePluginMock.createSetupContract();

await plugin.setup(coreSetup, { home: homeSetup });

expect(homeSetup.featureCatalogue.register).toHaveBeenCalledTimes(1);
expect(homeSetup.featureCatalogue.register).toHaveBeenCalledWith(
expect.objectContaining({
id: 'saved_objects',
})
);
});
});
});
Loading