fix: 优化schemaForm onChange 解决弹窗中弹窗编辑报错问题 (#10011)

This commit is contained in:
liaoxuezhi 2024-04-12 14:53:44 +08:00 committed by GitHub
parent fd3f14926e
commit f8df71ce8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -101,8 +101,6 @@ export function SchemaFrom({
return schema; return schema;
}, [body, controls, submitOnChange]); }, [body, controls, submitOnChange]);
value = value || {};
const finalValue = pipeIn ? pipeIn(value) : value;
const themeConfig = React.useMemo(() => getThemeConfig(), []); const themeConfig = React.useMemo(() => getThemeConfig(), []);
const submitSubscribers = React.useRef<Array<Function>>([]); const submitSubscribers = React.useRef<Array<Function>>([]);
const subscribeSubmit = React.useCallback( const subscribeSubmit = React.useCallback(
@ -131,19 +129,31 @@ export function SchemaFrom({
[] []
); );
const data = React.useMemo(() => {
value = value || {};
const finalValue = pipeIn ? pipeIn(value) : value;
return createObjectFromChain([ctx, themeConfig, finalValue]);
}, [value, themeConfig, ctx]);
return render( return render(
schema, schema,
{ {
onFinished: async (newValue: any) => { onFinished: async (newValue: any) => {
newValue = pipeOut ? await pipeOut(newValue, value) : newValue; newValue = pipeOut ? await pipeOut(newValue, value) : newValue;
const diffValue = diff(value, newValue); const diffValue = diff(value, newValue);
// 没有变化时不触发onChange
if (!diffValue) {
return;
}
onChange(newValue, diffValue, (schema, value, id, diff) => { onChange(newValue, diffValue, (schema, value, id, diff) => {
return submitSubscribers.current.reduce((schema, fn) => { return submitSubscribers.current.reduce((schema, fn) => {
return fn(schema, value, id, diff); return fn(schema, value, id, diff);
}, schema); }, schema);
}); });
}, },
data: createObjectFromChain([ctx, themeConfig, finalValue]), data: data,
node: node, node: node,
manager: manager, manager: manager,
popOverContainer, popOverContainer,