fix(defaultValue): should not use defaultValue in filter blocks (#3472)

This commit is contained in:
Zeke Zhang 2024-01-31 13:20:15 +08:00 committed by GitHub
parent 89bf75871f
commit e7a28035c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -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 (
<DatePickerProvider value={{ utc: false }}>
<FormBlockProvider name="filter-form" {...props}></FormBlockProvider>
<DefaultValueProvider isAllowToSetDefaultValue={() => false}>
<FormBlockProvider name="filter-form" {...props}></FormBlockProvider>
</DefaultValueProvider>
</DatePickerProvider>
);
};

View File

@ -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<Field>();
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'])) {