// 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';
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";
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
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'
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'