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, StyleRulesCallback, withStyles, WithStyles, Button, CircularProgress } from '@material-ui/core';
10 import { COLLECTION_NAME_VALIDATION, COLLECTION_DESCRIPTION_VALIDATION } from '~/validators/validators';
11 import { COLLECTION_FORM_NAME } from '~/store/collections/updater/collection-updater-action';
12 import { TextField } from '~/components/text-field/text-field';
14 type CssRules = 'content' | 'actions' | 'buttonWrapper' | 'saveButton' | 'circularProgress';
16 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
19 flexDirection: 'column'
23 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3 - theme.spacing.unit / 2}px
24 ${theme.spacing.unit * 3}px ${theme.spacing.unit * 3}px`
42 interface DialogCollectionDataProps {
50 interface DialogCollectionAction {
51 handleClose: () => void;
52 onSubmit: (data: { name: string, description: string }) => void;
55 type DialogCollectionProps = DialogCollectionDataProps & DialogCollectionAction & WithStyles<CssRules>;
57 export const DialogCollectionUpdate = compose(
58 reduxForm({ form: COLLECTION_FORM_NAME }),
61 class DialogCollectionUpdate extends React.Component<DialogCollectionProps> {
64 const { classes, open, handleClose, handleSubmit, onSubmit, submitting, invalid, pristine } = this.props;
70 disableBackdropClick={true}
71 disableEscapeKeyDown={true}>
73 <form onSubmit={handleSubmit((data: any) => onSubmit(data))}>
74 <DialogTitle>Edit Collection</DialogTitle>
75 <DialogContent className={classes.content}>
79 validate={COLLECTION_NAME_VALIDATION}
80 label="Collection Name" />
81 <Field name='description'
84 validate={COLLECTION_DESCRIPTION_VALIDATION}
85 label="Description - optional" />
87 <DialogActions className={classes.actions}>
88 <Button onClick={handleClose} color="primary"
89 disabled={submitting}>CANCEL</Button>
90 <div className={classes.buttonWrapper}>
91 <Button type="submit" className={classes.saveButton}
93 disabled={invalid || submitting || pristine}
97 {submitting && <CircularProgress size={20} className={classes.circularProgress} />}