From 34bb43dace3a30c3362e83b40e087020f5ce3aa9 Mon Sep 17 00:00:00 2001 From: yubonluo Date: Fri, 18 Oct 2024 16:09:36 +0800 Subject: [PATCH 1/3] fix copy issue Signed-off-by: yubonluo --- .../components/duplicate_result_flyout.tsx | 12 ++++--- .../saved_objects_table.test.tsx | 33 ++++++++++++++++++- .../objects_table/saved_objects_table.tsx | 25 ++++++++------ 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_result_flyout.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_result_flyout.tsx index 2bca3d33ffe8..0698a55b6d52 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_result_flyout.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_result_flyout.tsx @@ -220,11 +220,13 @@ export class DuplicateResultFlyout extends React.Component - +

+ +

{this.copyResult({ failedCopies, successfulCopies })} diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx index df7bec839a90..b3e440460428 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx @@ -1021,7 +1021,38 @@ describe('SavedObjectsTable', () => { }); }); - it('should catch error when duplicating selected object is fail', async () => { + it('should catch error when duplicating selected object is failed', async () => { + const component = shallowRender({ applications, workspaces }); + component.setState({ isShowingDuplicateModal: true }); + + const mockCopy = jest.fn().mockResolvedValue({ error: 'error' }); + workspaces.client$.next({ copy: mockCopy }); + const client = workspaces.client$.getValue(); + + // Ensure all promises resolve + await new Promise((resolve) => process.nextTick(resolve)); + // Ensure the state changes are reflected + component.update(); + + await component.instance().onDuplicate(mockSelectedSavedObjects, false, 'workspace2', 'bar'); + + expect(client?.copy).toHaveBeenCalledWith( + [ + { id: '1', type: 'dashboard' }, + { id: '2', type: 'dashboard' }, + ], + 'workspace2', + false + ); + component.update(); + + expect(notifications.toasts.addDanger).toHaveBeenCalledWith({ + title: 'Unable to copy 2 saved objects.', + text: 'error', + }); + }); + + it('should show error toast when copy is fail', async () => { const component = shallowRender({ applications, workspaces }); component.setState({ isShowingDuplicateModal: true }); diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx index 3ecfd103488b..8c77f9dd3eff 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx @@ -761,13 +761,14 @@ export class SavedObjectsTable extends Component { + const showErrorNotification = (text?: string) => { notifications.toasts.addDanger({ title: i18n.translate('savedObjectsManagement.objectsTable.duplicate.dangerNotification', { defaultMessage: 'Unable to copy {useUpdatedUX, select, true {{errorCount, plural, one {# asset} other {# assets}}} other {{errorCount, plural, one {# saved object} other {# saved objects}}}}.', values: { errorCount: savedObjects.length, useUpdatedUX }, }), + ...(text && { text }), }); }; if (!workspaceClient) { @@ -781,18 +782,22 @@ export class SavedObjectsTable extends Component 0 ? result.successResults : [], - targetWorkspaceName, - }); + if (result?.error) { + showErrorNotification(result.error); + } else { + this.setState({ + isShowingDuplicateResultFlyout: true, + failedCopies: result?.errors || [], + successfulCopies: result?.successCount > 0 ? result.successResults : [], + targetWorkspaceName, + }); + } } catch (e) { showErrorNotification(); + } finally { + this.hideDuplicateModal(); + await this.refreshObjects(); } - this.hideDuplicateModal(); - await this.refreshObjects(); }; renderDuplicateModal() { From c6bb3e59ccccdc9591b6ef36aa6b5a4e33e9e5ae Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 08:16:52 +0000 Subject: [PATCH 2/3] Changeset file for PR #8648 created/updated --- changelogs/fragments/8648.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/8648.yml diff --git a/changelogs/fragments/8648.yml b/changelogs/fragments/8648.yml new file mode 100644 index 000000000000..84cc02108e2d --- /dev/null +++ b/changelogs/fragments/8648.yml @@ -0,0 +1,2 @@ +fix: +- [Workspace] Workspace assets page crashed after library_write permission revoked ([#8648](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8648)) \ No newline at end of file From 93811834183ce5aac222a6700c155ae383c550af Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Fri, 18 Oct 2024 20:00:26 +0800 Subject: [PATCH 3/3] fix: snapshot Signed-off-by: SuZhou-Joe --- .../duplicate_result_flyout.test.tsx.snap | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/duplicate_result_flyout.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/duplicate_result_flyout.test.tsx.snap index 39270a4557ed..9501523a3755 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/duplicate_result_flyout.test.tsx.snap +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/duplicate_result_flyout.test.tsx.snap @@ -142,9 +142,13 @@ HTMLCollection [
- - Copy saved objects to targetWorkspace - +

+ + Copy saved objects to targetWorkspace + +

- - Copy saved objects to targetWorkspace - +

+ + Copy saved objects to targetWorkspace + +