fix: non UI configured states should only display corresponding inhreited collection block (#2879)

This commit is contained in:
katherinehhh 2023-10-20 11:39:04 +08:00 committed by GitHub
parent b587560a10
commit bc758e6846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 12 deletions

View File

@ -81,13 +81,9 @@ export const useFormBlockType = () => {
return { type: ctx.type } as { type: 'update' | 'create' }; return { type: ctx.type } as { type: 'update' | 'create' };
}; };
export const useIsEmptyRecord = () => { export const useIsDetailBlock = () => {
const record = useRecord(); const ctx = useActionContext();
const keys = Object.keys(record); return !(ctx?.fieldSchema?.['x-acl-action'] === 'create' || ctx?.fieldSchema?.['x-action'] === 'create');
if (keys.includes('__parent')) {
return keys.length > 1;
}
return keys.length > 0;
}; };
export const FormBlockProvider = (props) => { export const FormBlockProvider = (props) => {
@ -96,16 +92,17 @@ export const FormBlockProvider = (props) => {
const { __collection } = record; const { __collection } = record;
const currentCollection = useCollection(); const currentCollection = useCollection();
const { designable } = useDesignable(); const { designable } = useDesignable();
const isEmptyRecord = useIsEmptyRecord(); const isDetailBlock = useIsDetailBlock();
let detailFlag = false; let detailFlag = false;
if (isEmptyRecord) { if (isDetailBlock) {
detailFlag = true; detailFlag = true;
if (!designable && __collection) { if (!designable && __collection) {
console.log(__collection === collection);
detailFlag = __collection === collection; detailFlag = __collection === collection;
} }
} }
const createFlag = const createFlag =
(currentCollection.name === (collection?.name || collection) && !isEmptyRecord) || !currentCollection.name; (currentCollection.name === (collection?.name || collection) && !isDetailBlock) || !currentCollection.name;
return ( return (
(detailFlag || createFlag || isCusomeizeCreate) && ( (detailFlag || createFlag || isCusomeizeCreate) && (
<BlockProvider data-testid={props['data-testid'] || 'form-block'} {...props} block={'form'}> <BlockProvider data-testid={props['data-testid'] || 'form-block'} {...props} block={'form'}>

View File

@ -2,7 +2,7 @@ import { useFieldSchema, useForm } from '@formily/react';
import { App } from 'antd'; import { App } from 'antd';
import { useContext } from 'react'; import { useContext } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useIsEmptyRecord } from '../../../block-provider/FormBlockProvider'; import { useIsDetailBlock } from '../../../block-provider/FormBlockProvider';
import { ActionContext } from './context'; import { ActionContext } from './context';
export const useA = () => { export const useA = () => {
@ -56,7 +56,7 @@ export const useCloseAction = () => {
export const useLinkageAction = () => { export const useLinkageAction = () => {
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();
const isRecordAction = useIsEmptyRecord(); const isRecordAction = useIsDetailBlock();
const isAction = ['Action.Link', 'Action'].includes(fieldSchema['x-component']); const isAction = ['Action.Link', 'Action'].includes(fieldSchema['x-component']);
return isAction && isRecordAction; return isAction && isRecordAction;
}; };

View File

@ -438,6 +438,7 @@ FormItem.Designer = function Designer() {
if (!hasAddNew) { if (!hasAddNew) {
const addNewActionschema = { const addNewActionschema = {
'x-action': 'create', 'x-action': 'create',
'x-acl-action': 'create',
title: "{{t('Add new')}}", title: "{{t('Add new')}}",
'x-designer': 'Action.Designer', 'x-designer': 'Action.Designer',
'x-component': 'Action', 'x-component': 'Action',
@ -485,6 +486,7 @@ FormItem.Designer = function Designer() {
if (!hasAddNew) { if (!hasAddNew) {
const addNewActionschema = { const addNewActionschema = {
'x-action': 'create', 'x-action': 'create',
'x-acl-action': 'create',
title: "{{t('Add new')}}", title: "{{t('Add new')}}",
'x-designer': 'Action.Designer', 'x-designer': 'Action.Designer',
'x-component': 'Action', 'x-component': 'Action',

View File

@ -5,6 +5,7 @@ export const CreateActionInitializer = (props) => {
const schema = { const schema = {
type: 'void', type: 'void',
'x-action': 'create', 'x-action': 'create',
'x-acl-action': 'create',
title: "{{t('Add new')}}", title: "{{t('Add new')}}",
'x-designer': 'Action.Designer', 'x-designer': 'Action.Designer',
'x-component': 'Action', 'x-component': 'Action',