1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { connect } from 'react-redux';
6 import { WrappedFieldMetaProps, WrappedFieldInputProps, WrappedFieldProps } from 'redux-form';
7 import { identity } from 'lodash';
8 import { Vocabulary } from '~/models/vocabulary';
9 import { RootState } from '~/store/store';
10 import { getVocabulary } from '~/store/vocabulary/vocabulary-selctors';
12 export interface VocabularyProp {
13 vocabulary: Vocabulary;
16 export const mapStateToProps = (state: RootState): VocabularyProp => ({
17 vocabulary: getVocabulary(state.properties),
20 export const connectVocabulary = connect(mapStateToProps);
22 export const ITEMS_PLACEHOLDER: string[] = [];
24 export const hasError = ({ touched, invalid }: WrappedFieldMetaProps) =>
27 export const getErrorMsg = (meta: WrappedFieldMetaProps) =>
32 export const handleBlur = ({ onBlur, value }: WrappedFieldInputProps) =>
36 export const buildProps = ({ input, meta }: WrappedFieldProps) => ({
38 onChange: input.onChange,
39 onBlur: handleBlur(input),
40 items: ITEMS_PLACEHOLDER,
41 onSelect: input.onChange,
42 renderSuggestion: identity,
43 error: hasError(meta),
44 helperText: getErrorMsg(meta),