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, Button, CircularProgress, Grid } from '@material-ui/core';
10 import { TagProperty } from '~/models/tag';
11 import { TextField } from '~/components/text-field/text-field';
12 import { createCollectionTag, COLLECTION_TAG_FORM_NAME } from '~/store/collection-panel/collection-panel-action';
13 import { TAG_VALUE_VALIDATION, TAG_KEY_VALIDATION } from '~/validators/validators';
15 type CssRules = 'buttonWrapper' | 'saveButton' | 'circularProgress';
17 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
20 display: 'inline-block'
35 interface CollectionTagFormDataProps {
41 interface CollectionTagFormActionProps {
45 type CollectionTagFormProps = CollectionTagFormDataProps & CollectionTagFormActionProps & WithStyles<CssRules>;
47 export const CollectionTagForm = compose(
49 form: COLLECTION_TAG_FORM_NAME,
50 onSubmit: (data: TagProperty, dispatch: Dispatch) => {
51 dispatch<any>(createCollectionTag(data));
52 dispatch(reset(COLLECTION_TAG_FORM_NAME));
57 class CollectionTagForm extends React.Component<CollectionTagFormProps> {
60 const { classes, submitting, pristine, invalid, handleSubmit } = this.props;
62 <form onSubmit={handleSubmit}>
63 <Grid container justify="flex-start" alignItems="baseline" spacing={24}>
64 <Grid item xs={3} component={"span"}>
68 validate={TAG_KEY_VALIDATION}
71 <Grid item xs={5} component={"span"}>
75 validate={TAG_VALUE_VALIDATION}
78 <Grid item component={"span"} className={classes.buttonWrapper}>
79 <Button type="submit" className={classes.saveButton}
82 disabled={invalid || submitting || pristine}
86 {submitting && <CircularProgress size={20} className={classes.circularProgress} />}