From bc758e6846679b5238280d021a17f09feaf5cc01 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Fri, 20 Oct 2023 11:39:04 +0800 Subject: [PATCH] fix: non UI configured states should only display corresponding inhreited collection block (#2879) --- .../src/block-provider/FormBlockProvider.tsx | 17 +++++++---------- .../src/schema-component/antd/action/hooks.ts | 4 ++-- .../antd/form-item/FormItem.tsx | 2 ++ .../items/CreateActionInitializer.tsx | 1 + 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/core/client/src/block-provider/FormBlockProvider.tsx b/packages/core/client/src/block-provider/FormBlockProvider.tsx index 671b55232..74a12dd8a 100644 --- a/packages/core/client/src/block-provider/FormBlockProvider.tsx +++ b/packages/core/client/src/block-provider/FormBlockProvider.tsx @@ -81,13 +81,9 @@ export const useFormBlockType = () => { return { type: ctx.type } as { type: 'update' | 'create' }; }; -export const useIsEmptyRecord = () => { - const record = useRecord(); - const keys = Object.keys(record); - if (keys.includes('__parent')) { - return keys.length > 1; - } - return keys.length > 0; +export const useIsDetailBlock = () => { + const ctx = useActionContext(); + return !(ctx?.fieldSchema?.['x-acl-action'] === 'create' || ctx?.fieldSchema?.['x-action'] === 'create'); }; export const FormBlockProvider = (props) => { @@ -96,16 +92,17 @@ export const FormBlockProvider = (props) => { const { __collection } = record; const currentCollection = useCollection(); const { designable } = useDesignable(); - const isEmptyRecord = useIsEmptyRecord(); + const isDetailBlock = useIsDetailBlock(); let detailFlag = false; - if (isEmptyRecord) { + if (isDetailBlock) { detailFlag = true; if (!designable && __collection) { + console.log(__collection === collection); detailFlag = __collection === collection; } } const createFlag = - (currentCollection.name === (collection?.name || collection) && !isEmptyRecord) || !currentCollection.name; + (currentCollection.name === (collection?.name || collection) && !isDetailBlock) || !currentCollection.name; return ( (detailFlag || createFlag || isCusomeizeCreate) && ( diff --git a/packages/core/client/src/schema-component/antd/action/hooks.ts b/packages/core/client/src/schema-component/antd/action/hooks.ts index 93fcf675e..bc0a34f59 100644 --- a/packages/core/client/src/schema-component/antd/action/hooks.ts +++ b/packages/core/client/src/schema-component/antd/action/hooks.ts @@ -2,7 +2,7 @@ import { useFieldSchema, useForm } from '@formily/react'; import { App } from 'antd'; import { useContext } from 'react'; import { useTranslation } from 'react-i18next'; -import { useIsEmptyRecord } from '../../../block-provider/FormBlockProvider'; +import { useIsDetailBlock } from '../../../block-provider/FormBlockProvider'; import { ActionContext } from './context'; export const useA = () => { @@ -56,7 +56,7 @@ export const useCloseAction = () => { export const useLinkageAction = () => { const fieldSchema = useFieldSchema(); - const isRecordAction = useIsEmptyRecord(); + const isRecordAction = useIsDetailBlock(); const isAction = ['Action.Link', 'Action'].includes(fieldSchema['x-component']); return isAction && isRecordAction; }; diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx index 7d04b088f..3f60e13e5 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx @@ -438,6 +438,7 @@ FormItem.Designer = function Designer() { if (!hasAddNew) { const addNewActionschema = { 'x-action': 'create', + 'x-acl-action': 'create', title: "{{t('Add new')}}", 'x-designer': 'Action.Designer', 'x-component': 'Action', @@ -485,6 +486,7 @@ FormItem.Designer = function Designer() { if (!hasAddNew) { const addNewActionschema = { 'x-action': 'create', + 'x-acl-action': 'create', title: "{{t('Add new')}}", 'x-designer': 'Action.Designer', 'x-component': 'Action', diff --git a/packages/core/client/src/schema-initializer/items/CreateActionInitializer.tsx b/packages/core/client/src/schema-initializer/items/CreateActionInitializer.tsx index cba7ce227..c76de0174 100644 --- a/packages/core/client/src/schema-initializer/items/CreateActionInitializer.tsx +++ b/packages/core/client/src/schema-initializer/items/CreateActionInitializer.tsx @@ -5,6 +5,7 @@ export const CreateActionInitializer = (props) => { const schema = { type: 'void', 'x-action': 'create', + 'x-acl-action': 'create', title: "{{t('Add new')}}", 'x-designer': 'Action.Designer', 'x-component': 'Action',