X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/83df67242fa95dd321a19189e68e3ce82f1a0837..17963753e57340121942857300c41c7852275c4b:/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 eb3c805093..1f92118885 100644
--- a/src/views-components/resource-properties-form/property-key-field.tsx
+++ b/src/views-components/resource-properties-form/property-key-field.tsx
@@ -3,35 +3,36 @@
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-import { change, WrappedFieldProps, WrappedFieldMetaProps, WrappedFieldInputProps, Field } from 'redux-form';
+import { WrappedFieldProps, Field, FormName } from 'redux-form';
import { memoize } from 'lodash';
import { Autocomplete } from '~/components/autocomplete/autocomplete';
-import { Vocabulary, getTags, getTagKeyID, PropFieldSuggestion } from '~/models/vocabulary';
-import { connectVocabulary, VocabularyProp, buildProps } 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 { COLLECTION_TAG_FORM_NAME } from '~/store/collection-panel/collection-panel-action';
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) =>
+ validate={skipValidation ? undefined : getValidation(vocabulary)} />
);
-export const PropertyKeyInput = ({ vocabulary, ...props }: WrappedFieldProps & VocabularyProp) =>
- ;
+const PropertyKeyInput = ({ vocabulary, ...props }: WrappedFieldProps & VocabularyProp) =>
+ (
+
+ )} />;
const getValidation = memoize(
(vocabulary: Vocabulary) =>
@@ -49,24 +50,3 @@ 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);
};
-
-// Attempts to match a manually typed key label with a key ID, when the user
-// doesn't select the key from the suggestions list.
-const handleBlur = (
- { dispatch }: WrappedFieldMetaProps,
- { onBlur, value }: WrappedFieldInputProps,
- vocabulary: Vocabulary) =>
- () => {
- dispatch(change(COLLECTION_TAG_FORM_NAME, PROPERTY_KEY_FIELD_ID, getTagKeyID(value, vocabulary)));
- onBlur(value);
- };
-
-// When selecting a property key, save its ID for later usage.
-const handleSelect = (
- { onChange }: WrappedFieldInputProps,
- { dispatch }: WrappedFieldMetaProps) => {
- return (item:PropFieldSuggestion) => {
- onChange(item.label);
- dispatch(change(COLLECTION_TAG_FORM_NAME, PROPERTY_KEY_FIELD_ID, item.id));
- };
-};