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, withStyles, WithStyles } from '@material-ui/core';
10 import { PropertyKeyField, PROPERTY_KEY_FIELD_NAME, PROPERTY_KEY_FIELD_ID } from './property-key-field';
11 import { PropertyValueField, PROPERTY_VALUE_FIELD_NAME, PROPERTY_VALUE_FIELD_ID } from './property-value-field';
12 import { ProgressButton } from 'components/progress-button/progress-button';
13 import { GridClassKey } from '@material-ui/core/Grid';
15 const AddButton = withStyles(theme => ({
16 root: { marginTop: theme.spacing.unit }
19 const mapStateToProps = (state: RootState) => {
21 applySelector: (selector) => selector(state, 'key', 'value', 'keyID', 'valueID')
25 interface ApplySelector {
26 applySelector: (selector) => any;
29 export interface ResourcePropertiesFormData {
31 [PROPERTY_KEY_FIELD_NAME]: string;
32 [PROPERTY_KEY_FIELD_ID]: string;
33 [PROPERTY_VALUE_FIELD_NAME]: string;
34 [PROPERTY_VALUE_FIELD_ID]: string;
35 clearPropertyKeyOnSelect?: boolean;
38 type ResourcePropertiesFormProps = {uuid: string; clearPropertyKeyOnSelect?: boolean } & InjectedFormProps<ResourcePropertiesFormData, {uuid: string;}> & WithStyles<GridClassKey> & ApplySelector;
40 export const ResourcePropertiesForm = connect(mapStateToProps)(({ handleSubmit, change, submitting, invalid, classes, uuid, clearPropertyKeyOnSelect, applySelector, ...props }: ResourcePropertiesFormProps ) => {
41 change('uuid', uuid); // Sets the uuid field to the uuid of the resource.
42 const propertyValue = applySelector(formValueSelector(props.form));
43 return <form data-cy='resource-properties-form' onSubmit={handleSubmit}>
44 <Grid container spacing={16} classes={classes}>
46 <PropertyKeyField clearPropertyKeyOnSelect />
49 <PropertyValueField />
53 data-cy='property-add-btn'
54 disabled={invalid || !(propertyValue.key && propertyValue.value)}