From 3d8c3da5fdc9488ac37d09211af8312e77ebebcb Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Tue, 28 Aug 2018 13:55:55 +0200 Subject: [PATCH] Extract collection partial copy dialog Feature #14119 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- .../collection-panel-files-actions.ts | 56 --------------- .../collection-partial-copy-actions.ts | 71 +++++++++++++++++++ .../collection-partial-copy-dialog.tsx | 26 ------- .../collection-files-action-set.ts | 2 +- .../collection-partial-copy-dialog.tsx | 28 ++++++++ .../collection-partial-copy-dialog.ts | 19 +++++ .../form-fields/collection-form-fields.tsx | 8 --- src/views/workbench/workbench.tsx | 2 +- 8 files changed, 120 insertions(+), 92 deletions(-) create mode 100644 src/store/collections/collection-partial-copy-actions.ts delete mode 100644 src/views-components/collection-partial-copy-dialog/collection-partial-copy-dialog.tsx create mode 100644 src/views-components/dialog-copy/collection-partial-copy-dialog.tsx create mode 100644 src/views-components/dialog-forms/collection-partial-copy-dialog.ts diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts index 01b4fe4f..d509218e 100644 --- a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts +++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts @@ -86,63 +86,7 @@ export const openMultipleFilesRemoveDialog = () => } }); -export const COLLECTION_PARTIAL_COPY = 'COLLECTION_PARTIAL_COPY'; -export interface CollectionPartialCopyFormData { - name: string; - description: string; - projectUuid: string; -} - -export const openCollectionPartialCopyDialog = () => - (dispatch: Dispatch, getState: () => RootState) => { - const currentCollection = getState().collectionPanel.item; - if (currentCollection) { - const initialData = { - name: currentCollection.name, - description: currentCollection.description, - projectUuid: '' - }; - dispatch(initialize(COLLECTION_PARTIAL_COPY, initialData)); - dispatch(resetPickerProjectTree()); - dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY, data: {} })); - } - }; - -export const doCollectionPartialCopy = ({ name, description, projectUuid }: CollectionPartialCopyFormData) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(startSubmit(COLLECTION_PARTIAL_COPY)); - const state = getState(); - const currentCollection = state.collectionPanel.item; - if (currentCollection) { - try { - const collection = await services.collectionService.get(currentCollection.uuid); - const collectionCopy = { - ...collection, - name, - description, - ownerUuid: projectUuid, - uuid: undefined - }; - const newCollection = await services.collectionService.create(collectionCopy); - const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, false).map(file => file.id); - await services.collectionService.deleteFiles(newCollection.uuid, paths); - dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY })); - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'New collection created.', hideDuration: 2000 })); - } catch (e) { - const error = getCommonResourceServiceError(e); - if (error === CommonResourceServiceError.UNIQUE_VIOLATION) { - dispatch(stopSubmit(COLLECTION_PARTIAL_COPY, { name: 'Collection with this name already exists.' })); - } else if (error === CommonResourceServiceError.UNKNOWN) { - dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY })); - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Could not create a copy of collection', hideDuration: 2000 })); - } else { - dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY })); - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been copied but may contain incorrect files.', hideDuration: 2000 })); - } - } - } - }; export const RENAME_FILE_DIALOG = 'renameFileDialog'; export interface RenameFileDialogData { diff --git a/src/store/collections/collection-partial-copy-actions.ts b/src/store/collections/collection-partial-copy-actions.ts new file mode 100644 index 00000000..cba23abb --- /dev/null +++ b/src/store/collections/collection-partial-copy-actions.ts @@ -0,0 +1,71 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { Dispatch } from 'redux'; +import { RootState } from '~/store/store'; +import { initialize, startSubmit, stopSubmit } from 'redux-form'; +import { resetPickerProjectTree } from '~/store/project-tree-picker/project-tree-picker-actions'; +import { dialogActions } from '~/store/dialog/dialog-actions'; +import { ServiceRepository } from '~/services/services'; +import { filterCollectionFilesBySelection } from '../collection-panel/collection-panel-files/collection-panel-files-state'; +import { snackbarActions } from '~/store/snackbar/snackbar-actions'; +import { getCommonResourceServiceError, CommonResourceServiceError } from '~/common/api/common-resource-service'; + +export const COLLECTION_PARTIAL_COPY_DIALOG = 'COLLECTION_PARTIAL_COPY_DIALOG'; + +export interface CollectionPartialCopyFormData { + name: string; + description: string; + projectUuid: string; +} + +export const openCollectionPartialCopyDialog = () => + (dispatch: Dispatch, getState: () => RootState) => { + const currentCollection = getState().collectionPanel.item; + if (currentCollection) { + const initialData = { + name: currentCollection.name, + description: currentCollection.description, + projectUuid: '' + }; + dispatch(initialize(COLLECTION_PARTIAL_COPY_DIALOG, initialData)); + dispatch(resetPickerProjectTree()); + dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY_DIALOG, data: {} })); + } + }; + +export const doCollectionPartialCopy = ({ name, description, projectUuid }: CollectionPartialCopyFormData) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(startSubmit(COLLECTION_PARTIAL_COPY_DIALOG)); + const state = getState(); + const currentCollection = state.collectionPanel.item; + if (currentCollection) { + try { + const collection = await services.collectionService.get(currentCollection.uuid); + const collectionCopy = { + ...collection, + name, + description, + ownerUuid: projectUuid, + uuid: undefined + }; + const newCollection = await services.collectionService.create(collectionCopy); + const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, false).map(file => file.id); + await services.collectionService.deleteFiles(newCollection.uuid, paths); + dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY_DIALOG })); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'New collection created.', hideDuration: 2000 })); + } catch (e) { + const error = getCommonResourceServiceError(e); + if (error === CommonResourceServiceError.UNIQUE_VIOLATION) { + dispatch(stopSubmit(COLLECTION_PARTIAL_COPY_DIALOG, { name: 'Collection with this name already exists.' })); + } else if (error === CommonResourceServiceError.UNKNOWN) { + dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY_DIALOG })); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Could not create a copy of collection', hideDuration: 2000 })); + } else { + dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY_DIALOG })); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been copied but may contain incorrect files.', hideDuration: 2000 })); + } + } + } + }; \ No newline at end of file diff --git a/src/views-components/collection-partial-copy-dialog/collection-partial-copy-dialog.tsx b/src/views-components/collection-partial-copy-dialog/collection-partial-copy-dialog.tsx deleted file mode 100644 index 86fc360e..00000000 --- a/src/views-components/collection-partial-copy-dialog/collection-partial-copy-dialog.tsx +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: AGPL-3.0 - -import * as React from "react"; -import { compose } from "redux"; -import { reduxForm, InjectedFormProps } from 'redux-form'; -import { withDialog, WithDialogProps } from '~/store/dialog/with-dialog'; -import { COLLECTION_PARTIAL_COPY, doCollectionPartialCopy, CollectionPartialCopyFormData } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions'; -import { CollectionPartialCopyFields } from '~/views-components/form-fields/collection-form-fields'; -import { FormDialog } from '~/components/form-dialog/form-dialog'; - -export const CollectionPartialCopyDialog = compose( - withDialog(COLLECTION_PARTIAL_COPY), - reduxForm({ - form: COLLECTION_PARTIAL_COPY, - onSubmit: (data: CollectionPartialCopyFormData, dispatch) => { - dispatch(doCollectionPartialCopy(data)); - } - }))((props: WithDialogProps & InjectedFormProps) => - ); diff --git a/src/views-components/context-menu/action-sets/collection-files-action-set.ts b/src/views-components/context-menu/action-sets/collection-files-action-set.ts index 965109ca..5c4dab30 100644 --- a/src/views-components/context-menu/action-sets/collection-files-action-set.ts +++ b/src/views-components/context-menu/action-sets/collection-files-action-set.ts @@ -4,7 +4,7 @@ import { ContextMenuActionSet } from "../context-menu-action-set"; import { collectionPanelFilesAction, openMultipleFilesRemoveDialog } from "~/store/collection-panel/collection-panel-files/collection-panel-files-actions"; -import { openCollectionPartialCopyDialog } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions'; +import { openCollectionPartialCopyDialog } from '~/store/collections/collection-partial-copy-actions'; export const collectionFilesActionSet: ContextMenuActionSet = [[{ name: "Select all", diff --git a/src/views-components/dialog-copy/collection-partial-copy-dialog.tsx b/src/views-components/dialog-copy/collection-partial-copy-dialog.tsx new file mode 100644 index 00000000..ce2a991b --- /dev/null +++ b/src/views-components/dialog-copy/collection-partial-copy-dialog.tsx @@ -0,0 +1,28 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from "react"; +import { FormDialog } from '~/components/form-dialog/form-dialog'; +import { CollectionNameField, CollectionDescriptionField, CollectionProjectPickerField } from '../form-fields/collection-form-fields'; +import { WithDialogProps } from '~/store/dialog/with-dialog'; +import { InjectedFormProps } from 'redux-form'; +import { CollectionPartialCopyFormData } from '../../store/collections/collection-partial-copy-actions'; + +type PartialCopyFormDialogProps = WithDialogProps & InjectedFormProps; + +export const CollectionPartialCopyDialog = (props: PartialCopyFormDialogProps) => + ; + +export const CollectionPartialCopyFields = () =>
+
+ + +
+ +
; diff --git a/src/views-components/dialog-forms/collection-partial-copy-dialog.ts b/src/views-components/dialog-forms/collection-partial-copy-dialog.ts new file mode 100644 index 00000000..33f6c257 --- /dev/null +++ b/src/views-components/dialog-forms/collection-partial-copy-dialog.ts @@ -0,0 +1,19 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { compose } from "redux"; +import { reduxForm } from 'redux-form'; +import { withDialog, } from '~/store/dialog/with-dialog'; +import { CollectionPartialCopyFormData, doCollectionPartialCopy, COLLECTION_PARTIAL_COPY_DIALOG } from '~/store/collections/collection-partial-copy-actions'; +import { CollectionPartialCopyDialog as Dialog } from "~/views-components/dialog-copy/collection-partial-copy-dialog"; + + +export const CollectionPartialCopyDialog = compose( + withDialog(COLLECTION_PARTIAL_COPY_DIALOG), + reduxForm({ + form: COLLECTION_PARTIAL_COPY_DIALOG, + onSubmit: (data: CollectionPartialCopyFormData, dispatch) => { + dispatch(doCollectionPartialCopy(data)); + } + }))(Dialog); \ No newline at end of file diff --git a/src/views-components/form-fields/collection-form-fields.tsx b/src/views-components/form-fields/collection-form-fields.tsx index 10c807b6..af240fc5 100644 --- a/src/views-components/form-fields/collection-form-fields.tsx +++ b/src/views-components/form-fields/collection-form-fields.tsx @@ -8,14 +8,6 @@ import { TextField } from "~/components/text-field/text-field"; import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION, COLLECTION_PROJECT_VALIDATION } from "~/validators/validators"; import { ProjectTreePicker } from "~/views-components/project-tree-picker/project-tree-picker"; -export const CollectionPartialCopyFields = () =>
-
- - -
- -
; - export const CollectionNameField = () =>