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, reset } from 'redux-form';
7 import { compose, Dispatch } from 'redux';
8 import { ArvadosTheme } from '~/common/custom-theme';
9 import { StyleRulesCallback, withStyles, WithStyles, TextField, Button, CircularProgress } from '@material-ui/core';
10 import { TagProperty } from '~/models/tag';
11 import { createCollectionTag, COLLECTION_TAG_FORM_NAME } from '~/store/collection-panel/collection-panel-action';
12 import { TAG_VALUE_VALIDATION, TAG_KEY_VALIDATION } from '~/validators/validators';
14 type CssRules = 'form' | 'textField' | 'buttonWrapper' | 'saveButton' | 'circularProgress';
16 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
18 marginBottom: theme.spacing.unit * 4
21 marginRight: theme.spacing.unit
25 display: 'inline-block'
40 interface CollectionTagFormDataProps {
46 interface CollectionTagFormActionProps {
50 interface TextFieldProps {
52 floatinglabeltext: string;
58 type CollectionTagFormProps = CollectionTagFormDataProps & CollectionTagFormActionProps & WithStyles<CssRules>;
60 export const CollectionTagForm = compose(
62 form: COLLECTION_TAG_FORM_NAME,
63 onSubmit: (data: TagProperty, dispatch: Dispatch) => {
64 dispatch<any>(createCollectionTag(data));
65 dispatch(reset(COLLECTION_TAG_FORM_NAME));
70 class CollectionTagForm extends React.Component<CollectionTagFormProps> {
73 const { classes, submitting, pristine, invalid, handleSubmit } = this.props;
75 <form className={classes.form} onSubmit={handleSubmit}>
78 component={this.renderTextField}
79 floatinglabeltext="Key"
80 validate={TAG_KEY_VALIDATION}
81 className={classes.textField}
85 component={this.renderTextField}
86 floatinglabeltext="Value"
87 validate={TAG_VALUE_VALIDATION}
88 className={classes.textField}
90 <div className={classes.buttonWrapper}>
91 <Button type="submit" className={classes.saveButton}
94 disabled={invalid || submitting || pristine}
98 {submitting && <CircularProgress size={20} className={classes.circularProgress} />}
104 renderTextField = ({ input, label, meta: { touched, error }, ...custom }: TextFieldProps) => (
106 helperText={touched && error}
108 className={this.props.classes.textField}
109 error={touched && !!error}