17016: Code optimisation
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 7 Jan 2021 21:34:07 +0000 (22:34 +0100)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 7 Jan 2021 22:00:09 +0000 (23:00 +0100)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

cypress/integration/delete-multiple-files.spec.js
src/services/collection-service/collection-service.ts

index bd40a2b7600235922fbf01d688f6ab28d2358a67..2c7f48404abf02eb9962ca0d4874da2ba41e118d 100644 (file)
@@ -50,29 +50,12 @@ describe('Collection panel tests', function () {
         cy.createCollection(adminUser.token, {
             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
             owner_uuid: activeUser.user.uuid,
-            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:baz\n"
+            manifest_text: "./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:baz\n"
         })
             .as('testCollection').then(function () {
                 cy.loginAs(activeUser);
                 cy.visit(`/collections/${this.testCollection.uuid}`);
 
-                cy.get('[data-cy=collection-files-panel]')
-                    .contains('bar').rightclick({ force: true });
-
-                cy.get('[data-cy=context-menu]')
-                    .contains('Rename')
-                    .click();
-
-                cy.get('[data-cy=form-dialog]')
-                    .should('contain', 'Rename')
-                    .within(() => {
-                        cy.get('input').type(`{selectall}{backspace}subdir/foo`);
-                    });
-                cy.get('[data-cy=form-submit-btn]').click();
-                cy.get('[data-cy=collection-files-panel]')
-                    .should('not.contain', 'bar')
-                    .and('contain', 'subdir');
-
                 cy.get('[data-cy=virtual-file-tree] > div > i').first().click();
                 cy.get('[data-cy=collection-files-panel]')
                     .should('contain', 'foo');
@@ -83,6 +66,10 @@ describe('Collection panel tests', function () {
                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
                 cy.get('[data-cy=context-menu] div').contains('Remove selected').click();
                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
+
+                cy.get('[data-cy=collection-files-panel]')
+                    .should('not.contain', 'subdir')
+                    .and('contain', 'baz');
             });
     });
 })
index 7e6126a05b36abf655bc3e0f2cb95c48519e0e8f..5ae03b89eb0f816c7f595d322dadd1000d94b8cd 100644 (file)
@@ -37,7 +37,16 @@ export class CollectionService extends TrashableResourceService<CollectionResour
 
     async deleteFiles(collectionUuid: string, filePaths: string[]) {
         const sortedUniquePaths = Array.from(new Set(filePaths))
-            .sort((a, b) => b.length - a.length);
+            .sort((a, b) => a.length - b.length)
+            .reduce((acc, currentPath) => {
+                const parentPathFound = acc.find((parentPath) => currentPath.indexOf(`${parentPath}/`) > -1);
+
+                if (!parentPathFound) {
+                    return [...acc, currentPath];
+                }
+
+                return acc;
+            }, []);
 
         for (const path of sortedUniquePaths) {
             if (path.indexOf(collectionUuid) === -1) {