X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6578e959652ed10a51424d1b66f80280164824dd..c44f9aa1e0b36cac00eca89d694876d40d427615:/src/views-components/resource-properties-form/property-key-field.tsx diff --git a/src/views-components/resource-properties-form/property-key-field.tsx b/src/views-components/resource-properties-form/property-key-field.tsx index 85cc07f6de..d17f50d465 100644 --- a/src/views-components/resource-properties-form/property-key-field.tsx +++ b/src/views-components/resource-properties-form/property-key-field.tsx @@ -3,51 +3,52 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { WrappedFieldProps, Field } from 'redux-form'; -import { identity, memoize } from 'lodash'; +import { WrappedFieldProps, Field, FormName } from 'redux-form'; +import { memoize } from 'lodash'; import { Autocomplete } from '~/components/autocomplete/autocomplete'; -import { Vocabulary } from '~/models/vocabulary'; -import { require } from '~/validators/require'; -import { ITEMS_PLACEHOLDER, connectVocabulary, VocabularyProp, hasError, getErrorMsg, handleBlur } from '~/views-components/resource-properties-form/property-field-common'; +import { Vocabulary, getTags, getTagKeyID } from '~/models/vocabulary'; +import { handleSelect, handleBlur, connectVocabulary, VocabularyProp, ValidationProp, buildProps } from '~/views-components/resource-properties-form/property-field-common'; +import { TAG_KEY_VALIDATION } from '~/validators/validators'; +import { escapeRegExp } from '~/common/regexp.ts'; export const PROPERTY_KEY_FIELD_NAME = 'key'; +export const PROPERTY_KEY_FIELD_ID = 'keyID'; export const PropertyKeyField = connectVocabulary( - ({ vocabulary }: VocabularyProp) => + ({ vocabulary, skipValidation }: VocabularyProp & ValidationProp) => + ); - -const PropertyKeyInput = ({ input, meta, vocabulary }: WrappedFieldProps & VocabularyProp) => - ; + validate={skipValidation ? undefined : getValidation(vocabulary)} /> + +); + +const PropertyKeyInput = ({ vocabulary, ...props }: WrappedFieldProps & VocabularyProp) => + ( + + )} />; const getValidation = memoize( (vocabulary: Vocabulary) => - vocabulary.strict - ? [require, matchTags(vocabulary)] - : [require]); + vocabulary.strict_tags + ? [...TAG_KEY_VALIDATION, matchTags(vocabulary)] + : TAG_KEY_VALIDATION); const matchTags = (vocabulary: Vocabulary) => (value: string) => - getTagsList(vocabulary).find(tag => tag.includes(value)) + getTags(vocabulary).find(tag => tag.label === value) ? undefined : 'Incorrect key'; -const getSuggestions = (value: string, vocabulary: Vocabulary) => - getTagsList(vocabulary).filter(tag => tag.includes(value) && tag !== value); - -const getTagsList = ({ tags }: Vocabulary) => - Object.keys(tags); +const getSuggestions = (value: string, vocabulary: Vocabulary) => { + const re = new RegExp(escapeRegExp(value), "i"); + return getTags(vocabulary).filter(tag => re.test(tag.label) && tag.label !== value); +};