mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:36:44 +00:00
refactor: workflow block && template block support setting block height (#4678)
* refactor: workflow support setting block height * refactor: support block template * fix: bug * fix: bug * fix: bug * fix: bug * fix: bug
This commit is contained in:
parent
6b6b69ae09
commit
2b7544bdc4
@ -2,9 +2,7 @@
|
|||||||
"version": "1.2.4-alpha",
|
"version": "1.2.4-alpha",
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"useWorkspaces": true,
|
"useWorkspaces": true,
|
||||||
"npmClientArgs": [
|
"npmClientArgs": ["--ignore-engines"],
|
||||||
"--ignore-engines"
|
|
||||||
],
|
|
||||||
"command": {
|
"command": {
|
||||||
"version": {
|
"version": {
|
||||||
"forcePublish": true,
|
"forcePublish": true,
|
||||||
|
@ -15,7 +15,7 @@ import { withDynamicSchemaProps } from '../hoc/withDynamicSchemaProps';
|
|||||||
import { useTableBlockParams } from '../modules/blocks/data-blocks/table';
|
import { useTableBlockParams } from '../modules/blocks/data-blocks/table';
|
||||||
import { FixedBlockWrapper, SchemaComponentOptions } from '../schema-component';
|
import { FixedBlockWrapper, SchemaComponentOptions } from '../schema-component';
|
||||||
import { BlockProvider, useBlockRequestContext } from './BlockProvider';
|
import { BlockProvider, useBlockRequestContext } from './BlockProvider';
|
||||||
|
import { useBlockHeightProps } from './hooks';
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -67,6 +67,7 @@ const InternalTableBlockProvider = (props: Props) => {
|
|||||||
const { resource, service } = useBlockRequestContext();
|
const { resource, service } = useBlockRequestContext();
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const [expandFlag, setExpandFlag] = useState(fieldNames || propsExpandFlag ? true : false);
|
const [expandFlag, setExpandFlag] = useState(fieldNames || propsExpandFlag ? true : false);
|
||||||
|
const { heightProps } = useBlockHeightProps();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setExpandFlag(fieldNames || propsExpandFlag);
|
setExpandFlag(fieldNames || propsExpandFlag);
|
||||||
@ -104,6 +105,7 @@ const InternalTableBlockProvider = (props: Props) => {
|
|||||||
childrenColumnName,
|
childrenColumnName,
|
||||||
allIncludesChildren,
|
allIncludesChildren,
|
||||||
setExpandFlag: setExpandFlagValue,
|
setExpandFlag: setExpandFlagValue,
|
||||||
|
heightProps,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
@ -147,7 +149,6 @@ export const TableBlockProvider = withDynamicSchemaProps((props) => {
|
|||||||
const collection = getCollection(props.collection, props.dataSource);
|
const collection = getCollection(props.collection, props.dataSource);
|
||||||
const { treeTable } = fieldSchema?.['x-decorator-props'] || {};
|
const { treeTable } = fieldSchema?.['x-decorator-props'] || {};
|
||||||
const { params, parseVariableLoading } = useTableBlockParamsCompat(props);
|
const { params, parseVariableLoading } = useTableBlockParamsCompat(props);
|
||||||
|
|
||||||
let childrenColumnName = 'children';
|
let childrenColumnName = 'children';
|
||||||
|
|
||||||
if (treeTable) {
|
if (treeTable) {
|
||||||
|
@ -9,17 +9,23 @@
|
|||||||
|
|
||||||
import { useFieldSchema } from '@formily/react';
|
import { useFieldSchema } from '@formily/react';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
import { useBlockTemplateContext } from '../../schema-templates/BlockTemplate';
|
||||||
|
|
||||||
export const useBlockHeightProps = () => {
|
export const useBlockHeightProps = () => {
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const cardItemSchema = getCardItemSchema(fieldSchema);
|
const cardItemSchema = getCardItemSchema(fieldSchema);
|
||||||
const pageSchema = useMemo(() => getPageSchema(fieldSchema), []);
|
const blockTemplateSchema = useBlockTemplateContext()?.fieldSchema;
|
||||||
|
const pageSchema = useMemo(() => getPageSchema(blockTemplateSchema || fieldSchema), []);
|
||||||
const { disablePageHeader, enablePageTabs, hidePageTitle } = pageSchema?.['x-component-props'] || {};
|
const { disablePageHeader, enablePageTabs, hidePageTitle } = pageSchema?.['x-component-props'] || {};
|
||||||
return {
|
return {
|
||||||
heightProps: { ...cardItemSchema?.['x-component-props'], disablePageHeader, enablePageTabs, hidePageTitle },
|
heightProps: {
|
||||||
|
...cardItemSchema?.['x-component-props'],
|
||||||
|
disablePageHeader,
|
||||||
|
enablePageTabs,
|
||||||
|
hidePageTitle,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPageSchema = (schema) => {
|
export const getPageSchema = (schema) => {
|
||||||
if (!schema) return null;
|
if (!schema) return null;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import { theme } from 'antd';
|
|||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { useCallback, useMemo, useRef, useState } from 'react';
|
import { useCallback, useMemo, useRef, useState } from 'react';
|
||||||
import { useDesignable } from '..';
|
import { useDesignable } from '..';
|
||||||
import { useDataBlockRequest } from '../../';
|
import { useDataBlockRequest, useCollection, useTableBlockContext } from '../../';
|
||||||
import { HeightMode } from '../../schema-settings/SchemaSettingsBlockHeightItem';
|
import { HeightMode } from '../../schema-settings/SchemaSettingsBlockHeightItem';
|
||||||
import { useBlockHeightProps, getPageSchema } from '../../block-provider/hooks';
|
import { useBlockHeightProps, getPageSchema } from '../../block-provider/hooks';
|
||||||
|
|
||||||
@ -58,7 +58,18 @@ const usePageFullScreenHeight = (props?) => {
|
|||||||
return navHeight + pageHeaderHeight + addBlockBtnHeight;
|
return navHeight + pageHeaderHeight + addBlockBtnHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
//抽屉中满屏
|
// 抽屉中满屏
|
||||||
|
const useDrawerFullScreenHeight = () => {
|
||||||
|
const { token } = theme.useToken();
|
||||||
|
const { designable } = useDesignable();
|
||||||
|
const tabActionHeight = token.paddingContentVerticalLG + token.margin + 2 * token.paddingContentVertical + 24;
|
||||||
|
const addBlockBtnHeight = designable
|
||||||
|
? token.controlHeight + 2 * token.paddingContentHorizontalLG
|
||||||
|
: 1 * token.paddingContentHorizontalLG;
|
||||||
|
return tabActionHeight + addBlockBtnHeight;
|
||||||
|
};
|
||||||
|
|
||||||
|
//满屏
|
||||||
const useFullScreenHeight = (props?) => {
|
const useFullScreenHeight = (props?) => {
|
||||||
const schema = useFieldSchema();
|
const schema = useFieldSchema();
|
||||||
const isDrawerBlock = hasActionContainerInParentChain(schema);
|
const isDrawerBlock = hasActionContainerInParentChain(schema);
|
||||||
@ -70,24 +81,18 @@ const useFullScreenHeight = (props?) => {
|
|||||||
return pageReservedHeight;
|
return pageReservedHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 抽屉中满屏
|
const InternalWorkflowCollection = ['users_jobs', 'approvals', 'approvalRecords'];
|
||||||
const useDrawerFullScreenHeight = () => {
|
|
||||||
const { token } = theme.useToken();
|
|
||||||
const { designable } = useDesignable();
|
|
||||||
const tabActionHeight = token.paddingContentVerticalLG + token.margin + 2 * token.paddingContentVertical + 24;
|
|
||||||
const addBlockBtnHeight = designable
|
|
||||||
? token.controlHeight + 3 * token.paddingContentHorizontalLG
|
|
||||||
: 2 * token.paddingContentHorizontalLG;
|
|
||||||
return tabActionHeight + addBlockBtnHeight;
|
|
||||||
};
|
|
||||||
// 表格区块高度计算
|
// 表格区块高度计算
|
||||||
const useTableHeight = () => {
|
const useTableHeight = () => {
|
||||||
const { token } = theme.useToken();
|
const { token } = theme.useToken();
|
||||||
const { heightProps } = useBlockHeightProps();
|
const { heightProps: blockHeightProps } = useBlockHeightProps();
|
||||||
|
const { heightProps: tableHeightProps } = useTableBlockContext();
|
||||||
const { designable } = useDesignable();
|
const { designable } = useDesignable();
|
||||||
const schema = useFieldSchema();
|
const schema = useFieldSchema();
|
||||||
|
const heightProps = tableHeightProps || blockHeightProps;
|
||||||
const pageFullScreenHeight = useFullScreenHeight();
|
const pageFullScreenHeight = useFullScreenHeight();
|
||||||
const { data } = useDataBlockRequest();
|
const { data } = useDataBlockRequest();
|
||||||
|
const { name } = useCollection();
|
||||||
const { count, pageSize } = (data as any)?.meta || ({} as any);
|
const { count, pageSize } = (data as any)?.meta || ({} as any);
|
||||||
const hasPagination = count > pageSize;
|
const hasPagination = count > pageSize;
|
||||||
const { heightMode, height, title } = heightProps;
|
const { heightMode, height, title } = heightProps;
|
||||||
@ -97,7 +102,8 @@ const useTableHeight = () => {
|
|||||||
const hasTableActions = Object.keys(schema.parent.properties.actions?.properties || {}).length > 0;
|
const hasTableActions = Object.keys(schema.parent.properties.actions?.properties || {}).length > 0;
|
||||||
const paginationHeight = hasPagination ? token.controlHeight + token.padding + token.marginLG : token.marginLG;
|
const paginationHeight = hasPagination ? token.controlHeight + token.padding + token.marginLG : token.marginLG;
|
||||||
const actionBarHeight = hasTableActions || designable ? token.controlHeight + 2 * token.marginLG : token.marginLG;
|
const actionBarHeight = hasTableActions || designable ? token.controlHeight + 2 * token.marginLG : token.marginLG;
|
||||||
const tableHeaderHeight = (designable ? token.controlHeight : 22) + 2 * token.padding + 1;
|
const tableHeaderHeight =
|
||||||
|
(designable && !InternalWorkflowCollection.includes(name) ? token.controlHeight : 22) + 2 * token.padding + 1;
|
||||||
const blockHeaderHeight = title ? token.fontSizeLG * token.lineHeightLG + token.padding * 2 - 1 : 0;
|
const blockHeaderHeight = title ? token.fontSizeLG * token.lineHeightLG + token.padding * 2 - 1 : 0;
|
||||||
if (heightMode === HeightMode.FULL_HEIGHT) {
|
if (heightMode === HeightMode.FULL_HEIGHT) {
|
||||||
return (
|
return (
|
||||||
|
@ -244,7 +244,7 @@ export const WorkflowTodo: React.FC & { Drawer: React.FC; Decorator: React.FC }
|
|||||||
'x-component': 'ActionBar',
|
'x-component': 'ActionBar',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
style: {
|
style: {
|
||||||
marginBottom: 16,
|
marginBottom: 'var(--nb-spacing)',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {
|
||||||
|
Loading…
Reference in New Issue
Block a user