* create empty plugin + move home feature registration to it * move the so action_registry to new plugin * adapt existing calls to the registry * fix i18n namespace * fix table unit tests * update codeowners * rename plugin to match other PRs * remove registerLegacyAPI from spaces public plugin * fix typo Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
a18633da23
commit
a686ed419a
|
@ -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": [
|
||||
|
|
|
@ -21,7 +21,7 @@ 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() }));
|
||||
|
||||
|
@ -29,9 +29,8 @@ 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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -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 }) => {
|
||||
|
|
|
@ -30,8 +30,6 @@ export {
|
|||
plugin,
|
||||
IndexPatternCreationConfig,
|
||||
IndexPatternListConfig,
|
||||
SavedObjectsManagementAction,
|
||||
SavedObjectsManagementRecord,
|
||||
} from './np_ready';
|
||||
|
||||
export {
|
||||
|
|
|
@ -40,8 +40,3 @@ export {
|
|||
IndexPatternCreationConfig,
|
||||
IndexPatternListConfig,
|
||||
} from './services/index_pattern_management';
|
||||
|
||||
export {
|
||||
SavedObjectsManagementAction,
|
||||
SavedObjectsManagementRecord,
|
||||
} from './services/saved_objects_management';
|
||||
|
|
|
@ -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 => ({});
|
||||
|
|
|
@ -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;
|
||||
|
@ -33,7 +29,6 @@ interface ManagementPluginStartDependencies {}
|
|||
|
||||
export interface ManagementSetup {
|
||||
indexPattern: IndexPatternManagementSetup;
|
||||
savedObjects: SavedObjectsManagementServiceSetup;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
|
@ -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 }),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -18,4 +18,3 @@
|
|||
*/
|
||||
|
||||
export * from './index_pattern_management';
|
||||
export * from './saved_objects_management';
|
||||
|
|
|
@ -1,55 +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 { SavedObjectsManagementActionRegistry } from './saved_objects_management_action_registry';
|
||||
import { SavedObjectsManagementAction } from './saved_objects_management_action';
|
||||
|
||||
describe('SavedObjectsManagementActionRegistry', () => {
|
||||
it('allows actions to be registered and retrieved', () => {
|
||||
const action = { id: 'foo' } as SavedObjectsManagementAction;
|
||||
SavedObjectsManagementActionRegistry.register(action);
|
||||
expect(SavedObjectsManagementActionRegistry.get()).toContain(action);
|
||||
});
|
||||
|
||||
it('requires an "id" property', () => {
|
||||
expect(() =>
|
||||
SavedObjectsManagementActionRegistry.register({} as SavedObjectsManagementAction)
|
||||
).toThrowErrorMatchingInlineSnapshot(`"Saved Objects Management Actions must have an id"`);
|
||||
});
|
||||
|
||||
it('does not allow actions with duplicate ids to be registered', () => {
|
||||
const action = { id: 'my-action' } as SavedObjectsManagementAction;
|
||||
SavedObjectsManagementActionRegistry.register(action);
|
||||
expect(() =>
|
||||
SavedObjectsManagementActionRegistry.register(action)
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Saved Objects Management Action with id 'my-action' already exists"`
|
||||
);
|
||||
});
|
||||
|
||||
it('#has returns true when an action with a matching ID exists', () => {
|
||||
const action = { id: 'existing-action' } as SavedObjectsManagementAction;
|
||||
SavedObjectsManagementActionRegistry.register(action);
|
||||
expect(SavedObjectsManagementActionRegistry.has('existing-action')).toEqual(true);
|
||||
});
|
||||
|
||||
it(`#has returns false when an action with doesn't exist`, () => {
|
||||
expect(SavedObjectsManagementActionRegistry.has('missing-action')).toEqual(false);
|
||||
});
|
||||
});
|
|
@ -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 = {
|
||||
|
@ -44,6 +45,7 @@ export const pluginsMock = {
|
|||
usageCollection: usageCollectionPluginMock.createSetupContract(),
|
||||
advancedSettings: advancedSettingsMock.createSetupContract(),
|
||||
kibanaLegacy: kibanaLegacyPluginMock.createSetupContract(),
|
||||
savedObjectsManagement: savedObjectsManagementPluginMock.createSetupContract(),
|
||||
}),
|
||||
createStart: () => ({
|
||||
data: dataPluginMock.createStartContract(),
|
||||
|
@ -56,6 +58,7 @@ export const pluginsMock = {
|
|||
management: managementPluginMock.createStartContract(),
|
||||
advancedSettings: advancedSettingsMock.createStartContract(),
|
||||
kibanaLegacy: kibanaLegacyPluginMock.createStartContract(),
|
||||
savedObjectsManagement: savedObjectsManagementPluginMock.createStartContract(),
|
||||
}),
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -87,6 +91,7 @@ export interface PluginsSetup {
|
|||
visTypeVega: VisTypeVegaSetup;
|
||||
discover: DiscoverSetup;
|
||||
telemetry?: TelemetryPluginSetup;
|
||||
savedObjectsManagement: SavedObjectsManagementPluginSetup;
|
||||
}
|
||||
|
||||
export interface PluginsStart {
|
||||
|
@ -106,6 +111,7 @@ export interface PluginsStart {
|
|||
discover: DiscoverStart;
|
||||
telemetry?: TelemetryPluginStart;
|
||||
dashboard: DashboardStart;
|
||||
savedObjectsManagement: SavedObjectsManagementPluginStart;
|
||||
}
|
||||
|
||||
export const npSetup = {
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
"id": "savedObjectsManagement",
|
||||
"version": "kibana",
|
||||
"server": true,
|
||||
"ui": false
|
||||
"ui": true,
|
||||
"requiredPlugins": ["home"]
|
||||
}
|
||||
|
|
32
src/plugins/saved_objects_management/public/index.ts
Normal file
32
src/plugins/saved_objects_management/public/index.ts
Normal file
|
@ -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
src/plugins/saved_objects_management/public/mocks.ts
Normal file
39
src/plugins/saved_objects_management/public/mocks.ts
Normal file
|
@ -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
src/plugins/saved_objects_management/public/plugin.test.ts
Normal file
47
src/plugins/saved_objects_management/public/plugin.test.ts
Normal file
|
@ -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',
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -18,24 +18,44 @@
|
|||
*/
|
||||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { CoreSetup, CoreStart, Plugin } from 'src/core/public';
|
||||
import { HomePublicPluginSetup, FeatureCatalogueCategory } from '../../home/public';
|
||||
import {
|
||||
FeatureCatalogueCategory,
|
||||
HomePublicPluginSetup,
|
||||
} from '../../../../../../../plugins/home/public';
|
||||
import { SavedObjectsManagementActionRegistry } from './saved_objects_management_action_registry';
|
||||
SavedObjectsManagementActionRegistry,
|
||||
ISavedObjectsManagementActionRegistry,
|
||||
} from './services';
|
||||
|
||||
interface SetupDependencies {
|
||||
export interface SavedObjectsManagementPluginSetup {
|
||||
actionRegistry: ISavedObjectsManagementActionRegistry;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface SavedObjectsManagementPluginStart {}
|
||||
|
||||
export interface SetupDependencies {
|
||||
home: HomePublicPluginSetup;
|
||||
}
|
||||
|
||||
export class SavedObjectsManagementService {
|
||||
public setup({ home }: SetupDependencies) {
|
||||
export class SavedObjectsManagementPlugin
|
||||
implements
|
||||
Plugin<
|
||||
SavedObjectsManagementPluginSetup,
|
||||
SavedObjectsManagementPluginStart,
|
||||
SetupDependencies,
|
||||
{}
|
||||
> {
|
||||
private actionRegistry = new SavedObjectsManagementActionRegistry();
|
||||
|
||||
public setup(
|
||||
core: CoreSetup<{}>,
|
||||
{ home }: SetupDependencies
|
||||
): SavedObjectsManagementPluginSetup {
|
||||
home.featureCatalogue.register({
|
||||
id: 'saved_objects',
|
||||
title: i18n.translate('management.objects.savedObjectsTitle', {
|
||||
title: i18n.translate('savedObjectsManagement.objects.savedObjectsTitle', {
|
||||
defaultMessage: 'Saved Objects',
|
||||
}),
|
||||
description: i18n.translate('management.objects.savedObjectsDescription', {
|
||||
description: i18n.translate('savedObjectsManagement.objects.savedObjectsDescription', {
|
||||
defaultMessage:
|
||||
'Import, export, and manage your saved searches, visualizations, and dashboards.',
|
||||
}),
|
||||
|
@ -46,12 +66,11 @@ export class SavedObjectsManagementService {
|
|||
});
|
||||
|
||||
return {
|
||||
registry: SavedObjectsManagementActionRegistry,
|
||||
actionRegistry: this.actionRegistry,
|
||||
};
|
||||
}
|
||||
|
||||
public stop() {}
|
||||
public start(core: CoreStart) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export type SavedObjectsManagementServiceSetup = ReturnType<SavedObjectsManagementService['setup']>;
|
|
@ -16,22 +16,22 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { SavedObjectsManagementAction } from './saved_objects_management_action';
|
||||
|
||||
const actions: Map<string, SavedObjectsManagementAction> = new Map();
|
||||
import { ISavedObjectsManagementActionRegistry } from './action_registry';
|
||||
|
||||
export const SavedObjectsManagementActionRegistry = {
|
||||
register: (action: SavedObjectsManagementAction) => {
|
||||
if (!action.id) {
|
||||
throw new TypeError('Saved Objects Management Actions must have an id');
|
||||
}
|
||||
if (actions.has(action.id)) {
|
||||
throw new Error(`Saved Objects Management Action with id '${action.id}' already exists`);
|
||||
}
|
||||
actions.set(action.id, action);
|
||||
},
|
||||
const createRegistryMock = (): jest.Mocked<ISavedObjectsManagementActionRegistry> => {
|
||||
const mock = {
|
||||
register: jest.fn(),
|
||||
has: jest.fn(),
|
||||
getAll: jest.fn(),
|
||||
};
|
||||
|
||||
has: (actionId: string) => actions.has(actionId),
|
||||
mock.has.mockReturnValue(true);
|
||||
mock.getAll.mockReturnValue([]);
|
||||
|
||||
get: () => Array.from(actions.values()),
|
||||
return mock;
|
||||
};
|
||||
|
||||
export const actionRegistryMock = {
|
||||
create: createRegistryMock,
|
||||
};
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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 { SavedObjectsManagementActionRegistry } from './action_registry';
|
||||
import { SavedObjectsManagementAction } from './action_types';
|
||||
|
||||
class DummyAction extends SavedObjectsManagementAction {
|
||||
constructor(public id: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
public euiAction = {
|
||||
name: 'name',
|
||||
description: 'description',
|
||||
icon: 'icon',
|
||||
type: 'type',
|
||||
};
|
||||
|
||||
public render = () => '';
|
||||
}
|
||||
|
||||
describe('SavedObjectsManagementActionRegistry', () => {
|
||||
let registry: SavedObjectsManagementActionRegistry;
|
||||
|
||||
const createAction = (id: string): SavedObjectsManagementAction => {
|
||||
return new DummyAction(id);
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
registry = new SavedObjectsManagementActionRegistry();
|
||||
});
|
||||
|
||||
describe('#register', () => {
|
||||
it('allows actions to be registered and retrieved', () => {
|
||||
const action = createAction('foo');
|
||||
registry.register(action);
|
||||
expect(registry.getAll()).toContain(action);
|
||||
});
|
||||
|
||||
it('does not allow actions with duplicate ids to be registered', () => {
|
||||
const action = createAction('my-action');
|
||||
registry.register(action);
|
||||
expect(() => registry.register(action)).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Saved Objects Management Action with id 'my-action' already exists"`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#has', () => {
|
||||
it('returns true when an action with a matching ID exists', () => {
|
||||
const action = createAction('existing-action');
|
||||
registry.register(action);
|
||||
expect(registry.has('existing-action')).toEqual(true);
|
||||
});
|
||||
|
||||
it(`returns false when an action doesn't exist`, () => {
|
||||
expect(registry.has('missing-action')).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 { SavedObjectsManagementAction } from './action_types';
|
||||
|
||||
export type ISavedObjectsManagementActionRegistry = PublicMethodsOf<
|
||||
SavedObjectsManagementActionRegistry
|
||||
>;
|
||||
|
||||
export class SavedObjectsManagementActionRegistry {
|
||||
private readonly actions = new Map<string, SavedObjectsManagementAction>();
|
||||
|
||||
/**
|
||||
* register given action in the registry.
|
||||
*/
|
||||
register(action: SavedObjectsManagementAction) {
|
||||
if (this.actions.has(action.id)) {
|
||||
throw new Error(`Saved Objects Management Action with id '${action.id}' already exists`);
|
||||
}
|
||||
this.actions.set(action.id, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the registry contains given action, false otherwise.
|
||||
*/
|
||||
has(actionId: string) {
|
||||
return this.actions.has(actionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* return all {@link SavedObjectsManagementAction | actions} currently registered.
|
||||
*/
|
||||
getAll() {
|
||||
return [...this.actions.values()];
|
||||
}
|
||||
}
|
|
@ -18,12 +18,8 @@
|
|||
*/
|
||||
|
||||
import { ReactNode } from 'react';
|
||||
import { SavedObjectReference } from 'src/core/public';
|
||||
|
||||
export interface SavedObjectsManagementRecordReference {
|
||||
type: string;
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
export interface SavedObjectsManagementRecord {
|
||||
type: string;
|
||||
id: string;
|
||||
|
@ -31,7 +27,7 @@ export interface SavedObjectsManagementRecord {
|
|||
icon: string;
|
||||
title: string;
|
||||
};
|
||||
references: SavedObjectsManagementRecordReference[];
|
||||
references: SavedObjectReference[];
|
||||
}
|
||||
|
||||
export abstract class SavedObjectsManagementAction {
|
|
@ -17,6 +17,8 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
export * from './saved_objects_management_action_registry';
|
||||
export * from './saved_objects_management_action';
|
||||
export * from './saved_objects_management_service';
|
||||
export {
|
||||
SavedObjectsManagementActionRegistry,
|
||||
ISavedObjectsManagementActionRegistry,
|
||||
} from './action_registry';
|
||||
export { SavedObjectsManagementAction, SavedObjectsManagementRecord } from './action_types';
|
|
@ -4,22 +4,12 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { SavedObjectsManagementAction } from 'src/legacy/core_plugins/management/public';
|
||||
import { npSetup } from 'ui/new_platform';
|
||||
import routes from 'ui/routes';
|
||||
import { SpacesPluginSetup } from '../../../../plugins/spaces/public';
|
||||
import { setup as managementSetup } from '../../../../../src/legacy/core_plugins/management/public/legacy';
|
||||
|
||||
const legacyAPI = {
|
||||
registerSavedObjectsManagementAction: (action: SavedObjectsManagementAction) => {
|
||||
managementSetup.savedObjects.registry.register(action);
|
||||
},
|
||||
};
|
||||
|
||||
const spaces = (npSetup.plugins as any).spaces as SpacesPluginSetup;
|
||||
if (spaces) {
|
||||
spaces.registerLegacyAPI(legacyAPI);
|
||||
|
||||
routes.when('/management/spaces/list', { redirectTo: '/management/kibana/spaces' });
|
||||
routes.when('/management/spaces/create', { redirectTo: '/management/kibana/spaces/create' });
|
||||
routes.when('/management/spaces/edit/:spaceId', {
|
||||
|
|
|
@ -4,7 +4,14 @@
|
|||
"kibanaVersion": "kibana",
|
||||
"configPath": ["xpack", "spaces"],
|
||||
"requiredPlugins": ["features", "licensing"],
|
||||
"optionalPlugins": ["advancedSettings", "home", "management", "security", "usageCollection"],
|
||||
"optionalPlugins": [
|
||||
"advancedSettings",
|
||||
"home",
|
||||
"management",
|
||||
"security",
|
||||
"usageCollection",
|
||||
"savedObjectsManagement"
|
||||
],
|
||||
"server": true,
|
||||
"ui": true
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ import { i18n } from '@kbn/i18n';
|
|||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
import { ToastsStart } from 'src/core/public';
|
||||
import {
|
||||
SavedObjectsManagementRecord,
|
||||
ProcessedImportResponse,
|
||||
processImportResponse,
|
||||
} from '../../../../../../src/legacy/core_plugins/management/public';
|
||||
import { SavedObjectsManagementRecord } from '../../../../../../src/plugins/saved_objects_management/public';
|
||||
import { Space } from '../../../common/model/space';
|
||||
import { SpacesManager } from '../../spaces_manager';
|
||||
import { ProcessingCopyToSpace } from './processing_copy_to_space';
|
||||
|
|
|
@ -13,10 +13,8 @@ import {
|
|||
EuiHorizontalRule,
|
||||
} from '@elastic/eui';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
import {
|
||||
SavedObjectsManagementRecord,
|
||||
ProcessedImportResponse,
|
||||
} from '../../../../../../src/legacy/core_plugins/management/public';
|
||||
import { ProcessedImportResponse } from '../../../../../../src/legacy/core_plugins/management/public';
|
||||
import { SavedObjectsManagementRecord } from '../../../../../../src/plugins/saved_objects_management/public';
|
||||
import { Space } from '../../../common/model/space';
|
||||
import { CopyOptions, ImportRetry } from '../types';
|
||||
import { SpaceResult } from './space_result';
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import React from 'react';
|
||||
import { EuiAccordion, EuiFlexGroup, EuiFlexItem, EuiText, EuiSpacer } from '@elastic/eui';
|
||||
import { SavedObjectsManagementRecord } from '../../../../../../src/legacy/core_plugins/management/public';
|
||||
import { SavedObjectsManagementRecord } from '../../../../../../src/plugins/saved_objects_management/public';
|
||||
import { SummarizedCopyToSpaceResult } from '../index';
|
||||
import { SpaceAvatar } from '../../space_avatar';
|
||||
import { Space } from '../../../common/model/space';
|
||||
|
|
|
@ -8,7 +8,7 @@ import React from 'react';
|
|||
import { EuiText, EuiFlexGroup, EuiFlexItem, EuiButtonEmpty } from '@elastic/eui';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
import { SummarizedCopyToSpaceResult } from '../index';
|
||||
import { SavedObjectsManagementRecord } from '../../../../../../src/legacy/core_plugins/management/public';
|
||||
import { SavedObjectsManagementRecord } from '../../../../../../src/plugins/saved_objects_management/public';
|
||||
import { Space } from '../../../common/model/space';
|
||||
import { CopyStatusIndicator } from './copy_status_indicator';
|
||||
import { ImportRetry } from '../types';
|
||||
|
|
|
@ -9,7 +9,7 @@ import { NotificationsStart } from 'src/core/public';
|
|||
import {
|
||||
SavedObjectsManagementAction,
|
||||
SavedObjectsManagementRecord,
|
||||
} from '../../../../../src/legacy/core_plugins/management/public';
|
||||
} from '../../../../../src/plugins/saved_objects_management/public';
|
||||
import { CopySavedObjectsToSpaceFlyout } from './components';
|
||||
import { SpacesManager } from '../spaces_manager';
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
* 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 '.';
|
||||
import { notificationServiceMock } from 'src/core/public/mocks';
|
||||
import { savedObjectsManagementPluginMock } from '../../../../../src/plugins/saved_objects_management/public/mocks';
|
||||
|
||||
describe('CopySavedObjectsToSpaceService', () => {
|
||||
describe('#setup', () => {
|
||||
|
@ -16,22 +16,14 @@ describe('CopySavedObjectsToSpaceService', () => {
|
|||
const deps = {
|
||||
spacesManager: spacesManagerMock.create(),
|
||||
notificationsSetup: notificationServiceMock.createSetupContract(),
|
||||
// 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,
|
||||
savedObjectsManagementSetup: savedObjectsManagementPluginMock.createSetupContract(),
|
||||
};
|
||||
|
||||
const service = new CopySavedObjectsToSpaceService();
|
||||
service.setup(deps);
|
||||
|
||||
expect(deps.managementSetup.savedObjects.registry.register).toHaveBeenCalledTimes(1);
|
||||
expect(deps.managementSetup.savedObjects.registry.register).toHaveBeenCalledWith(
|
||||
expect(deps.savedObjectsManagementSetup.actionRegistry.register).toHaveBeenCalledTimes(1);
|
||||
expect(deps.savedObjectsManagementSetup.actionRegistry.register).toHaveBeenCalledWith(
|
||||
expect.any(CopyToSpaceSavedObjectsManagementAction)
|
||||
);
|
||||
});
|
||||
|
|
|
@ -4,20 +4,20 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { ManagementSetup } from 'src/legacy/core_plugins/management/public';
|
||||
import { NotificationsSetup } from 'src/core/public';
|
||||
import { SavedObjectsManagementPluginSetup } from 'src/plugins/saved_objects_management/public';
|
||||
import { CopyToSpaceSavedObjectsManagementAction } from './copy_saved_objects_to_space_action';
|
||||
import { SpacesManager } from '../spaces_manager';
|
||||
|
||||
interface SetupDeps {
|
||||
spacesManager: SpacesManager;
|
||||
managementSetup: Pick<ManagementSetup, 'savedObjects'>;
|
||||
savedObjectsManagementSetup: SavedObjectsManagementPluginSetup;
|
||||
notificationsSetup: NotificationsSetup;
|
||||
}
|
||||
|
||||
export class CopySavedObjectsToSpaceService {
|
||||
public setup({ spacesManager, managementSetup, notificationsSetup }: SetupDeps) {
|
||||
public setup({ spacesManager, savedObjectsManagementSetup, notificationsSetup }: SetupDeps) {
|
||||
const action = new CopyToSpaceSavedObjectsManagementAction(spacesManager, notificationsSetup);
|
||||
managementSetup.savedObjects.registry.register(action);
|
||||
savedObjectsManagementSetup.actionRegistry.register(action);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import {
|
||||
ProcessedImportResponse,
|
||||
SavedObjectsManagementRecord,
|
||||
} from 'src/legacy/core_plugins/management/public';
|
||||
import { ProcessedImportResponse } from 'src/legacy/core_plugins/management/public';
|
||||
import { SavedObjectsManagementRecord } from 'src/plugins/saved_objects_management/public';
|
||||
|
||||
export interface SummarizedSavedObjectResult {
|
||||
type: string;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import { CoreSetup, CoreStart, Plugin } from 'src/core/public';
|
||||
import { HomePublicPluginSetup } from 'src/plugins/home/public';
|
||||
import { SavedObjectsManagementAction } from 'src/legacy/core_plugins/management/public';
|
||||
import { SavedObjectsManagementPluginSetup } from 'src/plugins/saved_objects_management/public';
|
||||
import { ManagementStart, ManagementSetup } from 'src/plugins/management/public';
|
||||
import { AdvancedSettingsSetup } from 'src/plugins/advanced_settings/public';
|
||||
import { FeaturesPluginStart } from '../../features/public';
|
||||
|
@ -24,6 +24,7 @@ export interface PluginsSetup {
|
|||
home?: HomePublicPluginSetup;
|
||||
management?: ManagementSetup;
|
||||
security?: SecurityPluginSetup;
|
||||
savedObjectsManagement?: SavedObjectsManagementPluginSetup;
|
||||
}
|
||||
|
||||
export interface PluginsStart {
|
||||
|
@ -32,10 +33,6 @@ export interface PluginsStart {
|
|||
security?: SecurityPluginStart;
|
||||
}
|
||||
|
||||
interface LegacyAPI {
|
||||
registerSavedObjectsManagementAction: (action: SavedObjectsManagementAction) => void;
|
||||
}
|
||||
|
||||
export type SpacesPluginSetup = ReturnType<SpacesPlugin['setup']>;
|
||||
export type SpacesPluginStart = ReturnType<SpacesPlugin['start']>;
|
||||
|
||||
|
@ -69,34 +66,22 @@ export class SpacesPlugin implements Plugin<SpacesPluginSetup, SpacesPluginStart
|
|||
});
|
||||
}
|
||||
|
||||
if (plugins.savedObjectsManagement) {
|
||||
const copySavedObjectsToSpaceService = new CopySavedObjectsToSpaceService();
|
||||
copySavedObjectsToSpaceService.setup({
|
||||
spacesManager: this.spacesManager,
|
||||
notificationsSetup: core.notifications,
|
||||
savedObjectsManagementSetup: plugins.savedObjectsManagement,
|
||||
});
|
||||
}
|
||||
|
||||
spaceSelectorApp.create({
|
||||
getStartServices: core.getStartServices,
|
||||
application: core.application,
|
||||
spacesManager: this.spacesManager,
|
||||
});
|
||||
|
||||
return {
|
||||
registerLegacyAPI: (legacyAPI: LegacyAPI) => {
|
||||
const copySavedObjectsToSpaceService = new CopySavedObjectsToSpaceService();
|
||||
copySavedObjectsToSpaceService.setup({
|
||||
spacesManager: this.spacesManager,
|
||||
managementSetup: {
|
||||
savedObjects: {
|
||||
registry: {
|
||||
register: action => legacyAPI.registerSavedObjectsManagementAction(action),
|
||||
has: () => {
|
||||
throw new Error('not available in legacy shim');
|
||||
},
|
||||
get: () => {
|
||||
throw new Error('not available in legacy shim');
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
notificationsSetup: core.notifications,
|
||||
});
|
||||
},
|
||||
};
|
||||
return {};
|
||||
}
|
||||
|
||||
public start(core: CoreStart, plugins: PluginsStart) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import { Observable, BehaviorSubject } from 'rxjs';
|
||||
import { skipWhile } from 'rxjs/operators';
|
||||
import { HttpSetup } from 'src/core/public';
|
||||
import { SavedObjectsManagementRecord } from 'src/legacy/core_plugins/management/public';
|
||||
import { SavedObjectsManagementRecord } from 'src/plugins/saved_objects_management/public';
|
||||
import { Space } from '../../common/model/space';
|
||||
import { GetSpacePurpose } from '../../common/model/types';
|
||||
import { CopySavedObjectsToSpaceResponse } from '../copy_saved_objects_to_space/types';
|
||||
|
|
|
@ -1530,8 +1530,8 @@
|
|||
"advancedSettings.voiceAnnouncement.searchResultScreenReaderMessage": "{query} を検索しました。{sectionLenght, plural, one {# セクション} other {# セクション}}に{optionLenght, plural, one {# オプション} other { # オプション}}があります。",
|
||||
"management.indexPatternHeader": "インデックスパターン",
|
||||
"management.indexPatternLabel": "Elasticsearch からのデータの取得に役立つインデックスパターンを管理します。",
|
||||
"management.objects.savedObjectsDescription": "保存された検索、ビジュアライゼーション、ダッシュボードのインポート、エクスポート、管理を行います",
|
||||
"management.objects.savedObjectsTitle": "保存されたオブジェクト",
|
||||
"savedObjectsManagement.objects.savedObjectsDescription": "保存された検索、ビジュアライゼーション、ダッシュボードのインポート、エクスポート、管理を行います",
|
||||
"savedObjectsManagement.objects.savedObjectsTitle": "保存されたオブジェクト",
|
||||
"kibana_legacy.bigUrlWarningNotificationMessage": "{advancedSettingsLink}で{storeInSessionStorageParam}オプションを有効にするか、オンスクリーンビジュアルを簡素化してください。",
|
||||
"kibana_legacy.bigUrlWarningNotificationMessage.advancedSettingsLinkText": "高度な設定",
|
||||
"kibana_legacy.bigUrlWarningNotificationTitle": "URLが大きく、Kibanaの動作が停止する可能性があります",
|
||||
|
|
|
@ -1531,8 +1531,8 @@
|
|||
"advancedSettings.voiceAnnouncement.searchResultScreenReaderMessage": "您已搜索 {query}。{sectionLenght, plural, one {# 个部分} other {# 个部分}}中有 {optionLenght, plural, one {# 个选项} other {# 个选项}}",
|
||||
"management.indexPatternHeader": "索引模式",
|
||||
"management.indexPatternLabel": "管理帮助从 Elasticsearch 检索数据的索引模式。",
|
||||
"management.objects.savedObjectsDescription": "导入、导出和管理您的已保存搜索、可视化和仪表板。",
|
||||
"management.objects.savedObjectsTitle": "已保存对象",
|
||||
"savedObjectsManagement.objects.savedObjectsDescription": "导入、导出和管理您的已保存搜索、可视化和仪表板。",
|
||||
"savedObjectsManagement.objects.savedObjectsTitle": "已保存对象",
|
||||
"kibana_legacy.bigUrlWarningNotificationMessage": "在{advancedSettingsLink}中启用“{storeInSessionStorageParam}”选项或简化屏幕视觉效果。",
|
||||
"kibana_legacy.bigUrlWarningNotificationMessage.advancedSettingsLinkText": "高级设置",
|
||||
"kibana_legacy.bigUrlWarningNotificationTitle": "URL 过长,Kibana 可能无法工作",
|
||||
|
|
Loading…
Reference in a new issue