From 1b63553058e454d6cd3d0f291fd6520d941fadad Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Wed, 15 May 2024 15:59:53 +0200 Subject: [PATCH] Add confirmation window when documents have been deleted --- src/Common/dataAccess/deleteDocument.ts | 5 ++-- .../DocumentsTabV2/DocumentsTabV2.test.tsx | 1 + .../Tabs/DocumentsTabV2/DocumentsTabV2.tsx | 29 ++++++++++++------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Common/dataAccess/deleteDocument.ts b/src/Common/dataAccess/deleteDocument.ts index e51fad2ce..8e2dcc9f3 100644 --- a/src/Common/dataAccess/deleteDocument.ts +++ b/src/Common/dataAccess/deleteDocument.ts @@ -33,6 +33,7 @@ export const deleteDocument = async (collection: CollectionBase, documentId: Doc * @returns array of ids that were successfully deleted */ export const deleteDocuments = async (collection: CollectionBase, documentIds: DocumentId[]): Promise => { + const nbDocuments = documentIds.length; const clearMessage = logConsoleProgress(`Deleting ${documentIds.length} ${getEntityName(true)}`); try { const v2Container = await client().database(collection.databaseId).container(collection.id()); @@ -69,8 +70,8 @@ export const deleteDocuments = async (collection: CollectionBase, documentIds: D const allResult = await Promise.all(promiseArray); const flatAllResult = Array.prototype.concat.apply([], allResult); - logConsoleInfo(`Successfully deleted ${getEntityName(true)}: ${flatAllResult.length} out of ${documentIds.length}`); - // TODO: handle case result.length != documentIds.length + logConsoleInfo(`Successfully deleted ${getEntityName(true)}: ${flatAllResult.length} out of ${nbDocuments}`); + // TODO: handle case result.length != nbDocuments return flatAllResult; } catch (error) { handleError(error, "DeleteDocuments", `Error while deleting ${documentIds.length} ${getEntityName(true)}`); diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.test.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.test.tsx index 49890ab44..72ae8fc9b 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.test.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.test.tsx @@ -70,6 +70,7 @@ jest.mock("Explorer/Controls/Dialog", () => ({ useDialog: { getState: jest.fn(() => ({ showOkCancelModalDialog: (title: string, subText: string, okLabel: string, onOk: () => void) => onOk(), + showOkModalDialog: () => {}, })), }, })); diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx index 71cc86d5c..af63f359a 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx @@ -860,7 +860,7 @@ export const DocumentsTabComponent: React.FunctionComponent setIsExecuting(false)); @@ -873,16 +873,25 @@ export const DocumentsTabComponent: React.FunctionComponent { - const deletedRids = new Set(deletedIds.map((documentId) => documentId.rid)); - const newDocumentIds = [...documentIds.filter((documentId) => !deletedRids.has(documentId.rid))]; - setDocumentIds(newDocumentIds); + .then( + (deletedIds: DocumentId[]) => { + const deletedRids = new Set(deletedIds.map((documentId) => documentId.rid)); + const newDocumentIds = [...documentIds.filter((documentId) => !deletedRids.has(documentId.rid))]; + setDocumentIds(newDocumentIds); - setSelectedDocumentContent(undefined); - setClickedRow(undefined); - setSelectedRows(new Set()); - setEditorState(ViewModels.DocumentExplorerState.noDocumentSelected); - }) + setSelectedDocumentContent(undefined); + setClickedRow(undefined); + setSelectedRows(new Set()); + setEditorState(ViewModels.DocumentExplorerState.noDocumentSelected); + useDialog + .getState() + .showOkModalDialog("Delete documents", `${deletedIds.length} document(s) successfully deleted.`); + }, + (error: Error) => + useDialog + .getState() + .showOkModalDialog("Delete documents", `Document(s) deleted failed (${JSON.stringify(error)})`), + ) .finally(() => setIsExecuting(false)); }, [onExecutionErrorChange, _deleteDocuments, documentIds],