Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>
else {
vocabularyUrl = clusterConfigJSON.Workbench.VocabularyURL || "/vocabulary-example.json";
}
- // FIXME: The following line is for dev testing purposes
- vocabularyUrl = "/vocabulary-example.json";
-
config.vocabularyUrl = vocabularyUrl;
return { config, apiHost: workbenchConfig.API_HOST };
// SPDX-License-Identifier: AGPL-3.0
import { connect } from 'react-redux';
-import { WrappedFieldMetaProps, WrappedFieldInputProps, WrappedFieldProps } from 'redux-form';
+import { change, WrappedFieldMetaProps, WrappedFieldInputProps, WrappedFieldProps } from 'redux-form';
import { Vocabulary, PropFieldSuggestion } from '~/models/vocabulary';
import { RootState } from '~/store/store';
import { getVocabulary } from '~/store/vocabulary/vocabulary-selectors';
? meta.error
: '';
-export const handleBlur = ({ onBlur, value }: WrappedFieldInputProps) =>
- () =>
- onBlur(value);
-
export const buildProps = ({ input, meta }: WrappedFieldProps) => {
return {
value: input.value,
onChange: input.onChange,
- onBlur: handleBlur(input),
items: ITEMS_PLACEHOLDER,
renderSuggestion: (item:PropFieldSuggestion) => item.label,
error: hasError(meta),
helperText: getErrorMsg(meta),
};
};
+
+// Attempts to match a manually typed value label with a value ID, when the user
+// doesn't select the value from the suggestions list.
+export const handleBlur = (
+ fieldName: string,
+ formName: string,
+ { dispatch }: WrappedFieldMetaProps,
+ { onBlur, value }: WrappedFieldInputProps,
+ fieldValue: string) =>
+ () => {
+ dispatch(change(formName, fieldName, fieldValue));
+ onBlur(value);
+ };
+
+// When selecting a property value, save its ID for later usage.
+export const handleSelect = (
+ fieldName: string,
+ formName: string,
+ { onChange }: WrappedFieldInputProps,
+ { dispatch }: WrappedFieldMetaProps ) =>
+ (item:PropFieldSuggestion) => {
+ if (item) {
+ onChange(item.label);
+ dispatch(change(formName, fieldName, item.id));
+ }
+ };
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-import { change, WrappedFieldProps, WrappedFieldMetaProps, WrappedFieldInputProps,
- Field, FormName } 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, buildProps } from '~/views-components/resource-properties-form/property-field-common';
import { TAG_KEY_VALIDATION } from '~/validators/validators';
import { escapeRegExp } from '~/common/regexp.ts';
<Autocomplete
label='Key'
suggestions={getSuggestions(props.input.value, vocabulary)}
- onSelect={handleSelect(data.form, props.input, props.meta)}
+ onSelect={handleSelect(PROPERTY_KEY_FIELD_ID, data.form, props.input, props.meta)}
+ onBlur={handleBlur(PROPERTY_KEY_FIELD_ID, data.form, props.meta, props.input, getTagKeyID(props.input.value, vocabulary))}
{...buildProps(props)}
- onBlur={handleBlur(data.form, props.meta, props.input, 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 = (
- formName: string,
- { dispatch }: WrappedFieldMetaProps,
- { onBlur, value }: WrappedFieldInputProps,
- vocabulary: Vocabulary) =>
- () => {
- dispatch(change(formName, PROPERTY_KEY_FIELD_ID, getTagKeyID(value, vocabulary)));
- onBlur(value);
- };
-
-// When selecting a property key, save its ID for later usage.
-const handleSelect = (
- formName: string,
- { onChange }: WrappedFieldInputProps,
- { dispatch }: WrappedFieldMetaProps) => {
- return (item:PropFieldSuggestion) => {
- onChange(item.label);
- dispatch(change(formName, PROPERTY_KEY_FIELD_ID, item.id));
- };
-};
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-import { change, WrappedFieldProps, WrappedFieldMetaProps, WrappedFieldInputProps,
- Field, formValues, FormName } from 'redux-form';
+import { WrappedFieldProps, Field, formValues, FormName } from 'redux-form';
import { compose } from 'redux';
import { Autocomplete } from '~/components/autocomplete/autocomplete';
-import { Vocabulary, getTagValueID, isStrictTag, getTagValues, PropFieldSuggestion } from '~/models/vocabulary';
+import { Vocabulary, isStrictTag, getTagValues, getTagValueID } from '~/models/vocabulary';
import { PROPERTY_KEY_FIELD_ID } from '~/views-components/resource-properties-form/property-key-field';
-import { VocabularyProp, connectVocabulary, buildProps } from '~/views-components/resource-properties-form/property-field-common';
+import { handleSelect, handleBlur, VocabularyProp, connectVocabulary, buildProps } from '~/views-components/resource-properties-form/property-field-common';
import { TAG_VALUE_VALIDATION } from '~/validators/validators';
import { escapeRegExp } from '~/common/regexp.ts';
<Autocomplete
label='Value'
suggestions={getSuggestions(props.input.value, propertyKey, vocabulary)}
- onSelect={handleSelect(data.form, props.input, props.meta)}
+ onSelect={handleSelect(PROPERTY_VALUE_FIELD_ID, data.form, props.input, props.meta)}
+ onBlur={handleBlur(PROPERTY_VALUE_FIELD_ID, data.form, props.meta, props.input, getTagValueID(propertyKey, props.input.value, vocabulary))}
{...buildProps(props)}
- onBlur={handleBlur(data.form, props.meta, props.input, vocabulary, propertyKey)}
/>
)}/>;
return getTagValues(tagName, vocabulary).filter(v => re.test(v.label) && v.label !== value);
};
-// Attempts to match a manually typed value label with a value ID, when the user
-// doesn't select the value from the suggestions list.
-const handleBlur = (
- formName: string,
- { dispatch }: WrappedFieldMetaProps,
- { onBlur, value }: WrappedFieldInputProps,
- vocabulary: Vocabulary,
- tagKeyID: string) =>
- () => {
- dispatch(change(formName, PROPERTY_VALUE_FIELD_ID, getTagValueID(tagKeyID, value, vocabulary)));
- onBlur(value);
- };
-
-// When selecting a property value, save its ID for later usage.
-const handleSelect = (
- formName: string,
- { onChange }: WrappedFieldInputProps,
- { dispatch }: WrappedFieldMetaProps) => {
- return (item:PropFieldSuggestion) => {
- onChange(item.label);
- dispatch(change(formName, PROPERTY_VALUE_FIELD_ID, item.id));
- };
-};