Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>
() =>
onBlur(value);
-export const handleSelect = ({ onChange }: WrappedFieldInputProps) => {
- return (item:PropFieldSuggestion) => {
- onChange(item.label);
- };
-};
-
export const buildProps = ({ input, meta }: WrappedFieldProps) => {
return {
value: input.value,
onChange: input.onChange,
onBlur: handleBlur(input),
items: ITEMS_PLACEHOLDER,
- onSelect: handleSelect(input),
renderSuggestion: (item:PropFieldSuggestion) => item.label,
error: hasError(meta),
helperText: getErrorMsg(meta),
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-import { WrappedFieldProps, Field } from 'redux-form';
+import { change, WrappedFieldProps, WrappedFieldMetaProps, WrappedFieldInputProps, Field } from 'redux-form';
import { memoize } from 'lodash';
import { Autocomplete } from '~/components/autocomplete/autocomplete';
import { Vocabulary } from '~/models/vocabulary';
-import { connectVocabulary, VocabularyProp, buildProps } from '~/views-components/resource-properties-form/property-field-common';
+import { connectVocabulary, VocabularyProp, buildProps, PropFieldSuggestion } 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';
export const PROPERTY_KEY_FIELD_NAME = 'key';
+export const PROPERTY_KEY_FIELD_ID = 'keyID';
export const PropertyKeyField = connectVocabulary(
({ vocabulary }: VocabularyProp) =>
- <Field
- name={PROPERTY_KEY_FIELD_NAME}
- component={PropertyKeyInput}
- vocabulary={vocabulary}
- validate={getValidation(vocabulary)} />);
+ <div>
+ <Field
+ name={PROPERTY_KEY_FIELD_NAME}
+ component={PropertyKeyInput}
+ vocabulary={vocabulary}
+ validate={getValidation(vocabulary)} />
+ <Field
+ name={PROPERTY_KEY_FIELD_ID}
+ type='hidden'
+ component='input' />
+ </div>
+);
export const PropertyKeyInput = ({ vocabulary, ...props }: WrappedFieldProps & VocabularyProp) =>
<Autocomplete
label='Key'
suggestions={getSuggestions(props.input.value, vocabulary)}
+ onSelect={handleSelect(props.input, props.meta)}
{...buildProps(props)}
/>;
: [];
return ret;
};
+
+const handleSelect = (
+ { onChange }: WrappedFieldInputProps,
+ { dispatch }: WrappedFieldMetaProps) => {
+ return (item:PropFieldSuggestion) => {
+ onChange(item.label);
+ dispatch(change(COLLECTION_TAG_FORM_NAME, PROPERTY_KEY_FIELD_ID, item.id));
+ };
+};
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-import { WrappedFieldProps, Field, formValues } from 'redux-form';
+import { change, WrappedFieldProps, WrappedFieldMetaProps, WrappedFieldInputProps, Field, formValues } from 'redux-form';
import { compose } from 'redux';
import { Autocomplete } from '~/components/autocomplete/autocomplete';
import { Vocabulary } from '~/models/vocabulary';
import { PROPERTY_KEY_FIELD_NAME } from '~/views-components/resource-properties-form/property-key-field';
-import { VocabularyProp, connectVocabulary, buildProps } from '~/views-components/resource-properties-form/property-field-common';
+import { VocabularyProp, connectVocabulary, buildProps, PropFieldSuggestion } from '~/views-components/resource-properties-form/property-field-common';
import { TAG_VALUE_VALIDATION } from '~/validators/validators';
+import { COLLECTION_TAG_FORM_NAME } from '~/store/collection-panel/collection-panel-action';
interface PropertyKeyProp {
propertyKey: string;
export type PropertyValueFieldProps = VocabularyProp & PropertyKeyProp;
export const PROPERTY_VALUE_FIELD_NAME = 'value';
+export const PROPERTY_VALUE_FIELD_ID = 'valueID';
export const PropertyValueField = compose(
connectVocabulary,
formValues({ propertyKey: PROPERTY_KEY_FIELD_NAME })
)(
(props: PropertyValueFieldProps) =>
- <Field
- name={PROPERTY_VALUE_FIELD_NAME}
- component={PropertyValueInput}
- validate={getValidation(props)}
- {...props} />);
+ <div>
+ <Field
+ name={PROPERTY_VALUE_FIELD_NAME}
+ component={PropertyValueInput}
+ validate={getValidation(props)}
+ {...props} />
+ <Field
+ name={PROPERTY_VALUE_FIELD_ID}
+ type='hidden'
+ component='input' />
+ </div>
+);
export const PropertyValueInput = ({ vocabulary, propertyKey, ...props }: WrappedFieldProps & PropertyValueFieldProps) =>
<Autocomplete
label='Value'
suggestions={getSuggestions(props.input.value, propertyKey, vocabulary)}
+ onSelect={handleSelect(props.input, props.meta)}
{...buildProps(props)}
/>;
: [];
return ret;
};
+
+const handleSelect = (
+ { onChange }: WrappedFieldInputProps,
+ { dispatch }: WrappedFieldMetaProps) => {
+ return (item:PropFieldSuggestion) => {
+ onChange(item.label);
+ dispatch(change(COLLECTION_TAG_FORM_NAME, PROPERTY_VALUE_FIELD_ID, item.id));
+ };
+};
import * as React from 'react';
import { InjectedFormProps } from 'redux-form';
import { Grid, withStyles, WithStyles } from '@material-ui/core';
-import { PropertyKeyField, PROPERTY_KEY_FIELD_NAME } from './property-key-field';
-import { PropertyValueField, PROPERTY_VALUE_FIELD_NAME } from './property-value-field';
+import { PropertyKeyField, PROPERTY_KEY_FIELD_NAME, PROPERTY_KEY_FIELD_ID } from './property-key-field';
+import { PropertyValueField, PROPERTY_VALUE_FIELD_NAME, PROPERTY_VALUE_FIELD_ID } from './property-value-field';
import { ProgressButton } from '~/components/progress-button/progress-button';
import { GridClassKey } from '@material-ui/core/Grid';
export interface ResourcePropertiesFormData {
[PROPERTY_KEY_FIELD_NAME]: string;
+ [PROPERTY_KEY_FIELD_ID]: string;
[PROPERTY_VALUE_FIELD_NAME]: string;
+ [PROPERTY_VALUE_FIELD_ID]: string;
}
export type ResourcePropertiesFormProps = InjectedFormProps<ResourcePropertiesFormData> & WithStyles<GridClassKey>;
export const CollectionTagForm = reduxForm<ResourcePropertiesFormData>({
form: COLLECTION_TAG_FORM_NAME,
onSubmit: (data, dispatch) => {
+ console.log('FORM SUBMIT: ', data);
dispatch<any>(createCollectionTag(data));
dispatch(reset(COLLECTION_TAG_FORM_NAME));
}