From a3e0dc8338ab730f62d442b9dfcf18cc2e649253 Mon Sep 17 00:00:00 2001 From: Janicki Artur Date: Thu, 2 Aug 2018 13:03:34 +0200 Subject: [PATCH] init and save form, modify store Feature #13903 Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- src/common/api/common-resource-service.ts | 7 +++-- .../collection-panel-action.ts | 2 +- .../updator/collection-updator-action.ts | 30 ++++++++++++++----- .../updator/collection-updator-reducer.ts | 9 +++--- .../action-sets/collection-action-set.ts | 4 +-- .../dialog-collection-update.tsx | 3 +- .../collection-panel/collection-panel.tsx | 7 ++--- 7 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/common/api/common-resource-service.ts b/src/common/api/common-resource-service.ts index 3956fb73..8ad8fe91 100644 --- a/src/common/api/common-resource-service.ts +++ b/src/common/api/common-resource-service.ts @@ -100,8 +100,11 @@ export class CommonResourceService { })); } - update(uuid: string) { - throw new Error("Not implemented"); + update(uuid: string, data: any) { + return CommonResourceService.defaultResponse( + this.serverApi + .put(this.resourceType + uuid, data)); + } } diff --git a/src/store/collection-panel/collection-panel-action.ts b/src/store/collection-panel/collection-panel-action.ts index 946836a5..c0d3366e 100644 --- a/src/store/collection-panel/collection-panel-action.ts +++ b/src/store/collection-panel/collection-panel-action.ts @@ -21,7 +21,7 @@ export const loadCollection = (uuid: string, kind: ResourceKind) => return collectionService .get(uuid) .then(item => { - dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: item as CollectionResource })); + dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item })); }); }; diff --git a/src/store/collections/updator/collection-updator-action.ts b/src/store/collections/updator/collection-updator-action.ts index 5272baa8..ac422f07 100644 --- a/src/store/collections/updator/collection-updator-action.ts +++ b/src/store/collections/updator/collection-updator-action.ts @@ -8,26 +8,40 @@ import { Dispatch } from "redux"; import { RootState } from "../../store"; import { collectionService } from '../../../services/services'; import { CollectionResource } from '../../../models/collection'; +import { initialize } from 'redux-form'; +import { collectionPanelActions } from "../../collection-panel/collection-panel-action"; export const collectionUpdatorActions = unionize({ - OPEN_COLLECTION_UPDATOR: ofType<{ ownerUuid: string }>(), + OPEN_COLLECTION_UPDATOR: ofType<{ uuid: string }>(), CLOSE_COLLECTION_UPDATOR: ofType<{}>(), - UPDATE_COLLECTION: ofType<{}>(), UPDATE_COLLECTION_SUCCESS: ofType<{}>(), }, { tag: 'type', value: 'payload' }); + +export const COLLECTION_FORM_NAME = 'collectionEditDialog'; + +export const openUpdator = (uuid: string) => + (dispatch: Dispatch, getState: () => RootState) => { + dispatch(collectionUpdatorActions.OPEN_COLLECTION_UPDATOR({ uuid })); + const item = getState().collectionPanel.item; + if(item) { + dispatch(initialize(COLLECTION_FORM_NAME, { name: item.name, description: item.description })); + } + }; + export const updateCollection = (collection: Partial) => (dispatch: Dispatch, getState: () => RootState) => { - const { ownerUuid } = getState().collections.creator; - const collectiontData = { ownerUuid, ...collection }; - dispatch(collectionUpdatorActions.UPDATE_COLLECTION(collectiontData)); + const { uuid } = getState().collections.updator; return collectionService - // change for update - .create(collectiontData) - .then(collection => dispatch(collectionUpdatorActions.UPDATE_COLLECTION_SUCCESS(collection))); + .update(uuid, collection) + .then(collection => { + dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection })); + dispatch(collectionUpdatorActions.UPDATE_COLLECTION_SUCCESS()); + } + ); }; export type CollectionUpdatorAction = UnionOf; \ No newline at end of file diff --git a/src/store/collections/updator/collection-updator-reducer.ts b/src/store/collections/updator/collection-updator-reducer.ts index f47f1960..b9d0250c 100644 --- a/src/store/collections/updator/collection-updator-reducer.ts +++ b/src/store/collections/updator/collection-updator-reducer.ts @@ -8,7 +8,7 @@ export type CollectionUpdatorState = CollectionUpdator; interface CollectionUpdator { opened: boolean; - ownerUuid: string; + uuid: string; } const updateCollection = (state: CollectionUpdatorState, updator?: Partial) => ({ @@ -18,15 +18,14 @@ const updateCollection = (state: CollectionUpdatorState, updator?: Partial { return collectionUpdatorActions.match(action, { - OPEN_COLLECTION_UPDATOR: ({ ownerUuid }) => updateCollection(state, { ownerUuid, opened: true }), + OPEN_COLLECTION_UPDATOR: ({ uuid }) => updateCollection(state, { uuid, opened: true }), CLOSE_COLLECTION_UPDATOR: () => updateCollection(state, { opened: false }), - UPDATE_COLLECTION: () => updateCollection(state), - UPDATE_COLLECTION_SUCCESS: () => updateCollection(state, { opened: false, ownerUuid: "" }), + UPDATE_COLLECTION_SUCCESS: () => updateCollection(state, { opened: false, uuid: "" }), default: () => state }); }; 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 7f9cbc13..9e3ff348 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 @@ -8,14 +8,14 @@ import { toggleFavorite } from "../../../store/favorites/favorites-actions"; import { dataExplorerActions } from "../../../store/data-explorer/data-explorer-action"; import { FAVORITE_PANEL_ID } from "../../../views/favorite-panel/favorite-panel"; import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, ProvenanceGraphIcon, AdvancedIcon, RemoveIcon } from "../../../components/icon/icon"; -import { collectionUpdatorActions } from "../../../store/collections/updator/collection-updator-action"; +import { openUpdator } from "../../../store/collections/updator/collection-updator-action"; export const collectionActionSet: ContextMenuActionSet = [[ { icon: RenameIcon, name: "Edit collection", execute: (dispatch, resource) => { - dispatch(collectionUpdatorActions.OPEN_COLLECTION_UPDATOR({ ownerUuid: resource.uuid })); + dispatch(openUpdator(resource.uuid)); } }, { diff --git a/src/views-components/dialog-update/dialog-collection-update.tsx b/src/views-components/dialog-update/dialog-collection-update.tsx index 30a3256d..80a82b27 100644 --- a/src/views-components/dialog-update/dialog-collection-update.tsx +++ b/src/views-components/dialog-update/dialog-collection-update.tsx @@ -8,6 +8,7 @@ import { compose } from 'redux'; import { ArvadosTheme } from '../../common/custom-theme'; import { Dialog, DialogActions, DialogContent, DialogTitle, TextField, StyleRulesCallback, withStyles, WithStyles, Button, CircularProgress } from '../../../node_modules/@material-ui/core'; import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION } from '../../validators/create-project/create-project-validator'; +import { COLLECTION_FORM_NAME } from '../../store/collections/updator/collection-updator-action'; type CssRules = 'content' | 'actions' | 'textField' | 'buttonWrapper' | 'saveButton' | 'circularProgress'; @@ -64,7 +65,7 @@ interface TextFieldProps { } export const DialogCollectionUpdate = compose( - reduxForm({ form: 'collectionEditDialog' }), + reduxForm({ form: COLLECTION_FORM_NAME }), withStyles(styles))( class DialogCollectionUpdate extends React.Component { diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx index 71ec309f..340d7c9c 100644 --- a/src/views/collection-panel/collection-panel.tsx +++ b/src/views/collection-panel/collection-panel.tsx @@ -59,13 +59,12 @@ export const CollectionPanel = withStyles(styles)( } - title={item && item.name } /> + title={item && item.name } + subheader={item && item.description} /> - - Here I will add copy - + -- 2.30.2