From 75ff7238d0dfc8f1668f5838b0468f46aea636b0 Mon Sep 17 00:00:00 2001 From: Wilson Wong Date: Tue, 17 Oct 2023 14:19:09 -0700 Subject: [PATCH 1/7] fix:(SC-3376) Handle delete success/fail toasts on a per object basis objectStore.ts now uses Promise.allSettled instead of Promise.all and returns an array of objects for each promise with their status. DeleteObjectButton.vue waits for the array and displays a toast based on each success or fail. --- frontend/src/components/object/DeleteObjectButton.vue | 11 +++++++++-- frontend/src/store/objectStore.ts | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/object/DeleteObjectButton.vue b/frontend/src/components/object/DeleteObjectButton.vue index 6bbf268a..7809260f 100644 --- a/frontend/src/components/object/DeleteObjectButton.vue +++ b/frontend/src/components/object/DeleteObjectButton.vue @@ -42,8 +42,15 @@ const confirmDelete = () => { rejectLabel: 'Cancel', accept: async () => { try { - await objectStore.deleteObjects(props.ids, props.versionId); - emit('on-deleted-success', props.versionId); + const res = await objectStore.deleteObjects(props.ids, props.versionId); + res?.forEach((ele, index)=>{ + if (ele.status === 'fulfilled') { + emit('on-deleted-success', props.ids[index]); + } else { + toast.error(`Error deleting ${props.ids[index]}`); + emit('on-deleted-error'); + } + }); } catch (error: any) { toast.error(`Error deleting one or more ${item}s`); emit('on-deleted-error'); diff --git a/frontend/src/store/objectStore.ts b/frontend/src/store/objectStore.ts index 9b5d8ff1..e1642072 100644 --- a/frontend/src/store/objectStore.ts +++ b/frontend/src/store/objectStore.ts @@ -81,7 +81,9 @@ export const useObjectStore = defineStore('object', () => { try { appStore.beginIndeterminateLoading(); - await Promise.all( + // Promise.allSettled returns array with an object per promise + // check MDN for details + return await Promise.allSettled( objectIds.map(async (id) => { await objectService.deleteObject(id, versionId); }) From 9eb75fe5ddd3c79d87c367e4da2a61dce863d712 Mon Sep 17 00:00:00 2001 From: Wilson Wong Date: Thu, 19 Oct 2023 11:19:26 -0700 Subject: [PATCH 2/7] Resolving merge conflict --- .../components/object/DeleteObjectButton.vue | 25 +++++-------------- frontend/src/store/objectStore.ts | 4 +-- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/frontend/src/components/object/DeleteObjectButton.vue b/frontend/src/components/object/DeleteObjectButton.vue index 7809260f..f7b6acd0 100644 --- a/frontend/src/components/object/DeleteObjectButton.vue +++ b/frontend/src/components/object/DeleteObjectButton.vue @@ -37,19 +37,14 @@ const confirmDelete = () => { const msgContext = props.ids.length > 1 ? `the selected ${props.ids.length} ${item}s` : `this ${item}`; confirm.require({ message: `Please confirm that you want to delete ${msgContext}.`, - header: `Delete ${props.ids.length > 1 ? item + 's' : item }`, + header: `Delete ${props.ids.length > 1 ? item + 's' : item}`, acceptLabel: 'Confirm', rejectLabel: 'Cancel', accept: async () => { try { - const res = await objectStore.deleteObjects(props.ids, props.versionId); - res?.forEach((ele, index)=>{ - if (ele.status === 'fulfilled') { - emit('on-deleted-success', props.ids[index]); - } else { - toast.error(`Error deleting ${props.ids[index]}`); - emit('on-deleted-error'); - } + props.ids?.forEach(async (ele) => { + const res = await objectStore.deleteObjects([ele], props.versionId); + if (res) emit('on-deleted-success', props.versionId); }); } catch (error: any) { toast.error(`Error deleting one or more ${item}s`); @@ -64,18 +59,10 @@ const confirmDelete = () => {