From c273f3308110a1fb814f3a3695d2c50efc160915 Mon Sep 17 00:00:00 2001 From: Katherine Date: Mon, 30 Sep 2024 13:00:56 +0800 Subject: [PATCH] fix: the issue of current and association collection fields affecting each other in configuration (#5343) --- .../schema-initializer/items/InitializerWithSwitch.tsx | 1 + packages/core/client/src/schema-initializer/utils.ts | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/core/client/src/schema-initializer/items/InitializerWithSwitch.tsx b/packages/core/client/src/schema-initializer/items/InitializerWithSwitch.tsx index b7fbaaac51..dead375076 100644 --- a/packages/core/client/src/schema-initializer/items/InitializerWithSwitch.tsx +++ b/packages/core/client/src/schema-initializer/items/InitializerWithSwitch.tsx @@ -20,6 +20,7 @@ export const InitializerWithSwitch = (props) => { type, item.find, passInRemove ?? item.remove, + schema?.name || item?.schema?.name, ); const { insert } = useSchemaInitializer(); return ( diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index 7311de1cb4..a1b643db34 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -751,14 +751,14 @@ export const useCustomFormItemInitializerFields = (options?: any) => { }); }; -export const findSchema = (schema: Schema, key: string, action: string) => { +export const findSchema = (schema: Schema, key: string, action: string, name?: string) => { if (!Schema.isSchemaInstance(schema)) return null; return schema.reduceProperties((buf, s) => { - if (s[key] === action) { + if (s[key] === action && (!name || s.name === name)) { return s; } if (s['x-component'] !== 'Action.Container' && !s['x-component'].includes('AssociationField')) { - const c = findSchema(s, key, action); + const c = findSchema(s, key, action, name); if (c) { return c; } @@ -780,7 +780,7 @@ const recursiveParent = (schema: Schema) => { return recursiveParent(schema.parent); }; -export const useCurrentSchema = (action: string, key: string, find = findSchema, rm = removeSchema) => { +export const useCurrentSchema = (action: string, key: string, find = findSchema, rm = removeSchema, name?: string) => { const { removeActiveFieldName } = useFormActiveFields() || {}; const { form }: { form?: Form } = useFormBlockContext(); let fieldSchema = useFieldSchema(); @@ -791,7 +791,7 @@ export const useCurrentSchema = (action: string, key: string, find = findSchema, } } const { remove } = useDesignable(); - const schema = find(fieldSchema, key, action); + const schema = find(fieldSchema, key, action, name); return { schema, exists: !!schema,