fix: 修复弹窗修改无法删除属性的问题 (#10102)

This commit is contained in:
liaoxuezhi 2024-04-24 21:42:04 +08:00 committed by GitHub
parent 6a049c5066
commit 759d4534d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 147 additions and 83 deletions

View File

@ -553,18 +553,27 @@ export const MainStore = types
}
const isSubEditor = self.isSubEditor;
const isHiddenProps = getEnv(self).isHiddenProps;
return JSONPipeOut(
JSONGetById(self.schema, self.activeId),
getEnv(self).isHiddenProps ||
((key, props) =>
// 如果是子弹窗,不显示 definitions要是通过代码模式改了就麻烦了
(isSubEditor && key === 'definitions') ||
(key, props) => {
if (isSubEditor && key === 'definitions') {
return true;
}
if (typeof isHiddenProps === 'function') {
return isHiddenProps(key, props);
}
return (
(key.substring(0, 2) === '$$' &&
key !== '$$comments' &&
key !== '$$commonSchema') ||
typeof props === 'function' || // pipeIn 和 pipeOut
key.substring(0, 2) === '__')
key.substring(0, 2) === '__'
);
}
);
},
@ -1812,7 +1821,7 @@ export const MainStore = types
? 'drawer'
: 'dialog';
schema = JSONUpdate(schema, id, modal);
schema = JSONUpdate(schema, id, modal, true);
// 如果编辑的是公共弹窗
if (!parent.actionType) {
@ -1829,25 +1838,35 @@ export const MainStore = types
modalKey &&
newHostKey !== (value === 'drawer' ? 'drawer' : 'dialog')
) {
schema = JSONUpdate(schema, host.$$id, {
actionType: (modal as any).actionType || modal.type,
args: undefined,
dialog: undefined,
drawer: undefined,
[newHostKey]: host[value === 'drawer' ? 'drawer' : 'dialog']
});
schema = JSONUpdate(
schema,
host.$$id,
{
actionType: (modal as any).actionType || modal.type,
args: undefined,
dialog: undefined,
drawer: undefined,
[newHostKey]: host[value === 'drawer' ? 'drawer' : 'dialog']
},
true
);
}
return value;
});
} else {
// 内嵌弹窗只用改自己就行了
schema = JSONUpdate(schema, parent.$$id, {
actionType: (modal as any).actionType || modal.type,
args: undefined,
dialog: undefined,
drawer: undefined,
[newHostKey]: modal
});
schema = JSONUpdate(
schema,
parent.$$id,
{
actionType: (modal as any).actionType || modal.type,
args: undefined,
dialog: undefined,
drawer: undefined,
[newHostKey]: modal
},
true
);
}
// 如果弹窗里面又弹窗指向自己,那么也要更新
@ -1860,16 +1879,26 @@ export const MainStore = types
if (refIds.length) {
let refKey = '';
[schema, refKey] = addModal(schema, modal);
schema = JSONUpdate(schema, parent.$$id, {
[newHostKey]: JSONPipeIn({
$ref: refKey
})
});
schema = JSONUpdate(
schema,
parent.$$id,
{
[newHostKey]: JSONPipeIn({
$ref: refKey
})
},
true
);
refIds.forEach(refId => {
schema = JSONUpdate(schema, refId, {
$ref: refKey,
$$originId: undefined
});
schema = JSONUpdate(
schema,
refId,
{
$ref: refKey,
$$originId: undefined
},
true
);
});
}

View File

@ -1519,7 +1519,7 @@ export function mergeDefinitions(
// 当前更新弹窗里面用到了需要转成 ref
if (refs.includes(key)) {
if (schema.$$id === $$originId) {
schema = JSONUpdate(schema, $$originId, JSONPipeIn(def));
schema = JSONUpdate(schema, $$originId, JSONPipeIn(def), true);
return;
}
@ -1528,17 +1528,22 @@ export function mergeDefinitions(
}
const modalType = def.type === 'drawer' ? 'drawer' : 'dialog';
schema = JSONUpdate(schema, parent.$$id, {
...parent,
__actionModals: undefined,
args: undefined,
dialog: undefined,
drawer: undefined,
actionType: def.actionType ?? modalType,
[modalType]: JSONPipeIn({
$ref: key
})
});
schema = JSONUpdate(
schema,
parent.$$id,
{
...parent,
__actionModals: undefined,
args: undefined,
dialog: undefined,
drawer: undefined,
actionType: def.actionType ?? modalType,
[modalType]: JSONPipeIn({
$ref: key
})
},
true
);
schema.definitions[key] = JSONPipeIn(def);
} else if (parent) {
// 没用到,可能修改了弹窗的内容为引用其他弹窗,同样需要更新,但是不会提取为 definitions
@ -1550,15 +1555,20 @@ export function mergeDefinitions(
if (changes) {
const newModal = patchDiff(origin, changes);
delete newModal.$$originId;
schema = JSONUpdate(schema, parent.$$id, {
...parent,
__actionModals: undefined,
args: undefined,
dialog: undefined,
drawer: undefined,
actionType: def.actionType ?? modalType,
[modalType]: newModal
});
schema = JSONUpdate(
schema,
parent.$$id,
{
...parent,
__actionModals: undefined,
args: undefined,
dialog: undefined,
drawer: undefined,
actionType: def.actionType ?? modalType,
[modalType]: newModal
},
true
);
}
}
} else if (refs.includes(key)) {

View File

@ -132,32 +132,42 @@ function DialogActionPanel({
const newModal = patchDiff(origin, changes);
delete newModal.$$originId;
delete newModal.$$ref;
schema = JSONUpdate(schema, parent.$$id, {
...parent,
__actionModals: undefined,
args: undefined,
dialog: undefined,
drawer: undefined,
actionType: def.actionType ?? modalType,
[modalType]: newModal
});
schema = JSONUpdate(
schema,
parent.$$id,
{
...parent,
__actionModals: undefined,
args: undefined,
dialog: undefined,
drawer: undefined,
actionType: def.actionType ?? modalType,
[modalType]: newModal
},
true
);
}
// 不要写下面的 defintions 了
return;
} else {
const modalType = def.type === 'drawer' ? 'drawer' : 'dialog';
schema = JSONUpdate(schema, parent.$$id, {
...parent,
__actionModals: undefined,
args: undefined,
dialog: undefined,
drawer: undefined,
actionType: def.actionType ?? modalType,
[modalType]: JSONPipeIn({
$ref: modal.$$ref!
})
});
schema = JSONUpdate(
schema,
parent.$$id,
{
...parent,
__actionModals: undefined,
args: undefined,
dialog: undefined,
drawer: undefined,
actionType: def.actionType ?? modalType,
[modalType]: JSONPipeIn({
$ref: modal.$$ref!
})
},
true
);
}
}
schema.definitions[modal.$$ref!] = JSONPipeIn(def);
@ -261,10 +271,15 @@ function DialogActionPanel({
const definition = schema.definitions[key];
const exits = JSONGetById(definition, id);
if (exits) {
schema.definitions[key] = JSONUpdate(schema.definitions[key], id, {
...schema,
definitions: undefined
});
schema.definitions[key] = JSONUpdate(
schema.definitions[key],
id,
{
...schema,
definitions: undefined
},
true
);
}
});
}
@ -280,16 +295,26 @@ function DialogActionPanel({
if (refIds.length) {
let refKey = '';
[schema, refKey] = addModal(schema, currentModal.modal);
schema = JSONUpdate(schema, actionSchema.$$id, {
[modalType]: JSONPipeIn({
$ref: refKey
})
});
schema = JSONUpdate(
schema,
actionSchema.$$id,
{
[modalType]: JSONPipeIn({
$ref: refKey
})
},
true
);
refIds.forEach(refId => {
schema = JSONUpdate(schema, refId, {
$ref: refKey,
$$originId: undefined
});
schema = JSONUpdate(
schema,
refId,
{
$ref: refKey,
$$originId: undefined
},
true
);
});
}