From: Janicki Artur Date: Thu, 23 Aug 2018 09:33:27 +0000 (+0200) Subject: store - change collection update action name, create collection form fields X-Git-Tag: 1.3.0~133^2~10 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/9bad01c91c6c67d5067419ab709129ff1d1e6b18 store - change collection update action name, create collection form fields Feature #14103 Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- diff --git a/src/store/collections/collection-update-actions.ts b/src/store/collections/collection-update-actions.ts new file mode 100644 index 00000000..13df864d --- /dev/null +++ b/src/store/collections/collection-update-actions.ts @@ -0,0 +1,58 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { Dispatch } from "redux"; +import { getCommonResourceServiceError, CommonResourceServiceError } from "~/common/api/common-resource-service"; +import { ServiceRepository } from "~/services/services"; +import { CollectionResource } from '~/models/collection'; +import { RootState } from "~/store/store"; +import { initialize, startSubmit, stopSubmit } from 'redux-form'; +import { collectionPanelActions } from "~/store/collection-panel/collection-panel-action"; +import { updateDetails } from "~/store/details-panel/details-panel-action"; +import { dialogActions } from "~/store/dialog/dialog-actions"; +import { dataExplorerActions } from "~/store/data-explorer/data-explorer-action"; +import { snackbarActions } from "~/store/snackbar/snackbar-actions"; +import { ContextMenuResource } from '~/store/context-menu/context-menu-reducer'; +import { PROJECT_PANEL_ID } from "~/views/project-panel/project-panel"; + +export interface CollectionUpdateFormDialogData { + uuid: string; + name: string; + description: string; +} + +export const COLLECTION_FORM_NAME = 'collectionEditDialog'; + +export const openUpdater = (resource: ContextMenuResource) => + (dispatch: Dispatch) => { + dispatch(initialize(COLLECTION_FORM_NAME, resource)); + dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_FORM_NAME, data: {} })); + }; + +export const editCollection = (data: CollectionUpdateFormDialogData) => + async (dispatch: Dispatch) => { + await dispatch(updateCollection(data)); + dispatch(snackbarActions.OPEN_SNACKBAR({ + message: "Collection has been successfully updated.", + hideDuration: 2000 + })); + }; + +export const updateCollection = (collection: Partial) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const uuid = collection.uuid || ''; + dispatch(startSubmit(COLLECTION_FORM_NAME)); + try { + const updatedCollection = await services.collectionService.update(uuid, collection); + dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: updatedCollection as CollectionResource })); + dispatch(updateDetails(updatedCollection)); + dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); + dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_FORM_NAME })); + } catch(e) { + const error = getCommonResourceServiceError(e); + if (error === CommonResourceServiceError.UNIQUE_VIOLATION) { + dispatch(stopSubmit(COLLECTION_FORM_NAME, { name: 'Collection with the same name already exists.' })); + } + } + }; \ No newline at end of file diff --git a/src/store/collections/collection-updater-actions.ts b/src/store/collections/collection-updater-actions.ts deleted file mode 100644 index 34eadd1b..00000000 --- a/src/store/collections/collection-updater-actions.ts +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: AGPL-3.0 - -import { Dispatch } from "redux"; -import { RootState } from "../store"; -import { ServiceRepository } from "~/services/services"; -import { CollectionResource } from '~/models/collection'; -import { initialize } from 'redux-form'; -import { collectionPanelActions } from "../collection-panel/collection-panel-action"; -import { updateDetails } from "~/store/details-panel/details-panel-action"; -import { dialogActions } from "~/store/dialog/dialog-actions"; -import { dataExplorerActions } from "~/store/data-explorer/data-explorer-action"; -import { PROJECT_PANEL_ID } from "~/views/project-panel/project-panel"; -import { snackbarActions } from "~/store/snackbar/snackbar-actions"; - -export interface CollectionUpdateFormDialogData { - name: string; - description: string; -} - -export const COLLECTION_FORM_NAME = 'collectionEditDialog'; - -export const openUpdater = (resource: { name: string, uuid: string }) => - (dispatch: Dispatch) => { - dispatch(initialize(COLLECTION_FORM_NAME, resource)); - dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_FORM_NAME, data: resource })); - }; - -export const editCollection = (data: { name: string, description: string }) => - (dispatch: Dispatch) => { - return dispatch(updateCollection(data)).then(() => { - dispatch(snackbarActions.OPEN_SNACKBAR({ - message: "Collection has been successfully updated.", - hideDuration: 2000 - })); - dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID })); - }); - }; - -export const updateCollection = (collection: Partial) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const uuid = collection.uuid || ''; - return services.collectionService - .update(uuid, collection) - .then(collection => { - dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection as CollectionResource })); - dispatch(updateDetails(collection)); - dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_FORM_NAME })); - } - ); - }; \ No newline at end of file diff --git a/src/views-components/form-dialog/collection-form-dialog.tsx b/src/views-components/collection-form-fields/collection-form-fields.tsx similarity index 93% rename from src/views-components/form-dialog/collection-form-dialog.tsx rename to src/views-components/collection-form-fields/collection-form-fields.tsx index d5f1d852..10c807b6 100644 --- a/src/views-components/form-dialog/collection-form-dialog.tsx +++ b/src/views-components/collection-form-fields/collection-form-fields.tsx @@ -6,7 +6,7 @@ import * as React from "react"; import { Field, WrappedFieldProps } from "redux-form"; import { TextField } from "~/components/text-field/text-field"; import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION, COLLECTION_PROJECT_VALIDATION } from "~/validators/validators"; -import { ProjectTreePicker } from "../project-tree-picker/project-tree-picker"; +import { ProjectTreePicker } from "~/views-components/project-tree-picker/project-tree-picker"; export const CollectionPartialCopyFields = () =>
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 index e230470b..00aa5ef9 100644 --- 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 @@ -6,7 +6,7 @@ import * as React from "react"; import { compose } from "redux"; import { reduxForm, InjectedFormProps } from 'redux-form'; import { withDialog, WithDialogProps } from '~/store/dialog/with-dialog'; -import { CollectionPartialCopyFields } from '../form-dialog/collection-form-dialog'; +import { CollectionPartialCopyFields } from '../collection-form-fields/collection-form-fields'; import { FormDialog } from '~/components/form-dialog/form-dialog'; import { COLLECTION_PARTIAL_COPY, doCollectionPartialCopy, CollectionPartialCopyFormData } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions'; diff --git a/src/views-components/context-menu/action-sets/collection-action-set.ts b/src/views-components/context-menu/action-sets/collection-action-set.ts index e5343824..1b949000 100644 --- a/src/views-components/context-menu/action-sets/collection-action-set.ts +++ b/src/views-components/context-menu/action-sets/collection-action-set.ts @@ -6,7 +6,7 @@ import { ContextMenuActionSet } from "../context-menu-action-set"; import { ToggleFavoriteAction } from "../actions/favorite-action"; import { toggleFavorite } from "~/store/favorites/favorites-actions"; import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, ProvenanceGraphIcon, AdvancedIcon, RemoveIcon } from "~/components/icon/icon"; -import { openUpdater } from "~/store/collections/collection-updater-actions"; +import { openUpdater } from "~/store/collections/collection-update-actions"; import { favoritePanelActions } from "~/store/favorite-panel/favorite-panel-action"; import { openMoveCollectionDialog } from '~/store/move-collection-dialog/move-collection-dialog'; import { openProjectCopyDialog } from "~/store/project-copy-project-dialog/project-copy-project-dialog"; diff --git a/src/views-components/context-menu/action-sets/collection-resource-action-set.ts b/src/views-components/context-menu/action-sets/collection-resource-action-set.ts index 1baa6416..989c8f1f 100644 --- a/src/views-components/context-menu/action-sets/collection-resource-action-set.ts +++ b/src/views-components/context-menu/action-sets/collection-resource-action-set.ts @@ -6,7 +6,7 @@ import { ContextMenuActionSet } from "../context-menu-action-set"; import { ToggleFavoriteAction } from "../actions/favorite-action"; import { toggleFavorite } from "~/store/favorites/favorites-actions"; import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, RemoveIcon } from "~/components/icon/icon"; -import { openUpdater } from "~/store/collections/collection-updater-actions"; +import { openUpdater } from "~/store/collections/collection-update-actions"; import { favoritePanelActions } from "~/store/favorite-panel/favorite-panel-action"; import { openMoveCollectionDialog } from '~/store/move-collection-dialog/move-collection-dialog'; import { openProjectCopyDialog } from '~/store/project-copy-project-dialog/project-copy-project-dialog'; diff --git a/src/views-components/dialog-update/dialog-collection-update.tsx b/src/views-components/dialog-update/dialog-collection-update.tsx index 31dd264d..7b1d4561 100644 --- a/src/views-components/dialog-update/dialog-collection-update.tsx +++ b/src/views-components/dialog-update/dialog-collection-update.tsx @@ -3,12 +3,11 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { InjectedFormProps, Field } from 'redux-form'; +import { InjectedFormProps } from 'redux-form'; import { WithDialogProps } from '~/store/dialog/with-dialog'; -import { CollectionUpdateFormDialogData } from '~/store/collections/collection-updater-actions'; -import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION } from '~/validators/validators'; -import { TextField } from '~/components/text-field/text-field'; +import { CollectionUpdateFormDialogData } from '~/store/collections/collection-update-actions'; import { FormDialog } from '~/components/form-dialog/form-dialog'; +import { CollectionNameField, CollectionDescriptionField } from '~/views-components/collection-form-fields/collection-form-fields'; type DialogCollectionProps = WithDialogProps<{}> & InjectedFormProps; @@ -21,14 +20,6 @@ export const DialogCollectionUpdate = (props: DialogCollectionProps) => />; const CollectionEditFields = () => - - + + ; diff --git a/src/views-components/update-collection-dialog/update-collection-dialog.ts b/src/views-components/update-collection-dialog/update-collection-dialog.ts index 3556472e..7db45fae 100644 --- a/src/views-components/update-collection-dialog/update-collection-dialog.ts +++ b/src/views-components/update-collection-dialog/update-collection-dialog.ts @@ -6,7 +6,7 @@ import { compose } from "redux"; import { reduxForm } from 'redux-form'; import { withDialog } from "~/store/dialog/with-dialog"; import { DialogCollectionUpdate } from '../dialog-update/dialog-collection-update'; -import { editCollection, COLLECTION_FORM_NAME, CollectionUpdateFormDialogData } from '~/store/collections/collection-updater-actions'; +import { editCollection, COLLECTION_FORM_NAME, CollectionUpdateFormDialogData } from '~/store/collections/collection-update-actions'; export const UpdateCollectionDialog = compose( withDialog(COLLECTION_FORM_NAME),