[ARVADOS-WORKBENCH2] created: 1.2.0-130-ge1405a5
Git user
git at public.curoverse.com
Thu Aug 23 02:24:01 EDT 2018
at e1405a5108ab48429606c9460595dad6bd2d82c0 (commit)
commit e1405a5108ab48429606c9460595dad6bd2d82c0
Author: Janicki Artur <artur.janicki at contractors.roche.com>
Date: Tue Aug 21 13:04:35 2018 +0200
store - remove collection updater, rewrite collection edit dialog
Feature #14103
Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki at contractors.roche.com>
diff --git a/src/store/collections/collection-updater-actions.ts b/src/store/collections/collection-updater-actions.ts
new file mode 100644
index 0000000..34eadd1
--- /dev/null
+++ b/src/store/collections/collection-updater-actions.ts
@@ -0,0 +1,52 @@
+// 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
diff --git a/src/store/collections/collections-reducer.ts b/src/store/collections/collections-reducer.ts
index b2ee455..892a1ff 100644
--- a/src/store/collections/collections-reducer.ts
+++ b/src/store/collections/collections-reducer.ts
@@ -4,17 +4,14 @@
import { combineReducers } from 'redux';
import { collectionCreatorReducer, CollectionCreatorState } from "./creator/collection-creator-reducer";
-import { collectionUpdaterReducer, CollectionUpdaterState } from "./updater/collection-updater-reducer";
import { collectionUploaderReducer, CollectionUploaderState } from "./uploader/collection-uploader-reducer";
export type CollectionsState = {
creator: CollectionCreatorState;
- updater: CollectionUpdaterState;
uploader: CollectionUploaderState
};
export const collectionsReducer = combineReducers({
creator: collectionCreatorReducer,
- updater: collectionUpdaterReducer,
uploader: collectionUploaderReducer
});
diff --git a/src/store/collections/updater/collection-updater-action.ts b/src/store/collections/updater/collection-updater-action.ts
deleted file mode 100644
index 2f520d4..0000000
--- a/src/store/collections/updater/collection-updater-action.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import { default as unionize, ofType, UnionOf } from "unionize";
-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 { ContextMenuResource } from "../../context-menu/context-menu-reducer";
-import { updateDetails } from "~/store/details-panel/details-panel-action";
-
-export const collectionUpdaterActions = unionize({
- OPEN_COLLECTION_UPDATER: ofType<{ uuid: string }>(),
- CLOSE_COLLECTION_UPDATER: ofType<{}>(),
- UPDATE_COLLECTION_SUCCESS: ofType<{}>(),
-}, {
- tag: 'type',
- value: 'payload'
-});
-
-
-export const COLLECTION_FORM_NAME = 'collectionEditDialog';
-
-export const openUpdater = (item: ContextMenuResource) =>
- (dispatch: Dispatch, getState: () => RootState) => {
- if (item) {
- dispatch(collectionUpdaterActions.OPEN_COLLECTION_UPDATER({ uuid: item.uuid }));
- dispatch(initialize(COLLECTION_FORM_NAME, { name: item.name, description: item.description }));
- }
- };
-
-export const updateCollection = (collection: Partial<CollectionResource>) =>
- (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- const { uuid } = getState().collections.updater;
- return services.collectionService
- .update(uuid, collection)
- .then(collection => {
- dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection as CollectionResource }));
- dispatch(collectionUpdaterActions.UPDATE_COLLECTION_SUCCESS());
- dispatch<any>(updateDetails(collection));
- }
- );
- };
-
-export type CollectionUpdaterAction = UnionOf<typeof collectionUpdaterActions>;
diff --git a/src/store/collections/updater/collection-updater-reducer.ts b/src/store/collections/updater/collection-updater-reducer.ts
deleted file mode 100644
index 97d010f..0000000
--- a/src/store/collections/updater/collection-updater-reducer.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import { collectionUpdaterActions, CollectionUpdaterAction } from './collection-updater-action';
-
-export interface CollectionUpdaterState {
- opened: boolean;
- uuid: string;
-}
-
-const updateCollection = (state: CollectionUpdaterState, updater?: Partial<CollectionUpdaterState>) => ({
- ...state,
- ...updater
-});
-
-const initialState: CollectionUpdaterState = {
- opened: false,
- uuid: ''
-};
-
-export const collectionUpdaterReducer = (state: CollectionUpdaterState = initialState, action: CollectionUpdaterAction) => {
- return collectionUpdaterActions.match(action, {
- OPEN_COLLECTION_UPDATER: ({ uuid }) => updateCollection(state, { uuid, opened: true }),
- CLOSE_COLLECTION_UPDATER: () => updateCollection(state, { opened: false, uuid: "" }),
- UPDATE_COLLECTION_SUCCESS: () => updateCollection(state, { opened: false, uuid: "" }),
- default: () => state
- });
-};
diff --git a/src/views-components/dialog-update/dialog-collection-update.tsx b/src/views-components/dialog-update/dialog-collection-update.tsx
index 18c43f2..31dd264 100644
--- a/src/views-components/dialog-update/dialog-collection-update.tsx
+++ b/src/views-components/dialog-update/dialog-collection-update.tsx
@@ -3,103 +3,32 @@
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-import { reduxForm, Field } from 'redux-form';
-import { compose } from 'redux';
-import { ArvadosTheme } from '~/common/custom-theme';
-import { Dialog, DialogActions, DialogContent, DialogTitle, StyleRulesCallback, withStyles, WithStyles, Button, CircularProgress } from '@material-ui/core';
+import { InjectedFormProps, Field } 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 { COLLECTION_FORM_NAME } from '~/store/collections/updater/collection-updater-action';
import { TextField } from '~/components/text-field/text-field';
-
-type CssRules = 'content' | 'actions' | 'buttonWrapper' | 'saveButton' | 'circularProgress';
-
-const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
- content: {
- display: 'flex',
- flexDirection: 'column'
- },
- actions: {
- margin: 0,
- padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3 - theme.spacing.unit / 2}px
- ${theme.spacing.unit * 3}px ${theme.spacing.unit * 3}px`
- },
- buttonWrapper: {
- position: 'relative'
- },
- saveButton: {
- boxShadow: 'none'
- },
- circularProgress: {
- position: 'absolute',
- top: 0,
- bottom: 0,
- left: 0,
- right: 0,
- margin: 'auto'
- }
-});
-
-interface DialogCollectionDataProps {
- open: boolean;
- handleSubmit: any;
- submitting: boolean;
- invalid: boolean;
- pristine: boolean;
-}
-
-interface DialogCollectionAction {
- handleClose: () => void;
- onSubmit: (data: { name: string, description: string }) => void;
-}
-
-type DialogCollectionProps = DialogCollectionDataProps & DialogCollectionAction & WithStyles<CssRules>;
-
-export const DialogCollectionUpdate = compose(
- reduxForm({ form: COLLECTION_FORM_NAME }),
- withStyles(styles))(
-
- class DialogCollectionUpdate extends React.Component<DialogCollectionProps> {
-
- render() {
- const { classes, open, handleClose, handleSubmit, onSubmit, submitting, invalid, pristine } = this.props;
- return (
- <Dialog open={open}
- onClose={handleClose}
- fullWidth={true}
- maxWidth='sm'
- disableBackdropClick={true}
- disableEscapeKeyDown={true}>
-
- <form onSubmit={handleSubmit((data: any) => onSubmit(data))}>
- <DialogTitle>Edit Collection</DialogTitle>
- <DialogContent className={classes.content}>
- <Field name='name'
- disabled={submitting}
- component={TextField}
- validate={COLLECTION_NAME_VALIDATION}
- label="Collection Name" />
- <Field name='description'
- disabled={submitting}
- component={TextField}
- validate={COLLECTION_DESCRIPTION_VALIDATION}
- label="Description - optional" />
- </DialogContent>
- <DialogActions className={classes.actions}>
- <Button onClick={handleClose} color="primary"
- disabled={submitting}>CANCEL</Button>
- <div className={classes.buttonWrapper}>
- <Button type="submit" className={classes.saveButton}
- color="primary"
- disabled={invalid || submitting || pristine}
- variant="contained">
- SAVE
- </Button>
- {submitting && <CircularProgress size={20} className={classes.circularProgress} />}
- </div>
- </DialogActions>
- </form>
- </Dialog>
- );
- }
- }
- );
+import { FormDialog } from '~/components/form-dialog/form-dialog';
+
+type DialogCollectionProps = WithDialogProps<{}> & InjectedFormProps<CollectionUpdateFormDialogData>;
+
+export const DialogCollectionUpdate = (props: DialogCollectionProps) =>
+ <FormDialog
+ dialogTitle='Edit Collection'
+ formFields={CollectionEditFields}
+ submitLabel='Save'
+ {...props}
+ />;
+
+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" />
+</span>;
diff --git a/src/views-components/update-collection-dialog/update-collection-dialog..tsx b/src/views-components/update-collection-dialog/update-collection-dialog..tsx
deleted file mode 100644
index 239df58..0000000
--- a/src/views-components/update-collection-dialog/update-collection-dialog..tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import { connect } from "react-redux";
-import { Dispatch } from "redux";
-import { SubmissionError } from "redux-form";
-import { RootState } from "~/store/store";
-import { snackbarActions } from "~/store/snackbar/snackbar-actions";
-import { collectionUpdaterActions, updateCollection } from "~/store/collections/updater/collection-updater-action";
-import { dataExplorerActions } from "~/store/data-explorer/data-explorer-action";
-import { PROJECT_PANEL_ID } from "~/views/project-panel/project-panel";
-import { DialogCollectionUpdate } from "../dialog-update/dialog-collection-update";
-
-const mapStateToProps = (state: RootState) => ({
- open: state.collections.updater.opened
-});
-
-const mapDispatchToProps = (dispatch: Dispatch) => ({
- handleClose: () => {
- dispatch(collectionUpdaterActions.CLOSE_COLLECTION_UPDATER());
- },
- onSubmit: (data: { name: string, description: string }) => {
- return dispatch<any>(editCollection(data))
- .catch((e: any) => {
- if(e.errors) {
- throw new SubmissionError({ name: e.errors.join("").includes("UniqueViolation") ? "Collection with this name already exists." : "" });
- }
- });
- }
-});
-
-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 UpdateCollectionDialog = connect(mapStateToProps, mapDispatchToProps)(DialogCollectionUpdate);
diff --git a/src/views-components/update-collection-dialog/update-collection-dialog.ts b/src/views-components/update-collection-dialog/update-collection-dialog.ts
new file mode 100644
index 0000000..3556472
--- /dev/null
+++ b/src/views-components/update-collection-dialog/update-collection-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 { DialogCollectionUpdate } from '../dialog-update/dialog-collection-update';
+import { editCollection, COLLECTION_FORM_NAME, CollectionUpdateFormDialogData } from '~/store/collections/collection-updater-actions';
+
+export const UpdateCollectionDialog = compose(
+ withDialog(COLLECTION_FORM_NAME),
+ reduxForm<CollectionUpdateFormDialogData>({
+ form: COLLECTION_FORM_NAME,
+ onSubmit: (data, dispatch) => {
+ dispatch(editCollection(data));
+ }
+ })
+)(DialogCollectionUpdate);
\ No newline at end of file
diff --git a/src/views/workbench/workbench.tsx b/src/views/workbench/workbench.tsx
index 89bd71e..47e9386 100644
--- a/src/views/workbench/workbench.tsx
+++ b/src/views/workbench/workbench.tsx
@@ -40,7 +40,7 @@ import { CreateCollectionDialog } from '~/views-components/create-collection-dia
import { CollectionPanel } from '../collection-panel/collection-panel';
import { loadCollection, loadCollectionTags } from '~/store/collection-panel/collection-panel-action';
import { getCollectionUrl } from '~/models/collection';
-import { UpdateCollectionDialog } from '~/views-components/update-collection-dialog/update-collection-dialog.';
+import { UpdateCollectionDialog } from '~/views-components/update-collection-dialog/update-collection-dialog';
import { UpdateProjectDialog } from '~/views-components/update-project-dialog/update-project-dialog';
import { AuthService } from "~/services/auth-service/auth-service";
import { RenameFileDialog } from '~/views-components/rename-file-dialog/rename-file-dialog';
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list