1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { RootState } from 'store/store';
7 import { connect } from 'react-redux';
8 import { formValueSelector, InjectedFormProps } from 'redux-form';
9 import { Grid } from '@mui/material';
10 import { WithStyles } from '@mui/styles';
11 import withStyles from '@mui/styles/withStyles';
12 import { PropertyKeyField, PROPERTY_KEY_FIELD_NAME, PROPERTY_KEY_FIELD_ID } from './property-key-field';
13 import { PropertyValueField, PROPERTY_VALUE_FIELD_NAME, PROPERTY_VALUE_FIELD_ID } from './property-value-field';
14 import { ProgressButton } from 'components/progress-button/progress-button';
15 import { GridClassKey } from '@mui/material/Grid';
17 const AddButton = withStyles(theme => ({
18 root: { marginTop: theme.spacing(1) }
21 const mapStateToProps = (state: RootState) => {
23 applySelector: (selector) => selector(state, 'key', 'value', 'keyID', 'valueID')
27 interface ApplySelector {
28 applySelector: (selector) => any;
31 export interface ResourcePropertiesFormData {
33 [PROPERTY_KEY_FIELD_NAME]: string;
34 [PROPERTY_KEY_FIELD_ID]: string;
35 [PROPERTY_VALUE_FIELD_NAME]: string;
36 [PROPERTY_VALUE_FIELD_ID]: string;
37 clearPropertyKeyOnSelect?: boolean;
40 type ResourcePropertiesFormProps = {uuid: string; clearPropertyKeyOnSelect?: boolean } & InjectedFormProps<ResourcePropertiesFormData, {uuid: string;}> & WithStyles<GridClassKey> & ApplySelector;
42 export const ResourcePropertiesForm = connect(mapStateToProps)(({ handleSubmit, change, submitting, invalid, classes, uuid, clearPropertyKeyOnSelect, applySelector, ...props }: ResourcePropertiesFormProps ) => {
43 change('uuid', uuid); // Sets the uuid field to the uuid of the resource.
44 const propertyValue = applySelector(formValueSelector(props.form));
45 return <form data-cy='resource-properties-form' onSubmit={handleSubmit}>
46 <Grid container spacing={2} classes={classes}>
49 <PropertyKeyField clearPropertyKeyOnSelect />
52 data-cy='value-input'>
53 <PropertyValueField />
57 data-cy='property-add-btn'
58 disabled={invalid || !(propertyValue.key && propertyValue.value)}