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

View File

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