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 } from '@material-ui/core';
10 import { TagProperty } from '~/models/tag';
11 import { TextField } from '~/components/text-field/text-field';
12 import { TAG_VALUE_VALIDATION, TAG_KEY_VALIDATION } from '~/validators/validators';
13 import { PROJECT_PROPERTIES_FORM_NAME, createProjectProperty } from '~/store/details-panel/details-panel-action';
15 type CssRules = 'root' | 'keyField' | 'valueField' | 'buttonWrapper' | 'saveButton' | 'circularProgress';
17 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
24 marginRight: theme.spacing.unit * 3
28 marginRight: theme.spacing.unit * 3
47 interface ProjectPropertiesFormDataProps {
53 interface ProjectPropertiesFormActionProps {
57 type ProjectPropertiesFormProps = ProjectPropertiesFormDataProps & ProjectPropertiesFormActionProps & WithStyles<CssRules>;
59 export const ProjectPropertiesForm = compose(
61 form: PROJECT_PROPERTIES_FORM_NAME,
62 onSubmit: (data: TagProperty, dispatch: Dispatch) => {
63 dispatch<any>(createProjectProperty(data));
64 dispatch(reset(PROJECT_PROPERTIES_FORM_NAME));
68 ({ classes, submitting, pristine, invalid, handleSubmit }: ProjectPropertiesFormProps) =>
69 <form onSubmit={handleSubmit} className={classes.root}>
70 <div className={classes.keyField}>
74 validate={TAG_KEY_VALIDATION}
77 <div className={classes.valueField}>
81 validate={TAG_VALUE_VALIDATION}
84 <div className={classes.buttonWrapper}>
85 <Button type="submit" className={classes.saveButton}
88 disabled={invalid || submitting || pristine}
92 {submitting && <CircularProgress size={20} className={classes.circularProgress} />}