From e7a28035c2ea85f7a6df53fbcc31e0f74979ecce Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Wed, 31 Jan 2024 13:20:15 +0800 Subject: [PATCH] fix(defaultValue): should not use defaultValue in filter blocks (#3472) --- .../client/src/block-provider/FilterFormBlockProvider.tsx | 7 ++++--- .../core/client/src/collection-manager/CollectionField.tsx | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/client/src/block-provider/FilterFormBlockProvider.tsx b/packages/core/client/src/block-provider/FilterFormBlockProvider.tsx index 897d76f1d..850c04e7a 100644 --- a/packages/core/client/src/block-provider/FilterFormBlockProvider.tsx +++ b/packages/core/client/src/block-provider/FilterFormBlockProvider.tsx @@ -1,13 +1,14 @@ import React from 'react'; import { DatePickerProvider } from '../schema-component'; +import { DefaultValueProvider } from '../schema-settings'; import { FormBlockProvider } from './FormBlockProvider'; export const FilterFormBlockProvider = (props) => { - const { collection, resource } = props; - return ( - + false}> + + ); }; diff --git a/packages/core/client/src/collection-manager/CollectionField.tsx b/packages/core/client/src/collection-manager/CollectionField.tsx index cb91c07ec..16108e70f 100644 --- a/packages/core/client/src/collection-manager/CollectionField.tsx +++ b/packages/core/client/src/collection-manager/CollectionField.tsx @@ -5,6 +5,7 @@ import { concat } from 'lodash'; import React, { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useActionContext, useCompile, useComponent, useFormBlockContext, useRecord } from '..'; +import useIsAllowToSetDefaultValue from '../schema-settings/hooks/useIsAllowToSetDefaultValue'; import { CollectionFieldProvider } from './CollectionFieldProvider'; import { useCollectionField } from './hooks'; @@ -19,6 +20,7 @@ const InternalField: React.FC = (props: Props) => { const field = useField(); const fieldSchema = useFieldSchema(); const { uiSchema, defaultValue } = useCollectionField(); + const { isAllowToSetDefaultValue } = useIsAllowToSetDefaultValue(); const Component = useComponent(component || uiSchema?.['x-component'] || 'Input'); const compile = useCompile(); const setFieldProps = (key, value) => { @@ -46,7 +48,7 @@ const InternalField: React.FC = (props: Props) => { setFieldProps('title', uiSchema.title); setFieldProps('description', uiSchema.description); if (ctx?.form) { - const defaultVal = fieldSchema.default || defaultValue; + const defaultVal = isAllowToSetDefaultValue() ? fieldSchema.default || defaultValue : undefined; defaultVal !== null && defaultVal !== undefined && setFieldProps('initialValue', defaultVal); } if (!field.validator && (uiSchema['x-validator'] || fieldSchema['x-validator'])) {