fix(client): clone schema before insert

This commit is contained in:
chenos 2022-05-25 10:31:17 +08:00
parent cfd2b50a91
commit c7d7a26938
2 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,7 @@
import { ISchema, Schema, SchemaOptionsContext, useField, useFieldSchema } from '@formily/react';
import { uid } from '@formily/shared';
import { message } from 'antd';
import cloneDeep from 'lodash/cloneDeep';
import get from 'lodash/get';
import set from 'lodash/set';
import React, { useContext } from 'react';
@ -325,6 +326,8 @@ export class Designable {
if (removeParentsIfNoChildren) {
opts['removed'] = this.recursiveRemoveIfNoChildren(schema.parent, { breakRemoveOn });
}
} else if (schema) {
schema = cloneDeep(schema);
}
const properties = {};
let start = false;
@ -382,6 +385,8 @@ export class Designable {
if (removeParentsIfNoChildren) {
opts['removed'] = this.recursiveRemoveIfNoChildren(schema.parent, { breakRemoveOn });
}
} else if (schema) {
schema = cloneDeep(schema);
}
const properties = {};
let order = 1;
@ -430,6 +435,8 @@ export class Designable {
if (removeParentsIfNoChildren) {
opts['removed'] = this.recursiveRemoveIfNoChildren(schema.parent, { breakRemoveOn });
}
} else if (schema) {
schema = cloneDeep(schema);
}
this.prepareProperty(schema);
const wrapped = wrap(schema);
@ -466,6 +473,8 @@ export class Designable {
opts['removed'] = this.recursiveRemoveIfNoChildren(schema.parent, { breakRemoveOn });
}
schema.parent = null;
} else if (schema) {
schema = cloneDeep(schema);
}
let order = 0;

View File

@ -486,6 +486,7 @@ SchemaSettings.ActionModalItem = React.memo((props: any) => {
const cancelHandler = () => {
setVisible(false);
};
const submitHandler = () => {
onSubmit?.(cloneDeep(form.values));
setVisible(false);
@ -504,12 +505,7 @@ SchemaSettings.ActionModalItem = React.memo((props: any) => {
};
return (
<div
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
>
<>
<SchemaSettings.Item {...others} onClick={openAssignedFieldValueHandler}>
{props.children || props.title}
</SchemaSettings.Item>
@ -538,7 +534,7 @@ SchemaSettings.ActionModalItem = React.memo((props: any) => {
</FormLayout>
</FormProvider>
</Modal>
</div>
</>
);
});