mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:55:50 +00:00
fix: non UI configured states should only display corresponding inhreited collection block (#2879)
This commit is contained in:
parent
b587560a10
commit
bc758e6846
@ -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'}>
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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',
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user