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' };
};
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) && (
<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 { 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;
};

View File

@ -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',

View File

@ -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',