From 992852b9506bd3092bd052c681afca966478f88b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Mon, 28 Mar 2022 09:35:23 +0200 Subject: [PATCH] 18834: Fixed uploading file to a subdirectory, added tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- cypress/integration/collection.spec.js | 26 ++++++++++++------- .../collection-panel-files.tsx | 4 +-- .../collection-service/collection-service.ts | 8 +++--- .../collections/collection-upload-actions.ts | 12 ++++----- .../collection-panel-files.ts | 4 +-- .../files-upload-collection-dialog.ts | 5 ++-- 6 files changed, 34 insertions(+), 25 deletions(-) diff --git a/cypress/integration/collection.spec.js b/cypress/integration/collection.spec.js index b451fd66..6537e162 100644 --- a/cypress/integration/collection.spec.js +++ b/cypress/integration/collection.spec.js @@ -947,11 +947,11 @@ 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" + manifest_text: "./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n" }).as('testCollection1'); }); - it('uploads a file and checks the collection UI to be fresh', () => { + it.only('uploads a file and checks the collection UI to be fresh', () => { cy.getAll('@testCollection1') .then(function([testCollection1]) { cy.loginAs(activeUser); @@ -959,17 +959,25 @@ describe('Collection panel tests', function () { cy.get('[data-cy=upload-button]').click(); cy.get('[data-cy=collection-files-panel]') .contains('5mb_a.bin').should('not.exist'); - cy.get('[data-cy=collection-file-count]').should('contain', '1'); + cy.get('[data-cy=collection-file-count]').should('contain', '2'); cy.fixture('files/5mb.bin', 'base64').then(content => { cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin'); cy.get('[data-cy=form-submit-btn]').click(); - cy.get('[data-cy=form-submit-btn]').should('not.exist'); + // cy.get('[data-cy=form-submit-btn]').should('not.exist'); + cy.get('[data-cy=collection-files-panel]') + .contains('5mb_a.bin').should('exist'); + cy.get('[data-cy=collection-file-count]').should('contain', '3'); + + cy.get('[data-cy=collection-files-panel]').contains('subdir').click(); + cy.get('[data-cy=upload-button]').click(); + cy.fixture('files/5mb.bin', 'base64').then(content => { + cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin'); + cy.get('[data-cy=form-submit-btn]').click(); + // cy.get('[data-cy=form-submit-btn]').should('not.exist'); + cy.get('[data-cy=collection-files-panel]') + .contains('5mb_b.bin').should('exist'); + }); }); - // Confirm that the file browser has been updated. - cy.get('[data-cy=collection-files-panel]') - .contains('5mb_a.bin').should('exist'); - // Confirm that the collection panel has been updated. - cy.get('[data-cy=collection-file-count]').should('contain', '2'); }); }); diff --git a/src/components/collection-panel-files/collection-panel-files.tsx b/src/components/collection-panel-files/collection-panel-files.tsx index 1f7e8603..56833f64 100644 --- a/src/components/collection-panel-files/collection-panel-files.tsx +++ b/src/components/collection-panel-files/collection-panel-files.tsx @@ -28,7 +28,7 @@ export interface CollectionPanelFilesProps { isWritable: boolean; isLoading: boolean; tooManyFiles: boolean; - onUploadDataClick: () => void; + onUploadDataClick: (targetLocation?: string) => void; onSearchChange: (searchValue: string) => void; onItemMenuOpen: (event: React.MouseEvent, item: TreeItem, isWritable: boolean) => void; onOptionsMenuOpen: (event: React.MouseEvent, isWritable: boolean) => void; @@ -508,7 +508,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState className={classes.uploadButton} data-cy='upload-button' onClick={() => { - onUploadDataClick(); + onUploadDataClick(rightKey === leftKey ? undefined : rightKey); }} variant='contained' color='primary' diff --git a/src/services/collection-service/collection-service.ts b/src/services/collection-service/collection-service.ts index a3a7cf8f..9165e245 100644 --- a/src/services/collection-service/collection-service.ts +++ b/src/services/collection-service/collection-service.ts @@ -88,11 +88,11 @@ export class CollectionService extends TrashableResourceService { return; }) { - const fileURL = `c=${collectionUuid}/${file.name}`; + private async uploadFile(collectionUuid: string, file: File, fileId: number, onProgress: UploadProgress = () => { return; }, targetLocation: string = '') { + const fileURL = `c=${targetLocation !== '' ? targetLocation : collectionUuid}/${file.name}`; const requestConfig = { headers: { 'Content-Type': 'text/octet-stream' diff --git a/src/store/collections/collection-upload-actions.ts b/src/store/collections/collection-upload-actions.ts index 0ca681b9..135538b0 100644 --- a/src/store/collections/collection-upload-actions.ts +++ b/src/store/collections/collection-upload-actions.ts @@ -16,31 +16,31 @@ import { createTree } from 'models/tree'; import { loadCollectionPanel } from '../collection-panel/collection-panel-action'; import * as WorkbenchActions from 'store/workbench/workbench-actions'; -export const uploadCollectionFiles = (collectionUuid: string) => +export const uploadCollectionFiles = (collectionUuid: string, targetLocation?: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { dispatch(fileUploaderActions.START_UPLOAD()); const files = getState().fileUploader.map(file => file.file); - await services.collectionService.uploadFiles(collectionUuid, files, handleUploadProgress(dispatch)); + await services.collectionService.uploadFiles(collectionUuid, files, handleUploadProgress(dispatch), targetLocation); dispatch(WorkbenchActions.loadCollection(collectionUuid)); dispatch(fileUploaderActions.CLEAR_UPLOAD()); }; export const COLLECTION_UPLOAD_FILES_DIALOG = 'uploadCollectionFilesDialog'; -export const openUploadCollectionFilesDialog = () => (dispatch: Dispatch) => { +export const openUploadCollectionFilesDialog = (targetLocation?: string) => (dispatch: Dispatch) => { dispatch(reset(COLLECTION_UPLOAD_FILES_DIALOG)); dispatch(fileUploaderActions.CLEAR_UPLOAD()); - dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_UPLOAD_FILES_DIALOG, data: {} })); + dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_UPLOAD_FILES_DIALOG, data: { targetLocation } })); }; -export const submitCollectionFiles = () => +export const submitCollectionFiles = (targetLocation?: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const currentCollection = getState().collectionPanel.item; if (currentCollection) { try { dispatch(progressIndicatorActions.START_WORKING(COLLECTION_UPLOAD_FILES_DIALOG)); dispatch(startSubmit(COLLECTION_UPLOAD_FILES_DIALOG)); - await dispatch(uploadCollectionFiles(currentCollection.uuid)) + await dispatch(uploadCollectionFiles(currentCollection.uuid, targetLocation)) .then(() => dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES({ files: createTree() }))); dispatch(loadCollectionFiles(currentCollection.uuid)); dispatch(loadCollectionPanel(currentCollection.uuid)); diff --git a/src/views-components/collection-panel-files/collection-panel-files.ts b/src/views-components/collection-panel-files/collection-panel-files.ts index 6e57ab47..216ec669 100644 --- a/src/views-components/collection-panel-files/collection-panel-files.ts +++ b/src/views-components/collection-panel-files/collection-panel-files.ts @@ -45,8 +45,8 @@ const memoizedMapStateToProps = () => { }; const mapDispatchToProps = (dispatch: Dispatch): Pick => ({ - onUploadDataClick: () => { - dispatch(openUploadCollectionFilesDialog()); + onUploadDataClick: (targetLocation?: string) => { + dispatch(openUploadCollectionFilesDialog(targetLocation)); }, onCollapseToggle: (id) => { dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_COLLAPSE({ id })); diff --git a/src/views-components/dialog-forms/files-upload-collection-dialog.ts b/src/views-components/dialog-forms/files-upload-collection-dialog.ts index 22997775..81dbb0e7 100644 --- a/src/views-components/dialog-forms/files-upload-collection-dialog.ts +++ b/src/views-components/dialog-forms/files-upload-collection-dialog.ts @@ -13,8 +13,9 @@ export const FilesUploadCollectionDialog = compose( withDialog(COLLECTION_UPLOAD_FILES_DIALOG), reduxForm({ form: COLLECTION_UPLOAD_FILES_DIALOG, - onSubmit: (data, dispatch) => { - dispatch(submitCollectionFiles()); + onSubmit: (data, dispatch, dialog: any) => { + const targetLocation = (dialog.data || {}).targetLocation; + dispatch(submitCollectionFiles(targetLocation)); } }) )(DialogCollectionFilesUpload); -- 2.30.2