From: Stephen Smith Date: Mon, 10 Apr 2023 19:29:32 +0000 (-0400) Subject: 20031: Use replace files api for copy to new collection X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/b6c145e81728b3916370000a83648280bbfb94d2 20031: Use replace files api for copy to new collection Arvados-DCO-1.1-Signed-off-by: Stephen Smith --- diff --git a/src/store/collections/collection-partial-copy-actions.ts b/src/store/collections/collection-partial-copy-actions.ts index 73d117c26c..cccd7023e4 100644 --- a/src/store/collections/collection-partial-copy-actions.ts +++ b/src/store/collections/collection-partial-copy-actions.ts @@ -46,30 +46,31 @@ export const openCollectionPartialCopyToNewCollectionDialog = () => export const copyCollectionPartialToNewCollection = ({ name, description, projectUuid }: CollectionPartialCopyToNewCollectionFormData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(startSubmit(COLLECTION_PARTIAL_COPY_FORM_NAME)); const state = getState(); - const currentCollection = state.collectionPanel.item; - if (currentCollection) { + // Get current collection + const sourceCollection = state.collectionPanel.item; + + if (sourceCollection) { try { + dispatch(startSubmit(COLLECTION_PARTIAL_COPY_FORM_NAME)); dispatch(progressIndicatorActions.START_WORKING(COLLECTION_PARTIAL_COPY_FORM_NAME)); - const collectionManifestText = await services.collectionService.get(currentCollection.uuid, undefined, ['manifestText']); - const collectionCopy = { + + // Create new collection + const newCollection = await services.collectionService.create({ name, description, ownerUuid: projectUuid, uuid: undefined, - manifestText: collectionManifestText.manifestText, - }; - const newCollection = await services.collectionService.create(collectionCopy); - const copiedFiles = await services.collectionService.files(newCollection.uuid); - const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, true).map(file => file.id); - const filesToDelete = copiedFiles.map(({ id }) => id).filter(file => { - return !paths.find(path => path.indexOf(file.replace(newCollection.uuid, '')) > -1); }); - await services.collectionService.deleteFiles( - newCollection.uuid, - filesToDelete - ); + + // Get selected files + const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, true) + .map(file => file.id.replace(new RegExp(`(^${sourceCollection.uuid})`), '')); + + // Copy files + const updatedCollection = await services.collectionService.copyFiles(sourceCollection.portableDataHash, paths, newCollection.uuid, '/', false); + dispatch(updateResources([updatedCollection])); + dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY_FORM_NAME })); dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'New collection created.',