feat: form item designer form switch issue (#656)

This commit is contained in:
金昶 2022-07-21 22:43:05 +08:00 committed by GitHub
parent 22a4f0127d
commit 341114ffd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -292,8 +292,22 @@ const removeSchema = (schema, cb) => {
return cb(schema);
};
const recursiveParent = (schema: Schema) => {
if (!schema.parent) return null;
if (schema.parent['x-initializer']) return schema.parent;
return recursiveParent(schema.parent);
}
export const useCurrentSchema = (action: string, key: string, find = findSchema, rm = removeSchema) => {
const fieldSchema = useFieldSchema();
let fieldSchema = useFieldSchema();
if (!fieldSchema?.['x-initializer']) {
const recursiveInitializerSchema = recursiveParent(fieldSchema);
if (recursiveInitializerSchema) {
fieldSchema = recursiveInitializerSchema;
}
}
const { remove } = useDesignable();
const schema = find(fieldSchema, key, action);
return {