Skip to content

Commit

Permalink
fix: the issue of current and association collection fields affecting…
Browse files Browse the repository at this point in the history
… each other in configuration (nocobase#5343)
  • Loading branch information
katherinehhh authored Sep 30, 2024
1 parent 570eff0 commit c273f33
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const InitializerWithSwitch = (props) => {
type,
item.find,
passInRemove ?? item.remove,
schema?.name || item?.schema?.name,
);
const { insert } = useSchemaInitializer();
return (
Expand Down
10 changes: 5 additions & 5 deletions packages/core/client/src/schema-initializer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand All @@ -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,
Expand Down

0 comments on commit c273f33

Please sign in to comment.