X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/2c2bd28224c2480276ae714c54ab1be0a6896efd..ef8180fa2f0b90b1656b1d8c7ef12bc6ea028a0a:/src/views-components/dialog-update/dialog-project-update.tsx?ds=sidebyside

diff --git a/src/views-components/dialog-update/dialog-project-update.tsx b/src/views-components/dialog-update/dialog-project-update.tsx
index b5e788c0..a6ac65b1 100644
--- a/src/views-components/dialog-update/dialog-project-update.tsx
+++ b/src/views-components/dialog-update/dialog-project-update.tsx
@@ -2,100 +2,62 @@
 //
 // 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 { StyleRulesCallback, WithStyles, withStyles, Dialog, DialogTitle, DialogContent, DialogActions, CircularProgress, Button } from '../../../node_modules/@material-ui/core';
-import { TextField } from '~/components/text-field/text-field';
-import { PROJECT_FORM_NAME } from '~/store/project/project-action';
-import { PROJECT_NAME_VALIDATION, PROJECT_DESCRIPTION_VALIDATION } from '~/validators/validators';
-
-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'
+import React from 'react';
+import { InjectedFormProps } from 'redux-form';
+import { WithDialogProps } from 'store/dialog/with-dialog';
+import { ProjectUpdateFormDialogData, PROJECT_UPDATE_FORM_NAME } from 'store/projects/project-update-actions';
+import { FormDialog } from 'components/form-dialog/form-dialog';
+import { ProjectNameField, ProjectDescriptionField } from 'views-components/form-fields/project-form-fields';
+import { GroupClass } from 'models/group';
+import { FormGroup, FormLabel, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
+import { UpdateProjectPropertiesForm } from 'views-components/project-properties/update-project-properties-form';
+import { resourcePropertiesList } from 'views-components/resource-properties/resource-properties-list';
+
+type CssRules = 'propertiesForm' | 'description';
+
+const styles: StyleRulesCallback<CssRules> = theme => ({
+    propertiesForm: {
+        marginTop: theme.spacing.unit * 2,
+        marginBottom: theme.spacing.unit * 2,
     },
-    saveButton: {
-        boxShadow: 'none'
+    description: {
+        marginTop: theme.spacing.unit * 2,
+        marginBottom: theme.spacing.unit * 2,
     },
-    circularProgress: {
-        position: 'absolute',
-        top: 0,
-        bottom: 0,
-        left: 0,
-        right: 0,
-        margin: 'auto'
-    }
 });
 
-interface DialogProjectDataProps {
-    open: boolean;
-    handleSubmit: any;
-    submitting: boolean;
-    invalid: boolean;
-    pristine: boolean;
-}
-
-interface DialogProjectActionProps {
-    handleClose: () => void;
-    onSubmit: (data: { name: string, description: string }) => void;
-}
+type DialogProjectProps = WithDialogProps<{sourcePanel: GroupClass}> & InjectedFormProps<ProjectUpdateFormDialogData>;
 
-type DialogProjectProps = DialogProjectDataProps & DialogProjectActionProps & WithStyles<CssRules>;
+export const DialogProjectUpdate = (props: DialogProjectProps) => {
+    let title = 'Edit Project';
+    const sourcePanel = props.data.sourcePanel || '';
 
-export const DialogProjectUpdate = compose(
-    reduxForm({ form: PROJECT_FORM_NAME }),
-    withStyles(styles))(
+    if (sourcePanel === GroupClass.ROLE) {
+        title = 'Edit Group';
+    }
 
-        class DialogProjectUpdate extends React.Component<DialogProjectProps> {
-            render() {
-                const { handleSubmit, handleClose, onSubmit, open, classes, 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 Project</DialogTitle>
-                        <DialogContent className={classes.content}>
-                            <Field name='name' 
-                                disabled={submitting}
-                                component={TextField}
-                                validate={PROJECT_NAME_VALIDATION}
-                                label="Project Name" />
-                            <Field name='description' 
-                                disabled={submitting}
-                                component={TextField} 
-                                validate={PROJECT_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>;
-            }
-        }
-    );
+    return <FormDialog
+        dialogTitle={title}
+        formFields={ProjectEditFields as any}
+        submitLabel='Save'
+        {...props}
+    />;
+};
+
+const UpdateProjectPropertiesList = resourcePropertiesList(PROJECT_UPDATE_FORM_NAME);
+
+// Also used as "Group Edit Fields"
+const ProjectEditFields = withStyles(styles)(
+    ({ classes }: WithStyles<CssRules>) => <span>
+        <ProjectNameField />
+        <div className={classes.description}>
+            <ProjectDescriptionField />
+        </div>
+        <div className={classes.propertiesForm}>
+            <FormLabel>Properties</FormLabel>
+            <FormGroup>
+                <UpdateProjectPropertiesForm />
+                <UpdateProjectPropertiesList />
+            </FormGroup>
+        </div>
+    </span>);
