-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Spaces - Copy Saved Objects to Spaces UI #39002
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
Changes from all commits
e0aca37
933817e
8401fee
46a68df
d33e73d
c07f905
e27e111
29f2bdc
4b18c51
61491ff
a1b662e
8e00c79
8c4425b
bea29e3
92edadc
6fb21b3
c673e2f
4996c5d
4a7569a
e233d71
e40d2c7
31cc78d
91b8b02
486dafd
e3eff07
aa39d43
efb6f7f
75d5944
c942b87
34cf67b
472a3f6
5dc168f
d4183ac
7845745
b94a02a
1a4a1c4
ec953af
139d606
aa14457
0d62721
9beea0c
56f949d
fcf1870
189f872
e615838
917fc63
2fe0e21
09ba89e
5f1cde4
65e3594
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| export { SavedObjectsManagementActionRegistry } from './saved_objects_management_action_registry'; | ||
| export { | ||
| SavedObjectsManagementAction, | ||
| SavedObjectsManagementRecord, | ||
| SavedObjectsManagementRecordReference, | ||
| } from './saved_objects_management_action'; | ||
| export { | ||
| processImportResponse, | ||
| ProcessedImportResponse, | ||
| } from '../../../../core_plugins/kibana/public/management/sections/objects/lib/process_import_response'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't be reaching into the kibana plugin from here, should we move
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I thought this was acceptable because we do the same thing from
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting... well, let the "bad practices" roll :) Feel free to ignore this. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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 { ReactNode } from '@elastic/eui/node_modules/@types/react'; | ||
|
|
||
| export interface SavedObjectsManagementRecordReference { | ||
| type: string; | ||
| id: string; | ||
| name: string; | ||
| } | ||
| export interface SavedObjectsManagementRecord { | ||
| type: string; | ||
| id: string; | ||
| meta: { | ||
| icon: string; | ||
| title: string; | ||
| }; | ||
| references: SavedObjectsManagementRecordReference[]; | ||
| } | ||
|
|
||
| export abstract class SavedObjectsManagementAction { | ||
| public abstract render: () => ReactNode; | ||
| public abstract id: string; | ||
| public abstract euiAction: { | ||
| name: string; | ||
| description: string; | ||
| icon: string; | ||
| type: string; | ||
| available?: (item: SavedObjectsManagementRecord) => boolean; | ||
| enabled?: (item: SavedObjectsManagementRecord) => boolean; | ||
| onClick?: (item: SavedObjectsManagementRecord) => void; | ||
| render?: (item: SavedObjectsManagementRecord) => any; | ||
| }; | ||
|
|
||
| private callbacks: Function[] = []; | ||
|
|
||
| protected record: SavedObjectsManagementRecord | null = null; | ||
|
|
||
| public registerOnFinishCallback(callback: Function) { | ||
| this.callbacks.push(callback); | ||
| } | ||
|
|
||
| protected start(record: SavedObjectsManagementRecord) { | ||
| this.record = record; | ||
| } | ||
|
|
||
| protected finish() { | ||
| this.record = null; | ||
| this.callbacks.forEach(callback => callback()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * 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 './saved_objects_management_action'; | ||
|
|
||
| const actions: Map<string, SavedObjectsManagementAction> = new Map(); | ||
|
|
||
| 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); | ||
| }, | ||
|
|
||
| has: (actionId: string) => actions.has(actionId), | ||
|
|
||
| get: () => Array.from(actions.values()), | ||
| }; |
| 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 type GetSpacePurpose = 'any' | 'copySavedObjectsIntoSpace'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * 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 { | ||
| SavedObjectsManagementAction, | ||
| SavedObjectsManagementRecord, | ||
| } from 'ui/management/saved_objects_management'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { toastNotifications } from 'ui/notify'; | ||
| import { CopySavedObjectsToSpaceFlyout } from '../../views/management/components/copy_saved_objects_to_space'; | ||
| import { Space } from '../../../common/model/space'; | ||
| import { SpacesManager } from '../spaces_manager'; | ||
|
|
||
| export class CopyToSpaceSavedObjectsManagementAction extends SavedObjectsManagementAction { | ||
| public id: string = 'copy_saved_objects_to_space'; | ||
|
|
||
| public euiAction = { | ||
| name: i18n.translate('xpack.spaces.management.copyToSpace.actionTitle', { | ||
| defaultMessage: 'Copy to space', | ||
| }), | ||
| description: i18n.translate('xpack.spaces.management.copyToSpace.actionDescription', { | ||
| defaultMessage: 'Copy this saved object to one or more spaces', | ||
| }), | ||
| icon: 'spacesApp', | ||
| type: 'icon', | ||
| onClick: (object: SavedObjectsManagementRecord) => { | ||
| this.start(object); | ||
| }, | ||
| }; | ||
|
|
||
| constructor(private readonly spacesManager: SpacesManager, private readonly activeSpace: Space) { | ||
| super(); | ||
| } | ||
|
|
||
| public render = () => { | ||
| if (!this.record) { | ||
| throw new Error('No record available! `render()` was likely called before `start()`.'); | ||
| } | ||
| return ( | ||
| <CopySavedObjectsToSpaceFlyout | ||
| onClose={this.onClose} | ||
| savedObject={this.record} | ||
| spacesManager={this.spacesManager} | ||
| activeSpace={this.activeSpace} | ||
| toastNotifications={toastNotifications} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| private onClose = () => { | ||
| this.finish(); | ||
| }; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No functional changes in this file -- simply a conversion to TypeScript