From dcd89df482cfb57d15231de23639592587ce0410 Mon Sep 17 00:00:00 2001 From: sealday Date: Tue, 7 May 2024 20:30:14 +0800 Subject: [PATCH] feat: support edit associated form (#920) Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/920 --- .../src/block-provider/FormBlockProvider.tsx | 9 ++++- .../form/RecordFormBlockInitializer.tsx | 38 ++++++++++++------- .../buttons/RecordBlockInitializers.tsx | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/packages/core/client/src/block-provider/FormBlockProvider.tsx b/packages/core/client/src/block-provider/FormBlockProvider.tsx index 64ab10971..adb2b30d2 100644 --- a/packages/core/client/src/block-provider/FormBlockProvider.tsx +++ b/packages/core/client/src/block-provider/FormBlockProvider.tsx @@ -93,7 +93,7 @@ export const useIsDetailBlock = () => { export const FormBlockProvider = withDynamicSchemaProps((props) => { const record = useRecord(); const parentRecordData = useCollectionParentRecordData(); - const { collection, isCusomeizeCreate } = props; + const { collection, isCusomeizeCreate, parentRecord } = props; const { __collection } = record; const currentCollection = useCollection_deprecated(); const { designable } = useDesignable(); @@ -114,7 +114,12 @@ export const FormBlockProvider = withDynamicSchemaProps((props) => { return ( - + diff --git a/packages/core/client/src/modules/blocks/data-blocks/form/RecordFormBlockInitializer.tsx b/packages/core/client/src/modules/blocks/data-blocks/form/RecordFormBlockInitializer.tsx index 6d94b0b23..95633faef 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/form/RecordFormBlockInitializer.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/form/RecordFormBlockInitializer.tsx @@ -43,20 +43,30 @@ export function useCreateEditFormBlock() { const createEditFormBlock = useCallback( ({ item }) => { - insert( - createEditFormBlockUISchema( - association - ? { - association, - dataSource: item.dataSource, - isCurrent: true, - } - : { - collectionName: item.collectionName || item.name, - dataSource: item.dataSource, - }, - ), - ); + if (!association && item.associationField) { + const field = item.associationField; + insert( + createEditFormBlockUISchema({ + dataSource: item.dataSource, + association: `${field.collectionName}.${field.name}`, + }), + ); + } else { + insert( + createEditFormBlockUISchema( + association + ? { + association, + dataSource: item.dataSource, + isCurrent: true, + } + : { + collectionName: item.collectionName || item.name, + dataSource: item.dataSource, + }, + ), + ); + } }, [association, insert], ); diff --git a/packages/core/client/src/schema-initializer/buttons/RecordBlockInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/RecordBlockInitializers.tsx index 17fa7f53d..135db5de5 100644 --- a/packages/core/client/src/schema-initializer/buttons/RecordBlockInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/RecordBlockInitializers.tsx @@ -126,7 +126,7 @@ function useRecordBlocks() { if (collection) { return collectionsNeedToDisplay.some((c) => c.name === collection.name); } - return false; + return true; }, onlyCurrentDataSource: true, hideSearch: true,