Skip to content

Commit 2bc4669

Browse files
opensearch-trigger-bot[bot]github-actions[bot]opensearch-changeset-bot[bot]
authored
[Workspace] Copy selected/all saved objects (#6478) (#7429)
* [Worksapce][UI] duplicate selected/all saved objects * fix test error * optimize code transfer memory * revert useless modify * optimize the code * add test id * Changeset file for PR #6478 created/updated * According the last mockup to optimize the code * Delete useless code * Optimize the code * optimize code * delete useless code * Optimize user experience * Solve the test snapshot error * modefy the ui text * support copy result flyout * optimize the code * optimize the code --------- (cherry picked from commit 9abde5c) Signed-off-by: yubonluo <yubonluo@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent d660ff0 commit 2bc4669

33 files changed

+3156
-54
lines changed

changelogs/fragments/6478.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
feat:
2+
- [Workspace] Duplicate selected/all saved objects ([#6478](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6478))

src/plugins/saved_objects_management/public/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ export {
4646
ISavedObjectsManagementServiceRegistry,
4747
SavedObjectsManagementServiceRegistryEntry,
4848
} from './services';
49-
export { ProcessedImportResponse, processImportResponse, FailedImport } from './lib';
49+
export {
50+
ProcessedImportResponse,
51+
processImportResponse,
52+
FailedImport,
53+
duplicateSavedObjects,
54+
getSavedObjectLabel,
55+
} from './lib';
5056
export { SavedObjectRelation, SavedObjectWithMetadata, SavedObjectMetadata } from './types';
5157
export { SAVED_OBJECT_DELETE_TRIGGER, savedObjectDeleteTrigger } from './triggers';
5258
export { SavedObjectDeleteContext } from './ui_actions_bootstrap';
53-
59+
export { SavedObjectsDuplicateModal } from './management_section';
5460
export function plugin(initializerContext: PluginInitializerContext) {
5561
return new SavedObjectsManagementPlugin();
5662
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { httpServiceMock } from '../../../../core/public/mocks';
7+
import { duplicateSavedObjects } from './duplicate_saved_objects';
8+
9+
describe('copy saved objects', () => {
10+
const httpClient = httpServiceMock.createStartContract();
11+
const objects = [
12+
{ type: 'dashboard', id: '1' },
13+
{ type: 'visualization', id: '2' },
14+
];
15+
const targetWorkspace = '1';
16+
17+
it('make http call with all parameter provided', async () => {
18+
const includeReferencesDeep = true;
19+
await duplicateSavedObjects(httpClient, objects, targetWorkspace, includeReferencesDeep);
20+
expect(httpClient.post).toMatchInlineSnapshot(`
21+
[MockFunction] {
22+
"calls": Array [
23+
Array [
24+
"/api/workspaces/_duplicate_saved_objects",
25+
Object {
26+
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}",
27+
},
28+
],
29+
],
30+
"results": Array [
31+
Object {
32+
"type": "return",
33+
"value": undefined,
34+
},
35+
],
36+
}
37+
`);
38+
});
39+
40+
it('make http call without includeReferencesDeep parameter provided', async () => {
41+
await duplicateSavedObjects(httpClient, objects, targetWorkspace);
42+
expect(httpClient.post).toMatchInlineSnapshot(`
43+
[MockFunction] {
44+
"calls": Array [
45+
Array [
46+
"/api/workspaces/_duplicate_saved_objects",
47+
Object {
48+
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}",
49+
},
50+
],
51+
Array [
52+
"/api/workspaces/_duplicate_saved_objects",
53+
Object {
54+
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}",
55+
},
56+
],
57+
],
58+
"results": Array [
59+
Object {
60+
"type": "return",
61+
"value": undefined,
62+
},
63+
Object {
64+
"type": "return",
65+
"value": undefined,
66+
},
67+
],
68+
}
69+
`);
70+
});
71+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { HttpStart } from 'src/core/public';
7+
8+
export async function duplicateSavedObjects(
9+
http: HttpStart,
10+
objects: any[],
11+
targetWorkspace: string,
12+
includeReferencesDeep: boolean = true
13+
) {
14+
return await http.post('/api/workspaces/_duplicate_saved_objects', {
15+
body: JSON.stringify({
16+
objects,
17+
includeReferencesDeep,
18+
targetWorkspace,
19+
}),
20+
});
21+
}

src/plugins/saved_objects_management/public/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ export { extractExportDetails, SavedObjectsExportResultDetails } from './extract
5757
export { createFieldList } from './create_field_list';
5858
export { getAllowedTypes } from './get_allowed_types';
5959
export { filterQuery } from './filter_query';
60+
export { duplicateSavedObjects } from './duplicate_saved_objects';

src/plugins/saved_objects_management/public/management_section/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@
2929
*/
3030

3131
export { mountManagementSection } from './mount_section';
32+
export { SavedObjectsDuplicateModal } from './objects_table';

0 commit comments

Comments
 (0)