17016: Fixed deleteFiles function
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Tue, 1 Dec 2020 22:04:59 +0000 (23:04 +0100)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Tue, 1 Dec 2020 22:04:59 +0000 (23:04 +0100)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

src/services/collection-service/collection-service.ts
src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts

index 0aa0aa84de4f476866c60cccb68b5dc2acc9bcb9..7e6126a05b36abf655bc3e0f2cb95c48519e0e8f 100644 (file)
@@ -36,12 +36,14 @@ export class CollectionService extends TrashableResourceService<CollectionResour
     }
 
     async deleteFiles(collectionUuid: string, filePaths: string[]) {
-        for (const path of filePaths) {
-            const splittedPath = path.split('/');
-            if (collectionUuid) {
-                await this.webdavClient.delete(`c=${collectionUuid}/${splittedPath[1]}`);
-            } else {
+        const sortedUniquePaths = Array.from(new Set(filePaths))
+            .sort((a, b) => b.length - a.length);
+
+        for (const path of sortedUniquePaths) {
+            if (path.indexOf(collectionUuid) === -1) {
                 await this.webdavClient.delete(`c=${collectionUuid}${path}`);
+            } else {
+                await this.webdavClient.delete(`c=${path}`);
             }
         }
     }
index 3f9948fca034e3915e9bcebddd56d64bd4109e1a..373ee04eec06e3735d5c469668352394c274de85 100644 (file)
@@ -47,7 +47,8 @@ export const loadCollectionFiles = (uuid: string) =>
             dispatch(snackbarActions.OPEN_SNACKBAR({
                 message: `Error getting file list: ${e.errors[0]}`,
                 hideDuration: 2000,
-                kind: SnackbarKind.ERROR }));
+                kind: SnackbarKind.ERROR
+            }));
         });
     };
 
@@ -149,7 +150,7 @@ export const renameFile = (newFullPath: string) =>
                     dispatch<any>(loadCollectionPanel(currentCollection.uuid, true));
                     dispatch(dialogActions.CLOSE_DIALOG({ id: RENAME_FILE_DIALOG }));
                     dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'File name changed.', hideDuration: 2000 }));
-                }).catch (e => {
+                }).catch(e => {
                     const errors: FormErrors<RenameFileDialogData, string> = {
                         path: `Could not rename the file: ${e.responseText}`
                     };