X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/8623f430ea556381f8681c2aea00e43e64d3f6d1..7ea638f63582f5c9b6ab696c3dcb1855778d2432:/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 db2db3f7..99745199 100644
--- a/src/views-components/resource-properties-form/property-value-field.tsx
+++ b/src/views-components/resource-properties-form/property-value-field.tsx
@@ -3,39 +3,48 @@
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-import { WrappedFieldProps, Field, formValues } from 'redux-form';
+import { WrappedFieldProps, Field, formValues, FormName } from 'redux-form';
import { compose } from 'redux';
import { Autocomplete } from '~/components/autocomplete/autocomplete';
-import { Vocabulary } from '~/models/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 { Vocabulary, isStrictTag, getTagValues, getTagValueID } from '~/models/vocabulary';
+import { PROPERTY_KEY_FIELD_ID } from '~/views-components/resource-properties-form/property-key-field';
+import { handleSelect, handleBlur, VocabularyProp, ValidationProp, connectVocabulary, buildProps } from '~/views-components/resource-properties-form/property-field-common';
import { TAG_VALUE_VALIDATION } from '~/validators/validators';
+import { escapeRegExp } from '~/common/regexp.ts';
interface PropertyKeyProp {
propertyKey: string;
}
-type PropertyValueFieldProps = VocabularyProp & PropertyKeyProp;
+type PropertyValueFieldProps = VocabularyProp & PropertyKeyProp & ValidationProp;
export const PROPERTY_VALUE_FIELD_NAME = 'value';
+export const PROPERTY_VALUE_FIELD_ID = 'valueID';
-export const PropertyValueField = compose(
+const connectVocabularyAndPropertyKey = compose(
connectVocabulary,
- formValues({ propertyKey: PROPERTY_KEY_FIELD_NAME })
-)(
- (props: PropertyValueFieldProps) =>
+ formValues({ propertyKey: PROPERTY_KEY_FIELD_ID }),
+);
+
+export const PropertyValueField = connectVocabularyAndPropertyKey(
+ ({ skipValidation, ...props }: PropertyValueFieldProps) =>
);
+ validate={skipValidation ? undefined : getValidation(props)}
+ {...props} />
+);
const PropertyValueInput = ({ vocabulary, propertyKey, ...props }: WrappedFieldProps & PropertyValueFieldProps) =>
- ;
+ (
+
+ )} />;
const getValidation = (props: PropertyValueFieldProps) =>
isStrictTag(props.propertyKey, props.vocabulary)
@@ -44,19 +53,11 @@ const getValidation = (props: PropertyValueFieldProps) =>
const matchTagValues = ({ vocabulary, propertyKey }: PropertyValueFieldProps) =>
(value: string) =>
- getTagValues(propertyKey, vocabulary).find(v => v.includes(value))
+ getTagValues(propertyKey, vocabulary).find(v => v.label === value)
? undefined
: 'Incorrect value';
-const getSuggestions = (value: string, tagName: string, vocabulary: Vocabulary) =>
- getTagValues(tagName, vocabulary).filter(v => v.includes(value) && v !== value);
-
-const isStrictTag = (tagName: string, vocabulary: Vocabulary) => {
- const tag = vocabulary.tags[tagName];
- return tag ? tag.strict : false;
-};
-
-const getTagValues = (tagName: string, vocabulary: Vocabulary) => {
- const tag = vocabulary.tags[tagName];
- return tag && tag.values ? tag.values : [];
+const getSuggestions = (value: string, tagName: string, vocabulary: Vocabulary) => {
+ const re = new RegExp(escapeRegExp(value), "i");
+ return getTagValues(tagName, vocabulary).filter(v => re.test(v.label) && v.label !== value);
};