fix: linkage rule enable effect in form (#1669)

This commit is contained in:
katherinehhh 2023-04-08 14:26:12 +08:00 committed by GitHub
parent 7821af4024
commit a529d9b7eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import { ConfigProvider, Spin } from 'antd';
import React, { useEffect, useMemo } from 'react'; import React, { useEffect, useMemo } from 'react';
import { useActionContext } from '..'; import { useActionContext } from '..';
import { useAttach, useComponent } from '../..'; import { useAttach, useComponent } from '../..';
import { gridRowColWrap } from '../../../schema-initializer';
import { useProps } from '../../hooks/useProps'; import { useProps } from '../../hooks/useProps';
import { linkageMergeAction } from './utils'; import { linkageMergeAction } from './utils';
@ -69,8 +70,10 @@ const WithForm = (props) => {
const { form } = props; const { form } = props;
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();
const { setFormValueChanged } = useActionContext(); const { setFormValueChanged } = useActionContext();
const linkageRules = const linkageRules = useMemo(
(getLinkageRules(fieldSchema) || fieldSchema.parent?.['x-linkage-rules'])?.filter((k) => !k.disabled) || []; () => (getLinkageRules(fieldSchema) || fieldSchema.parent?.['x-linkage-rules'])?.filter((k) => !k.disabled) || [],
[fieldSchema.properties?.grid?.['x-linkage-rules']],
);
useEffect(() => { useEffect(() => {
const id = uid(); const id = uid();
form.addEffects(id, () => { form.addEffects(id, () => {
@ -114,7 +117,6 @@ const WithForm = (props) => {
}; };
}, []); }, []);
useEffect(() => { useEffect(() => {
if (linkageRules.length > 0) {
const id = uid(); const id = uid();
const linkagefields = []; const linkagefields = [];
const formGraph = form.getFormGraph(); const formGraph = form.getFormGraph();
@ -143,7 +145,6 @@ const WithForm = (props) => {
form.clearFormGraph(); form.clearFormGraph();
form.setFormGraph(formGraph); form.setFormGraph(formGraph);
}; };
}
}, [linkageRules]); }, [linkageRules]);
return fieldSchema['x-decorator'] === 'Form' ? <FormDecorator {...props} /> : <FormComponent {...props} />; return fieldSchema['x-decorator'] === 'Form' ? <FormDecorator {...props} /> : <FormComponent {...props} />;
}; };