From 49b75b6ab6595701d03d41ab5037522839c059c1 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Fri, 22 Sep 2023 11:09:53 +0800 Subject: [PATCH] refactor: view collection support add m2o association field (#2422) * refactor: view collection support add m2o association field * refactor: code improve --- .../src/block-provider/BlockProvider.tsx | 1 - .../Configuration/AddFieldAction.tsx | 125 ++++++++++-------- 2 files changed, 71 insertions(+), 55 deletions(-) diff --git a/packages/core/client/src/block-provider/BlockProvider.tsx b/packages/core/client/src/block-provider/BlockProvider.tsx index accdc3e0c..fe0043a2d 100644 --- a/packages/core/client/src/block-provider/BlockProvider.tsx +++ b/packages/core/client/src/block-provider/BlockProvider.tsx @@ -274,7 +274,6 @@ export const RenderChildrenWithAssociationFilter: React.FC = (props) => { }; export const BlockProvider = (props) => { - console.log(props); const { collection, association } = props; const resource = useResource(props); const params = { ...props.params }; diff --git a/packages/core/client/src/collection-manager/Configuration/AddFieldAction.tsx b/packages/core/client/src/collection-manager/Configuration/AddFieldAction.tsx index 0b7664bb4..453365b0d 100644 --- a/packages/core/client/src/collection-manager/Configuration/AddFieldAction.tsx +++ b/packages/core/client/src/collection-manager/Configuration/AddFieldAction.tsx @@ -240,28 +240,47 @@ export const AddFieldAction = (props) => { return optionArr; }, [getTemplate, record]); const items = useMemo(() => { - return getFieldOptions().map((option) => { - if (option.children.length === 0) { - return null; - } - - return { - type: 'group', - label: compile(option.label), - title: compile(option.label), - key: option.label, - children: option.children - .filter((child) => !['o2o', 'subTable', 'linkTo'].includes(child.name)) - .map((child) => { - return { - label: compile(child.title), - title: compile(child.title), - key: child.name, - dataTargetScope: child.targetScope, - }; - }), - }; - }); + return getFieldOptions() + .map((option) => { + if (option.children.length === 0) { + return null; + } + if (record.template === 'view') { + return { + type: 'group', + label: compile(option.label), + title: compile(option.label), + key: option.label, + children: option.children + .filter((child) => ['m2o'].includes(child.name)) + .map((child) => { + return { + label: compile(child.title), + title: compile(child.title), + key: child.name, + dataTargetScope: child.targetScope, + }; + }), + }; + } + return { + type: 'group', + label: compile(option.label), + title: compile(option.label), + key: option.label, + children: option.children + .filter((child) => !['o2o', 'subTable', 'linkTo'].includes(child.name)) + .map((child) => { + return { + label: compile(child.title), + title: compile(child.title), + key: child.name, + dataTargetScope: child.targetScope, + }; + }), + }; + }) + .filter((v) => v.children.length); }, [getFieldOptions]); const menu = useMemo(() => { return { @@ -283,37 +302,35 @@ export const AddFieldAction = (props) => { }; }, [getInterface, items, record]); return ( - record.template !== 'view' && ( - - - - {children || ( - - )} - - - - - ) + + + + {children || ( + + )} + + + + ); };