-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spaces - Copy Saved Objects to Spaces UI (#39002)
- Loading branch information
Showing
45 changed files
with
3,117 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/legacy/ui/public/management/saved_objects_management/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
67 changes: 67 additions & 0 deletions
67
src/legacy/ui/public/management/saved_objects_management/saved_objects_management_action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...blic/management/saved_objects_management/saved_objects_management_action_registry.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...ui/public/management/saved_objects_management/saved_objects_management_action_registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
56 changes: 56 additions & 0 deletions
56
...gins/spaces/public/lib/copy_saved_objects_to_space/copy_saved_objects_to_space_action.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
} |
Oops, something went wrong.