X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/81546d30cd19cd98939e56e1b01b5c9684941f98..f4e410a5984226818301332c25ac178403c2e0e9:/src/views-components/resource-properties-form/property-value-field.tsx diff --git a/src/views-components/resource-properties-form/property-value-field.tsx b/src/views-components/resource-properties-form/property-value-field.tsx index eed8e75b6c..13dcfeb544 100644 --- a/src/views-components/resource-properties-form/property-value-field.tsx +++ b/src/views-components/resource-properties-form/property-value-field.tsx @@ -3,54 +3,44 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { WrappedFieldProps, Field } from 'redux-form'; -import { connect } from 'react-redux'; -import { identity } from 'lodash'; -import { RootState } from '~/store/store'; -import { getVocabulary } from '~/store/vocabulary/vocabulary-selctors'; +import { WrappedFieldProps, Field, formValues } from 'redux-form'; +import { compose } from 'redux'; import { Autocomplete } from '~/components/autocomplete/autocomplete'; import { Vocabulary } from '~/models/vocabulary'; -import { require } from '~/validators/require'; - -interface VocabularyProp { - vocabulary: Vocabulary; -} +import { PROPERTY_KEY_FIELD_NAME } from '~/views-components/resource-properties-form/property-key-field'; +import { VocabularyProp, connectVocabulary, buildProps } from '~/views-components/resource-properties-form/property-field-common'; +import { TAG_VALUE_VALIDATION } from '~/validators/validators'; interface PropertyKeyProp { propertyKey: string; } -type PropertyValueFieldProps = VocabularyProp & PropertyKeyProp; +export type PropertyValueFieldProps = VocabularyProp & PropertyKeyProp; -const mapStateToProps = (state: RootState): VocabularyProp => ({ - vocabulary: getVocabulary(state.properties), -}); +export const PROPERTY_VALUE_FIELD_NAME = 'value'; -export const PropertyValueField = connect(mapStateToProps)( +export const PropertyValueField = compose( + connectVocabulary, + formValues({ propertyKey: PROPERTY_KEY_FIELD_NAME }) +)( (props: PropertyValueFieldProps) => ); -const PropertyValueInput = ({ input, meta, vocabulary, propertyKey }: WrappedFieldProps & PropertyValueFieldProps) => +export const PropertyValueInput = ({ vocabulary, propertyKey, ...props }: WrappedFieldProps & PropertyValueFieldProps) => ; const getValidation = (props: PropertyValueFieldProps) => isStrictTag(props.propertyKey, props.vocabulary) - ? [require, matchTagValues(props)] - : [require]; + ? [...TAG_VALUE_VALIDATION, matchTagValues(props)] + : TAG_VALUE_VALIDATION; const matchTagValues = ({ vocabulary, propertyKey }: PropertyValueFieldProps) => (value: string) => @@ -68,7 +58,5 @@ const isStrictTag = (tagName: string, vocabulary: Vocabulary) => { const getTagValues = (tagName: string, vocabulary: Vocabulary) => { const tag = vocabulary.tags[tagName]; - return tag ? tag.values : []; + return tag && tag.values ? tag.values : []; }; - -const ITEMS_PLACEHOLDER: string[] = [];