import * as React from 'react';
import { WrappedFieldProps, Field } from 'redux-form';
-import { connect } from 'react-redux';
-import { identity, memoize } from 'lodash';
-import { RootState } from '~/store/store';
-import { getVocabulary } from '~/store/vocabulary/vocabulary-selctors';
+import { memoize } from 'lodash';
import { Autocomplete } from '~/components/autocomplete/autocomplete';
import { Vocabulary } from '~/models/vocabulary';
-import { require } from '~/validators/require';
-
-interface VocabularyProp {
- vocabulary: Vocabulary;
-}
-
-const mapStateToProps = (state: RootState): VocabularyProp => ({
- vocabulary: getVocabulary(state.properties),
-});
+import { connectVocabulary, VocabularyProp, buildProps } from '~/views-components/resource-properties-form/property-field-common';
+import { TAG_KEY_VALIDATION } from '~/validators/validators';
export const PROPERTY_KEY_FIELD_NAME = 'key';
-export const PropertyKeyField = connect(mapStateToProps)(
+export const PropertyKeyField = connectVocabulary(
({ vocabulary }: VocabularyProp) =>
<Field
name={PROPERTY_KEY_FIELD_NAME}
vocabulary={vocabulary}
validate={getValidation(vocabulary)} />);
-const PropertyKeyInput = ({ input, meta, vocabulary }: WrappedFieldProps & VocabularyProp) =>
+export const PropertyKeyInput = ({ vocabulary, ...props }: WrappedFieldProps & VocabularyProp) =>
<Autocomplete
- value={input.value}
- onChange={input.onChange}
label='Key'
- suggestions={getSuggestions(input.value, vocabulary)}
- items={ITEMS_PLACEHOLDER}
- onSelect={input.onChange}
- renderSuggestion={identity}
- error={meta.invalid}
- helperText={meta.error}
+ suggestions={getSuggestions(props.input.value, vocabulary)}
+ {...buildProps(props)}
/>;
const getValidation = memoize(
(vocabulary: Vocabulary) =>
vocabulary.strict
- ? [require, matchTags(vocabulary)]
- : [require]);
+ ? [...TAG_KEY_VALIDATION, matchTags(vocabulary)]
+ : TAG_KEY_VALIDATION);
const matchTags = (vocabulary: Vocabulary) =>
(value: string) =>
const getTagsList = ({ tags }: Vocabulary) =>
Object.keys(tags);
-
-const ITEMS_PLACEHOLDER: string[] = [];