fix(linkage-rule): linkage rule support empty condiction (#4103)

* fix: linkage rule support empty condiction

* fix: linkage rule support empty condiction
This commit is contained in:
katherinehhh 2024-04-19 17:30:04 +08:00 committed by GitHub
parent 0af40dfa3e
commit 2093bc0058
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,8 +24,10 @@ import { useTemplateBlockContext } from '../../../block-provider/TemplateBlockPr
export interface FormProps {
[key: string]: any;
}
function hasInitialValues(obj) {
return Object.values(obj).some((value) => value !== null);
function hasInitialValues(obj, rule) {
const type = Object.keys(rule.condition)[0] || '$and';
const conditions = rule.condition[type];
return Object.values(obj).some((value) => value !== null) || !conditions.length;
}
const FormComponent: React.FC<FormProps> = (props) => {
const { form, children, ...others } = props;
@ -155,7 +157,7 @@ const WithForm = (props: WithFormProps) => {
return result;
},
getSubscriber(action, field, rule, variables, localVariables),
{ fireImmediately: hasInitialValues(form.initialValues) },
{ fireImmediately: hasInitialValues(form.initialValues, rule) },
),
);
});