From 6a7e7b35942924c1ab18eba8286794bdde9a242c Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Mon, 16 Oct 2023 10:31:10 +0800 Subject: [PATCH] fix: association field in assign field should set title field as collection field config (#2839) --- packages/core/client/src/collection-manager/interfaces/m2m.tsx | 3 ++- packages/core/client/src/collection-manager/interfaces/m2o.tsx | 3 ++- packages/core/client/src/collection-manager/interfaces/o2m.tsx | 3 ++- packages/core/client/src/collection-manager/interfaces/o2o.tsx | 3 ++- .../antd/association-field/AssociationSelect.tsx | 1 + .../src/schema-component/antd/association-field/hooks.ts | 1 + .../components/assigned-field/AssignedField.tsx | 2 +- 7 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/client/src/collection-manager/interfaces/m2m.tsx b/packages/core/client/src/collection-manager/interfaces/m2m.tsx index 2184c4f4e..839832418 100644 --- a/packages/core/client/src/collection-manager/interfaces/m2m.tsx +++ b/packages/core/client/src/collection-manager/interfaces/m2m.tsx @@ -47,7 +47,8 @@ export const m2m: IField = { availableTypes: ['belongsToMany'], schemaInitialize(schema: ISchema, { readPretty, block, targetCollection }) { // schema['type'] = 'array'; - if (targetCollection?.titleField && schema['x-component-props']) { + if (targetCollection?.titleField) { + schema['x-component-props'] = schema['x-component-props'] || {}; schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || { value: 'id' }; schema['x-component-props'].fieldNames.label = targetCollection.titleField; } diff --git a/packages/core/client/src/collection-manager/interfaces/m2o.tsx b/packages/core/client/src/collection-manager/interfaces/m2o.tsx index bf16abee4..f83fca161 100644 --- a/packages/core/client/src/collection-manager/interfaces/m2o.tsx +++ b/packages/core/client/src/collection-manager/interfaces/m2o.tsx @@ -46,7 +46,8 @@ export const m2o: IField = { availableTypes: ['belongsTo'], schemaInitialize(schema: ISchema, { block, readPretty, targetCollection }) { // schema['type'] = 'object'; - if (targetCollection?.titleField && schema['x-component-props']) { + if (targetCollection?.titleField) { + schema['x-component-props'] = schema['x-component-props'] || {}; schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || { value: 'id' }; schema['x-component-props'].fieldNames.label = targetCollection.titleField; } diff --git a/packages/core/client/src/collection-manager/interfaces/o2m.tsx b/packages/core/client/src/collection-manager/interfaces/o2m.tsx index 57ad67386..649870599 100644 --- a/packages/core/client/src/collection-manager/interfaces/o2m.tsx +++ b/packages/core/client/src/collection-manager/interfaces/o2m.tsx @@ -46,7 +46,8 @@ export const o2m: IField = { availableTypes: ['hasMany'], schemaInitialize(schema: ISchema, { field, block, readPretty, targetCollection }) { // schema['type'] = 'array'; - if (targetCollection?.titleField && schema['x-component-props']) { + if (targetCollection?.titleField) { + schema['x-component-props'] = schema['x-component-props'] || {}; schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || { value: 'id' }; schema['x-component-props'].fieldNames.label = targetCollection.titleField; } diff --git a/packages/core/client/src/collection-manager/interfaces/o2o.tsx b/packages/core/client/src/collection-manager/interfaces/o2o.tsx index b80307741..aeac9e807 100644 --- a/packages/core/client/src/collection-manager/interfaces/o2o.tsx +++ b/packages/core/client/src/collection-manager/interfaces/o2o.tsx @@ -400,7 +400,8 @@ export const obo: IField = { schema['x-component-props']['size'] = 'small'; } - if (targetCollection?.titleField && schema['x-component-props']) { + if (targetCollection?.titleField) { + schema['x-component-props'] = schema['x-component-props'] || {}; schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || { value: 'id' }; schema['x-component-props'].fieldNames.label = targetCollection.titleField; } diff --git a/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx b/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx index c44559e11..caa38070b 100644 --- a/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx @@ -44,6 +44,7 @@ const InternalAssociationSelect = observer((props: AssociationSelectProps) => { const { objectValue = true } = props; const field: any = useField(); const fieldSchema = useFieldSchema(); + console.log(fieldSchema); const service = useServiceOptions(props); const { options: collectionField } = useAssociationFieldContext(); const initValue = isVariable(props.value) ? undefined : props.value; diff --git a/packages/core/client/src/schema-component/antd/association-field/hooks.ts b/packages/core/client/src/schema-component/antd/association-field/hooks.ts index 2a790f0d8..24321c0be 100644 --- a/packages/core/client/src/schema-component/antd/association-field/hooks.ts +++ b/packages/core/client/src/schema-component/antd/association-field/hooks.ts @@ -50,6 +50,7 @@ export function useAssociationFieldContext() { export default function useServiceOptions(props) { const { action = 'list', service, fieldNames } = props; + console.log(fieldNames); const params = service?.params || {}; const fieldSchema = useFieldSchema(); const field = useField(); diff --git a/packages/core/client/src/schema-initializer/components/assigned-field/AssignedField.tsx b/packages/core/client/src/schema-initializer/components/assigned-field/AssignedField.tsx index d6b9f5a9e..186a6d7e1 100644 --- a/packages/core/client/src/schema-initializer/components/assigned-field/AssignedField.tsx +++ b/packages/core/client/src/schema-initializer/components/assigned-field/AssignedField.tsx @@ -134,7 +134,7 @@ export const AssignedField = (props: AssignedFieldProps) => { }, [JSON.stringify(_.omit(props, 'value'))], ); - + console.log(fieldSchema, collectionField); return (