--- /dev/null
+// 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<any>(updateCollection(data));
+ dispatch(snackbarActions.OPEN_SNACKBAR({
+ message: "Collection has been successfully updated.",
+ hideDuration: 2000
+ }));
+ };
+
+export const updateCollection = (collection: Partial<CollectionResource>) =>
+ 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<any>(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
+++ /dev/null
-// 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<any>(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<CollectionResource>) =>
- (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<any>(updateDetails(collection));
- dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_FORM_NAME }));
- }
- );
- };
\ No newline at end of file
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 = () => <div style={{ display: 'flex' }}>
<div>
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';
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";
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';
// 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<CollectionUpdateFormDialogData>;
/>;
const CollectionEditFields = () => <span>
- <Field
- name='name'
- component={TextField}
- validate={COLLECTION_NAME_VALIDATION}
- label="Collection Name" />
- <Field
- name="description"
- component={TextField}
- validate={COLLECTION_DESCRIPTION_VALIDATION}
- label="Description - optional" />
+ <CollectionNameField />
+ <CollectionDescriptionField />
</span>;
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),