1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { reduxForm, Field } from 'redux-form';
7 import { compose } from 'redux';
8 import { ArvadosTheme } from '../../common/custom-theme';
9 import { Dialog, DialogActions, DialogContent, DialogTitle, TextField, StyleRulesCallback, withStyles, WithStyles, Button, CircularProgress } from '../../../node_modules/@material-ui/core';
10 import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION } from '../../validators/create-project/create-project-validator';
12 type CssRules = 'content' | 'actions' | 'textField' | 'buttonWrapper' | 'saveButton' | 'circularProgress';
14 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
17 flexDirection: 'column'
21 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3 - theme.spacing.unit / 2}px
22 ${theme.spacing.unit * 3}px ${theme.spacing.unit * 3}px`
25 marginBottom: theme.spacing.unit * 3
43 interface DialogCollectionDataProps {
51 interface DialogCollectionAction {
52 handleClose: () => void;
53 onSubmit: (data: { name: string, description: string }) => void;
56 type DialogCollectionProps = DialogCollectionDataProps & DialogCollectionAction & WithStyles<CssRules>;
58 interface TextFieldProps {
60 floatinglabeltext: string;
66 export const DialogCollectionUpdate = compose(
67 reduxForm({ form: 'collectionEditDialog' }),
70 class DialogCollectionUpdate extends React.Component<DialogCollectionProps> {
73 const { classes, open, handleClose, handleSubmit, onSubmit, submitting, invalid, pristine } = this.props;
79 disableBackdropClick={true}
80 disableEscapeKeyDown={true}>
82 <form onSubmit={handleSubmit((data: any) => onSubmit(data))}>
83 <DialogTitle>Edit Collection</DialogTitle>
84 <DialogContent className={classes.content}>
87 component={this.renderTextField}
88 floatinglabeltext="Collection Name"
89 validate={COLLECTION_NAME_VALIDATION}
90 className={classes.textField}
91 label="Collection Name" />
92 <Field name="description"
94 component={this.renderTextField}
95 floatinglabeltext="Description - optional"
96 validate={COLLECTION_DESCRIPTION_VALIDATION}
97 className={classes.textField}
98 label="Description - optional" />
100 <DialogActions className={classes.actions}>
101 <Button onClick={handleClose} color="primary"
102 disabled={submitting}>CANCEL</Button>
103 <div className={classes.buttonWrapper}>
104 <Button type="submit" className={classes.saveButton}
106 disabled={invalid || submitting || pristine}
110 {submitting && <CircularProgress size={20} className={classes.circularProgress} />}
118 renderTextField = ({ input, label, meta: { touched, error }, ...custom }: TextFieldProps) => (
120 helperText={touched && error}
122 className={this.props.classes.textField}
123 error={touched && !!error}