15069: Adds optional validation disabling to property fields components.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 18 Nov 2019 12:46:01 +0000 (09:46 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Tue, 19 Nov 2019 16:14:53 +0000 (13:14 -0300)
Also, use these components with validation disabled on the advanced search UI.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

src/views-components/form-fields/search-bar-form-fields.tsx
src/views-components/resource-properties-form/property-key-field.tsx
src/views-components/resource-properties-form/property-value-field.tsx

index 8de48ea744a8494ae2575a5ee51358a0c591902f..4c8da3ae3755428756616866c6c34487562987fe 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { Field, WrappedFieldProps, FieldArray, formValues } from 'redux-form';
+import { Field, WrappedFieldProps, FieldArray } from 'redux-form';
 import { TextField, DateTextField } from "~/components/text-field/text-field";
 import { CheckboxField } from '~/components/checkbox-field/checkbox-field';
 import { NativeSelectField } from '~/components/select-field/select-field';
@@ -13,10 +13,8 @@ import { SEARCH_BAR_ADVANCE_FORM_PICKER_ID } from '~/store/search-bar/search-bar
 import { SearchBarAdvancedPropertiesView } from '~/views-components/search-bar/search-bar-advanced-properties-view';
 import { TreeItem } from "~/components/tree/tree";
 import { ProjectsTreePickerItem } from "~/views-components/projects-tree-picker/generic-projects-tree-picker";
-import { PropertyKeyInput } from '~/views-components/resource-properties-form/property-key-field';
-import { PropertyValueInput, PropertyValueFieldProps } from '~/views-components/resource-properties-form/property-value-field';
-import { VocabularyProp, connectVocabulary } from '~/views-components/resource-properties-form/property-field-common';
-import { compose } from 'redux';
+import { PropertyKeyField, } from '~/views-components/resource-properties-form/property-key-field';
+import { PropertyValueField } from '~/views-components/resource-properties-form/property-value-field';
 import { connect } from "react-redux";
 import { RootState } from "~/store/store";
 
@@ -88,22 +86,11 @@ export const SearchBarPropertiesField = () =>
         name="properties"
         component={SearchBarAdvancedPropertiesView} />;
 
-export const SearchBarKeyField = connectVocabulary(
-    ({ vocabulary }: VocabularyProp) =>
-        <Field
-            name='key'
-            component={PropertyKeyInput}
-            vocabulary={vocabulary} />);
+export const SearchBarKeyField = () =>
+    <PropertyKeyField skipValidation={true} />;
 
-export const SearchBarValueField = compose(
-    connectVocabulary,
-    formValues({ propertyKey: 'key' })
-)(
-    (props: PropertyValueFieldProps) =>
-        <Field
-            name='value'
-            component={PropertyValueInput}
-            {...props} />);
+export const SearchBarValueField = () =>
+    <PropertyValueField skipValidation={true} />;
 
 export const SearchBarSaveSearchField = () =>
     <Field
index 89a03946d594d49ced6a567b1af0edbe9b50ae55..e03e9be5a638886fd42eaf492d1803b8ac7d70d7 100644 (file)
@@ -14,16 +14,20 @@ import { escapeRegExp } from '~/common/regexp.ts';
 export const PROPERTY_KEY_FIELD_NAME = 'key';
 export const PROPERTY_KEY_FIELD_ID = 'keyID';
 
+interface PropertyKeyFieldProps {
+    skipValidation?: boolean;
+}
+
 export const PropertyKeyField = connectVocabulary(
-    ({ vocabulary }: VocabularyProp) =>
+    ({ vocabulary, skipValidation }: VocabularyProp & PropertyKeyFieldProps) =>
         <Field
             name={PROPERTY_KEY_FIELD_NAME}
             component={PropertyKeyInput}
             vocabulary={vocabulary}
-            validate={getValidation(vocabulary)} />
+            validate={skipValidation ? undefined : getValidation(vocabulary)} />
 );
 
-export const PropertyKeyInput = ({ vocabulary, ...props }: WrappedFieldProps & VocabularyProp) =>
+const PropertyKeyInput = ({ vocabulary, ...props }: WrappedFieldProps & VocabularyProp) =>
     <FormName children={data => (
         <Autocomplete
             label='Key'
index 4df44619a635ad4b56c24e11dca1f9d332f58b96..6a40f877a58ee44e0801c4a3b83b91ff5e93b73f 100644 (file)
@@ -16,24 +16,30 @@ interface PropertyKeyProp {
     propertyKey: string;
 }
 
-export type PropertyValueFieldProps = VocabularyProp & PropertyKeyProp;
+interface ValidationProp {
+    skipValidation?: boolean;
+}
+
+type PropertyValueFieldProps = VocabularyProp & PropertyKeyProp;
 
 export const PROPERTY_VALUE_FIELD_NAME = 'value';
 export const PROPERTY_VALUE_FIELD_ID = 'valueID';
 
-export const PropertyValueField = compose(
+const connectVocabularyAndPropertyKey = compose<any>(
     connectVocabulary,
-    formValues({ propertyKey: PROPERTY_KEY_FIELD_ID })
-)(
-    (props: PropertyValueFieldProps) =>
+    formValues({ propertyKey: PROPERTY_KEY_FIELD_ID }),
+);
+
+export const PropertyValueField = connectVocabularyAndPropertyKey(
+    ({skipValidation, ...props}: PropertyValueFieldProps & ValidationProp) =>
         <Field
             name={PROPERTY_VALUE_FIELD_NAME}
             component={PropertyValueInput}
-            validate={getValidation(props)}
+            validate={skipValidation ? undefined : getValidation(props)}
             {...props} />
 );
 
-export const PropertyValueInput = ({ vocabulary, propertyKey, ...props }: WrappedFieldProps & PropertyValueFieldProps) =>
+const PropertyValueInput = ({ vocabulary, propertyKey, ...props }: WrappedFieldProps & PropertyValueFieldProps) =>
     <FormName children={data => (
         <Autocomplete
             label='Value'