From 12a2f7c1bbdff9df9d448ee8b89b9180b814cd17 Mon Sep 17 00:00:00 2001 From: "bai.zixv" Date: Thu, 9 May 2024 22:41:44 +0800 Subject: [PATCH] fix: plugin-mobile-client, support set data scope (#956) Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/956 Reviewed-by: sealday Co-authored-by: bai.zixv Co-committed-by: bai.zixv --- .changeset/eighty-peas-explode.md | 5 ++ .../TabSearchAssociated.fields.tsx | 62 ++++++++++--------- .../settings/TabSearchItemFieldSettings.tsx | 5 +- 3 files changed, 42 insertions(+), 30 deletions(-) create mode 100644 .changeset/eighty-peas-explode.md diff --git a/.changeset/eighty-peas-explode.md b/.changeset/eighty-peas-explode.md new file mode 100644 index 000000000..07802ea30 --- /dev/null +++ b/.changeset/eighty-peas-explode.md @@ -0,0 +1,5 @@ +--- +"@tachybase/plugin-mobile-client": patch +--- + +tab-search diff --git a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/tab-search/initializer/TabSearchAssociated.fields.tsx b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/tab-search/initializer/TabSearchAssociated.fields.tsx index a398bec41..93b136fc7 100644 --- a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/tab-search/initializer/TabSearchAssociated.fields.tsx +++ b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/tab-search/initializer/TabSearchAssociated.fields.tsx @@ -55,7 +55,7 @@ function useAssociationFields(type: 'textField' | 'choiceField') { const { name, allFields } = collection || {}; const { getCollectionFields } = useCollectionFields_custom(); - const isMobield = useIsMobile(); + const isMobile = useIsMobile(); const cm = useCollectionManager(); @@ -85,7 +85,7 @@ function useAssociationFields(type: 'textField' | 'choiceField') { label, schemaName: field.name, }, - isMobield, + isMobile, ); return result; }); @@ -100,7 +100,7 @@ function useAssociationFields(type: 'textField' | 'choiceField') { label, schemaName: field.name, }, - isMobield, + isMobile, ); return result; }); @@ -111,7 +111,7 @@ function useAssociationFields(type: 'textField' | 'choiceField') { } // NOTE: 递归生成 schema 树 -function getItemInput(params: ItemInterface, isMobield?: boolean) { +function getItemInput(params: ItemInterface, isMobile?: boolean) { const { field, label, @@ -140,15 +140,18 @@ function getItemInput(params: ItemInterface, isMobield?: boolean) { const label = canBeRelatedField(field.interface) ? cm.getCollection(`${name}.${field.name}`)?.titleField : field.name; - return getItemInput({ - field: subField, - label, - schemaName: `${schemaName}.${subField.name}`, - collectionName: collectionName, - getCollectionFields: getCollectionFields, - processedCollections: [...processedCollections, field.target], - collectionManager: cm, - }); + return getItemInput( + { + field: subField, + label, + schemaName: `${schemaName}.${subField.name}`, + collectionName: collectionName, + getCollectionFields: getCollectionFields, + processedCollections: [...processedCollections, field.target], + collectionManager: cm, + }, + isMobile, + ); }) .filter(Boolean), } as SchemaInitializerItemType; @@ -199,8 +202,8 @@ function getItemInput(params: ItemInterface, isMobield?: boolean) { // 'x-decorator': 'FormItem', // 'x-component': 'CollectionField', 'x-component': matchTruthValue({ - ['TabSearchCollapsibleInputMItem']: isMobield, - ['TabSearchCollapsibleInputItem']: !isMobield, + ['TabSearchCollapsibleInputMItem']: isMobile, + ['TabSearchCollapsibleInputItem']: !isMobile, }), 'x-component-props': { fieldNames: { @@ -220,7 +223,7 @@ function getItemInput(params: ItemInterface, isMobield?: boolean) { } as SchemaInitializerItemType; } // NOTE: 递归生成 schema 树 -function getItemChoice(params: ItemInterface, isMobield?: boolean) { +function getItemChoice(params: ItemInterface, isMobile?: boolean) { const { field, label, @@ -266,16 +269,19 @@ function getItemChoice(params: ItemInterface, isMobield?: boolean) { ) .map((subField) => { const label = cm.getCollection(field.target)?.getPrimaryKey() || 'id'; - return getItemChoice({ - field: subField, - label, - schemaName: `${schemaName}.${subField.name}`, - collectionName: collectionName, - getCollectionFields: getCollectionFields, - processedCollections: [...processedCollections, field.target], - collectionManager: cm, - currentCollection: field.target, - }); + return getItemChoice( + { + field: subField, + label, + schemaName: `${schemaName}.${subField.name}`, + collectionName: collectionName, + getCollectionFields: getCollectionFields, + processedCollections: [...processedCollections, field.target], + collectionManager: cm, + currentCollection: field.target, + }, + isMobile, + ); }) .filter(Boolean), } as SchemaInitializerItemType; @@ -312,8 +318,8 @@ function getItemChoice(params: ItemInterface, isMobield?: boolean) { // 'x-decorator': 'FormItem', // 'x-component': 'CollectionField', 'x-component': matchTruthValue({ - ['TabSearchFieldMItem']: isMobield, - ['TabSearchFieldItem']: !isMobield, + ['TabSearchFieldMItem']: isMobile, + ['TabSearchFieldItem']: !isMobile, }), 'x-component-props': { fieldNames: { diff --git a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/tab-search/settings/TabSearchItemFieldSettings.tsx b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/tab-search/settings/TabSearchItemFieldSettings.tsx index 2351569f0..20ab55b17 100644 --- a/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/tab-search/settings/TabSearchItemFieldSettings.tsx +++ b/packages/plugins/@tachybase/plugin-mobile-client/src/client/core/schema/components/tab-search/settings/TabSearchItemFieldSettings.tsx @@ -35,9 +35,10 @@ export const TabSearchItemFieldSettings = new SchemaSettings({ const { form } = useFormBlockContext(); const field = useField(); const cm = useCollectionManager(); - const c = useCollection(); + const collection = useCollection(); const collectionField = - c.getField(fieldSchema['name']) || cm.getCollectionField(fieldSchema['x-collection-field']); + collection.getField(fieldSchema['fieldName']) || + cm.getCollectionField(fieldSchema['x-collection-field']); const { dn } = useDesignable(); return {