feat: auto-hide grid card block action bar when empty (#7069)

* feat: add useGridCardActionBarProps hook and integrate with ActionBar component

* test: update snapshot
This commit is contained in:
Zeke Zhang 2025-06-17 22:12:48 +08:00 committed by GitHub
parent b0bce69c94
commit dc6ea03c1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 37 additions and 16 deletions

View File

@ -19,9 +19,10 @@ import { useDetailsProps } from '../modules/blocks/data-blocks/details-single/ho
import { FormItemSchemaToolbar } from '../modules/blocks/data-blocks/form/FormItemSchemaToolbar'; import { FormItemSchemaToolbar } from '../modules/blocks/data-blocks/form/FormItemSchemaToolbar';
import { useCreateFormBlockDecoratorProps } from '../modules/blocks/data-blocks/form/hooks/useCreateFormBlockDecoratorProps'; import { useCreateFormBlockDecoratorProps } from '../modules/blocks/data-blocks/form/hooks/useCreateFormBlockDecoratorProps';
import { useCreateFormBlockProps } from '../modules/blocks/data-blocks/form/hooks/useCreateFormBlockProps'; import { useCreateFormBlockProps } from '../modules/blocks/data-blocks/form/hooks/useCreateFormBlockProps';
import { useDataFormItemProps } from '../modules/blocks/data-blocks/form/hooks/useDataFormItemProps';
import { useEditFormBlockDecoratorProps } from '../modules/blocks/data-blocks/form/hooks/useEditFormBlockDecoratorProps'; import { useEditFormBlockDecoratorProps } from '../modules/blocks/data-blocks/form/hooks/useEditFormBlockDecoratorProps';
import { useEditFormBlockProps } from '../modules/blocks/data-blocks/form/hooks/useEditFormBlockProps'; import { useEditFormBlockProps } from '../modules/blocks/data-blocks/form/hooks/useEditFormBlockProps';
import { useDataFormItemProps } from '../modules/blocks/data-blocks/form/hooks/useDataFormItemProps'; import { useGridCardActionBarProps } from '../modules/blocks/data-blocks/grid-card/hooks/useGridCardActionBarProps';
import { import {
useGridCardBlockDecoratorProps, useGridCardBlockDecoratorProps,
useGridCardBlockItemProps, useGridCardBlockItemProps,
@ -97,6 +98,7 @@ export const BlockSchemaComponentProvider: React.FC = (props) => {
useGridCardBlockProps, useGridCardBlockProps,
useFormItemProps, useFormItemProps,
useDataFormItemProps, useDataFormItemProps,
useGridCardActionBarProps,
}} }}
> >
{props.children} {props.children}
@ -161,6 +163,7 @@ export class BlockSchemaComponentPlugin extends Plugin {
useGridCardBlockItemProps, useGridCardBlockItemProps,
useFormItemProps, useFormItemProps,
useDataFormItemProps, useDataFormItemProps,
useGridCardActionBarProps,
}); });
} }
} }

View File

@ -27,12 +27,8 @@ describe('createGridCardBlockSchema', () => {
"actionBar": { "actionBar": {
"type": "void", "type": "void",
"x-component": "ActionBar", "x-component": "ActionBar",
"x-component-props": {
"style": {
"marginBottom": "var(--nb-spacing)",
},
},
"x-initializer": "gridCard:configureActions", "x-initializer": "gridCard:configureActions",
"x-use-component-props": "useGridCardActionBarProps",
}, },
"list": { "list": {
"properties": { "properties": {
@ -103,12 +99,8 @@ describe('createGridCardBlockSchema', () => {
"actionBar": { "actionBar": {
"type": "void", "type": "void",
"x-component": "ActionBar", "x-component": "ActionBar",
"x-component-props": {
"style": {
"marginBottom": "var(--nb-spacing)",
},
},
"x-initializer": "gridCard:configureActions", "x-initializer": "gridCard:configureActions",
"x-use-component-props": "useGridCardActionBarProps",
}, },
"list": { "list": {
"properties": { "properties": {

View File

@ -49,11 +49,7 @@ export const createGridCardBlockUISchema = (options: {
type: 'void', type: 'void',
'x-initializer': 'gridCard:configureActions', 'x-initializer': 'gridCard:configureActions',
'x-component': 'ActionBar', 'x-component': 'ActionBar',
'x-component-props': { 'x-use-component-props': 'useGridCardActionBarProps',
style: {
marginBottom: 'var(--nb-spacing)',
},
},
}, },
list: { list: {
type: 'array', type: 'array',

View File

@ -0,0 +1,26 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { useFieldSchema } from '@formily/react';
import _ from 'lodash';
import { useDesignable } from '../../../../../schema-component';
export const useGridCardActionBarProps = () => {
const fieldSchema = useFieldSchema();
const { designable } = useDesignable();
return {
style: {
marginBottom: 'var(--nb-spacing)',
},
// In non-configuration mode, when there are no buttons, ActionBar doesn't need to be displayed
hidden: !designable && _.isEmpty(fieldSchema.properties),
};
};

View File

@ -147,6 +147,10 @@ const InternalActionBar: FC = (props: any) => {
export const ActionBar = withDynamicSchemaProps( export const ActionBar = withDynamicSchemaProps(
(props: any) => { (props: any) => {
if (props.hidden) {
return null;
}
return <InternalActionBar {...props} />; return <InternalActionBar {...props} />;
}, },
{ displayName: 'ActionBar' }, { displayName: 'ActionBar' },