Skip to content

Commit

Permalink
[Workspace] Copy selected/all saved objects (#6478)
Browse files Browse the repository at this point in the history
* [Worksapce][UI] duplicate selected/all saved objects

Signed-off-by: yubonluo <yubonluo@amazon.com>

* fix test error

Signed-off-by: yubonluo <yubonluo@amazon.com>

* optimize code transfer memory

Signed-off-by: yubonluo <yubonluo@amazon.com>

* revert useless modify

Signed-off-by: yubonluo <yubonluo@amazon.com>

* optimize the code

Signed-off-by: yubonluo <yubonluo@amazon.com>

* add test id

Signed-off-by: yubonluo <yubonluo@amazon.com>

* Changeset file for PR #6478 created/updated

* According the last mockup to optimize the code

Signed-off-by: yubonluo <yubonluo@amazon.com>

* Delete useless code

Signed-off-by: yubonluo <yubonluo@amazon.com>

* Optimize the code

Signed-off-by: yubonluo <yubonluo@amazon.com>

* optimize code

Signed-off-by: yubonluo <yubonluo@amazon.com>

* delete useless code

Signed-off-by: yubonluo <yubonluo@amazon.com>

* Optimize user experience

Signed-off-by: yubonluo <yubonluo@amazon.com>

* Solve the test snapshot error

Signed-off-by: yubonluo <yubonluo@amazon.com>

* modefy the ui text

Signed-off-by: yubonluo <yubonluo@amazon.com>

* support copy result flyout

Signed-off-by: yubonluo <yubonluo@amazon.com>

* optimize the code

Signed-off-by: yubonluo <yubonluo@amazon.com>

* optimize the code

Signed-off-by: yubonluo <yubonluo@amazon.com>

---------

Signed-off-by: yubonluo <yubonluo@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 9abde5c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 77f6c70 commit 7daf7bb
Show file tree
Hide file tree
Showing 33 changed files with 3,156 additions and 54 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6478.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace] Duplicate selected/all saved objects ([#6478](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6478))
10 changes: 8 additions & 2 deletions src/plugins/saved_objects_management/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ export {
ISavedObjectsManagementServiceRegistry,
SavedObjectsManagementServiceRegistryEntry,
} from './services';
export { ProcessedImportResponse, processImportResponse, FailedImport } from './lib';
export {
ProcessedImportResponse,
processImportResponse,
FailedImport,
duplicateSavedObjects,
getSavedObjectLabel,
} from './lib';
export { SavedObjectRelation, SavedObjectWithMetadata, SavedObjectMetadata } from './types';
export { SAVED_OBJECT_DELETE_TRIGGER, savedObjectDeleteTrigger } from './triggers';
export { SavedObjectDeleteContext } from './ui_actions_bootstrap';

export { SavedObjectsDuplicateModal } from './management_section';
export function plugin(initializerContext: PluginInitializerContext) {
return new SavedObjectsManagementPlugin();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { httpServiceMock } from '../../../../core/public/mocks';
import { duplicateSavedObjects } from './duplicate_saved_objects';

describe('copy saved objects', () => {
const httpClient = httpServiceMock.createStartContract();
const objects = [
{ type: 'dashboard', id: '1' },
{ type: 'visualization', id: '2' },
];
const targetWorkspace = '1';

it('make http call with all parameter provided', async () => {
const includeReferencesDeep = true;
await duplicateSavedObjects(httpClient, objects, targetWorkspace, includeReferencesDeep);
expect(httpClient.post).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"/api/workspaces/_duplicate_saved_objects",
Object {
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}",
},
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`);
});

it('make http call without includeReferencesDeep parameter provided', async () => {
await duplicateSavedObjects(httpClient, objects, targetWorkspace);
expect(httpClient.post).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
"/api/workspaces/_duplicate_saved_objects",
Object {
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}",
},
],
Array [
"/api/workspaces/_duplicate_saved_objects",
Object {
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}",
},
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
Object {
"type": "return",
"value": undefined,
},
],
}
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { HttpStart } from 'src/core/public';

export async function duplicateSavedObjects(
http: HttpStart,
objects: any[],
targetWorkspace: string,
includeReferencesDeep: boolean = true
) {
return await http.post('/api/workspaces/_duplicate_saved_objects', {
body: JSON.stringify({
objects,
includeReferencesDeep,
targetWorkspace,
}),
});
}
1 change: 1 addition & 0 deletions src/plugins/saved_objects_management/public/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ export { extractExportDetails, SavedObjectsExportResultDetails } from './extract
export { createFieldList } from './create_field_list';
export { getAllowedTypes } from './get_allowed_types';
export { filterQuery } from './filter_query';
export { duplicateSavedObjects } from './duplicate_saved_objects';
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
*/

export { mountManagementSection } from './mount_section';
export { SavedObjectsDuplicateModal } from './objects_table';
Loading

0 comments on commit 7daf7bb

Please sign in to comment.