From d5db24f8cfa26d546596b99e644e37c72b6b1fae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Thu, 7 Jan 2021 22:34:07 +0100 Subject: [PATCH] 17016: Code optimisation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- .../integration/delete-multiple-files.spec.js | 23 ++++--------------- .../collection-service/collection-service.ts | 11 ++++++++- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cypress/integration/delete-multiple-files.spec.js b/cypress/integration/delete-multiple-files.spec.js index bd40a2b7..2c7f4840 100644 --- a/cypress/integration/delete-multiple-files.spec.js +++ b/cypress/integration/delete-multiple-files.spec.js @@ -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'); }); }); }) diff --git a/src/services/collection-service/collection-service.ts b/src/services/collection-service/collection-service.ts index 7e6126a0..5ae03b89 100644 --- a/src/services/collection-service/collection-service.ts +++ b/src/services/collection-service/collection-service.ts @@ -37,7 +37,16 @@ export class CollectionService extends TrashableResourceService 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) { -- 2.30.2