X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c4c906cb232d8974858e4da2393fb7a83a24fbd0..0ee5873d56416cf0c102f9e8930322fa80762f41:/src/components/form-dialog/form-dialog.tsx

diff --git a/src/components/form-dialog/form-dialog.tsx b/src/components/form-dialog/form-dialog.tsx
index 29c0b163..b50504a6 100644
--- a/src/components/form-dialog/form-dialog.tsx
+++ b/src/components/form-dialog/form-dialog.tsx
@@ -2,13 +2,13 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
+import React from 'react';
 import { InjectedFormProps } from 'redux-form';
 import { Dialog, DialogActions, DialogContent, DialogTitle } from '@material-ui/core/';
 import { Button, StyleRulesCallback, WithStyles, withStyles, CircularProgress } from '@material-ui/core';
-import { WithDialogProps } from '~/store/dialog/with-dialog';
+import { WithDialogProps } from 'store/dialog/with-dialog';
 
-type CssRules = "button" | "lastButton" | "formContainer" | "textField" | "dialog" | "dialogTitle" | "progressIndicator" | "dialogActions";
+type CssRules = "button" | "lastButton" | "form" | "formContainer" | "dialogTitle" | "progressIndicator" | "dialogActions";
 
 const styles: StyleRulesCallback<CssRules> = theme => ({
     button: {
@@ -16,74 +16,89 @@ const styles: StyleRulesCallback<CssRules> = theme => ({
     },
     lastButton: {
         marginLeft: theme.spacing.unit,
-        marginRight: "20px",
+        marginRight: "0",
+    },
+    form: {
+        display: 'flex',
+        overflowY: 'auto',
+        flexDirection: 'column',
+        flex: '0 1 auto',
     },
     formContainer: {
         display: "flex",
         flexDirection: "column",
-        marginTop: "20px",
+        paddingBottom: "0",
     },
     dialogTitle: {
-        paddingBottom: "0"
-    },
-    textField: {
-        marginTop: "32px",
-    },
-    dialog: {
-        minWidth: "600px",
-        minHeight: "320px"
+        paddingTop: theme.spacing.unit,
+        paddingBottom: theme.spacing.unit,
     },
     progressIndicator: {
         position: "absolute",
         minWidth: "20px",
     },
     dialogActions: {
-        marginBottom: "24px"
+        marginBottom: theme.spacing.unit,
+        marginRight: theme.spacing.unit * 3,
     }
 });
 
-interface DialogProjectProps {
+interface DialogProjectDataProps {
     cancelLabel?: string;
     dialogTitle: string;
-    formFields: React.ComponentType<InjectedFormProps<any>>;
+    formFields: React.ComponentType<InjectedFormProps<any> & WithDialogProps<any>>;
     submitLabel?: string;
+    cancelCallback?: Function;
+    enableWhenPristine?: boolean;
+    doNotDisableCancel?: boolean;
 }
 
-export const FormDialog = withStyles(styles)((props: DialogProjectProps & WithDialogProps<{}> & InjectedFormProps<any> & WithStyles<CssRules>) =>
+type DialogProjectProps = DialogProjectDataProps & WithDialogProps<{}> & InjectedFormProps<any> & WithStyles<CssRules>;
+
+export const FormDialog = withStyles(styles)((props: DialogProjectProps) =>
     <Dialog
         open={props.open}
         onClose={props.closeDialog}
-        disableBackdropClick={props.submitting}
-        disableEscapeKeyDown={props.submitting}>
-        <div className={props.classes.dialog}>
-            <form>
-                <DialogTitle className={props.classes.dialogTitle}>
-                    {props.dialogTitle}
-                </DialogTitle>
-                <DialogContent className={props.classes.formContainer}>
-                    <props.formFields {...props} />
-                </DialogContent>
-                <DialogActions className={props.classes.dialogActions}>
-                    <Button
-                        onClick={props.closeDialog}
-                        className={props.classes.button}
-                        color="primary"
-                        disabled={props.submitting}>
-                        {props.cancelLabel || 'Cancel'}
-                    </Button>
-                    <Button
-                        onClick={props.handleSubmit}
-                        className={props.classes.lastButton}
-                        color="primary"
-                        disabled={props.invalid || props.submitting || props.pristine}
-                        variant="contained">
-                        {props.submitLabel || 'Submit'}
-                        {props.submitting && <CircularProgress size={20} className={props.classes.progressIndicator} />}
-                    </Button>
-                </DialogActions>
-            </form>
-        </div>
+        disableBackdropClick
+        disableEscapeKeyDown={props.submitting}
+        fullWidth
+        maxWidth='md'>
+        <form data-cy='form-dialog' className={props.classes.form}>
+            <DialogTitle className={props.classes.dialogTitle}>
+                {props.dialogTitle}
+            </DialogTitle>
+            <DialogContent className={props.classes.formContainer}>
+                <props.formFields {...props} />
+            </DialogContent>
+            <DialogActions className={props.classes.dialogActions}>
+                <Button
+                    data-cy='form-cancel-btn'
+                    onClick={() => {
+                        props.closeDialog();
+
+                        if (props.cancelCallback) {
+                            props.cancelCallback();
+                            props.reset();
+                            props.initialize({});
+                        }
+                    }}
+                    className={props.classes.button}
+                    color="primary"
+                    disabled={props.doNotDisableCancel ? false : props.submitting}>
+                    {props.cancelLabel || 'Cancel'}
+                </Button>
+                <Button
+                    data-cy='form-submit-btn'
+                    type="submit"
+                    onClick={props.handleSubmit}
+                    className={props.classes.lastButton}
+                    color="primary"
+                    disabled={props.invalid || props.submitting || (props.pristine && !props.enableWhenPristine)}
+                    variant="contained">
+                    {props.submitLabel || 'Submit'}
+                    {props.submitting && <CircularProgress size={20} className={props.classes.progressIndicator} />}
+                </Button>
+            </DialogActions>
+        </form>
     </Dialog>
 );
-
-
