mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 11:12:20 +08:00
fix: add sub models
This commit is contained in:
parent
e96dc892b5
commit
623f979671
@ -10,6 +10,7 @@
|
|||||||
import { SettingOutlined } from '@ant-design/icons';
|
import { SettingOutlined } from '@ant-design/icons';
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import {
|
import {
|
||||||
|
AddActionButton,
|
||||||
AddActionModel,
|
AddActionModel,
|
||||||
AddFieldButton,
|
AddFieldButton,
|
||||||
Collection,
|
Collection,
|
||||||
@ -83,7 +84,10 @@ export class TableModel extends BlockFlowModel<S> {
|
|||||||
extraContext={{ currentModel: this, currentResource: this.resource }}
|
extraContext={{ currentModel: this, currentResource: this.resource }}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<AddActionModel
|
<AddActionButton model={this} subModelBaseClass="ActionModel">
|
||||||
|
<Button icon={<SettingOutlined />}>Configure actions</Button>
|
||||||
|
</AddActionButton>
|
||||||
|
{/* <AddActionModel
|
||||||
model={this}
|
model={this}
|
||||||
subModelKey={'actions'}
|
subModelKey={'actions'}
|
||||||
items={() => [
|
items={() => [
|
||||||
@ -104,7 +108,7 @@ export class TableModel extends BlockFlowModel<S> {
|
|||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Button icon={<SettingOutlined />}>Configure actions</Button>
|
<Button icon={<SettingOutlined />}>Configure actions</Button>
|
||||||
</AddActionModel>
|
</AddActionModel> */}
|
||||||
</Space>
|
</Space>
|
||||||
<Table
|
<Table
|
||||||
className={css`
|
className={css`
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { AddSubModelButton } from './AddSubModelButton';
|
import { AddSubModelButton, SubModelItemsType } from './AddSubModelButton';
|
||||||
import { FlowModel } from '../../models/flowModel';
|
import { FlowModel } from '../../models/flowModel';
|
||||||
import { ModelConstructor } from '../../types';
|
import { ModelConstructor } from '../../types';
|
||||||
import { Button } from 'antd';
|
import { Button } from 'antd';
|
||||||
@ -32,6 +32,14 @@ interface AddActionButtonProps {
|
|||||||
* 按钮文本
|
* 按钮文本
|
||||||
*/
|
*/
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
/**
|
||||||
|
* 过滤Model菜单的函数
|
||||||
|
*/
|
||||||
|
filter?: (blockClass: ModelConstructor, className: string) => boolean;
|
||||||
|
/**
|
||||||
|
* 自定义 items(如果提供,将覆盖默认的action菜单)
|
||||||
|
*/
|
||||||
|
items?: SubModelItemsType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,12 +59,17 @@ export const AddActionButton: React.FC<AddActionButtonProps> = ({
|
|||||||
subModelKey = 'actions',
|
subModelKey = 'actions',
|
||||||
children = <Button>Configure actions</Button>,
|
children = <Button>Configure actions</Button>,
|
||||||
subModelType = 'array',
|
subModelType = 'array',
|
||||||
|
items,
|
||||||
|
filter,
|
||||||
onModelAdded,
|
onModelAdded,
|
||||||
}) => {
|
}) => {
|
||||||
const items = useMemo(() => {
|
const allActionsItems = useMemo(() => {
|
||||||
const blockClasses = model.flowEngine.filterModelClassByParent(subModelBaseClass);
|
const actionClasses = model.flowEngine.filterModelClassByParent(subModelBaseClass);
|
||||||
const registeredBlocks = [];
|
const registeredBlocks = [];
|
||||||
for (const [className, ModelClass] of blockClasses) {
|
for (const [className, ModelClass] of actionClasses) {
|
||||||
|
if (filter && !filter(ModelClass, className)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const item = {
|
const item = {
|
||||||
key: className,
|
key: className,
|
||||||
label: ModelClass.meta?.title || className,
|
label: ModelClass.meta?.title || className,
|
||||||
@ -76,7 +89,7 @@ export const AddActionButton: React.FC<AddActionButtonProps> = ({
|
|||||||
model={model}
|
model={model}
|
||||||
subModelKey={subModelKey}
|
subModelKey={subModelKey}
|
||||||
subModelType={subModelType}
|
subModelType={subModelType}
|
||||||
items={items}
|
items={items ?? allActionsItems}
|
||||||
onModelAdded={onModelAdded}
|
onModelAdded={onModelAdded}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
@ -34,13 +34,13 @@ interface AddBlockButtonProps {
|
|||||||
*/
|
*/
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
/**
|
/**
|
||||||
* 自定义 items(如果提供,将覆盖默认的数据源选择行为)
|
* 自定义 items(如果提供,将覆盖默认的区块菜单)
|
||||||
*/
|
*/
|
||||||
items?: SubModelItemsType;
|
items?: SubModelItemsType;
|
||||||
/**
|
/**
|
||||||
* 过滤区块类型的函数
|
* 过滤Model菜单的函数
|
||||||
*/
|
*/
|
||||||
filterBlocks?: (blockClass: ModelConstructor, className: string) => boolean;
|
filter?: (blockClass: ModelConstructor, className: string) => boolean;
|
||||||
/**
|
/**
|
||||||
* 追加额外的菜单项到默认菜单中
|
* 追加额外的菜单项到默认菜单中
|
||||||
*/
|
*/
|
||||||
@ -80,7 +80,7 @@ export const AddBlockButton: React.FC<AddBlockButtonProps> = ({
|
|||||||
children = <Button>Add block</Button>,
|
children = <Button>Add block</Button>,
|
||||||
subModelType = 'array',
|
subModelType = 'array',
|
||||||
items,
|
items,
|
||||||
filterBlocks,
|
filter: filterBlocks,
|
||||||
appendItems,
|
appendItems,
|
||||||
onModelAdded,
|
onModelAdded,
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -42,6 +42,10 @@ export interface AddFieldButtonProps {
|
|||||||
* 显示的UI组件
|
* 显示的UI组件
|
||||||
*/
|
*/
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
/**
|
||||||
|
* 自定义 items(如果提供,将覆盖默认的字段菜单)
|
||||||
|
*/
|
||||||
|
items?: SubModelItemsType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,6 +67,7 @@ export const AddFieldButton: React.FC<AddFieldButtonProps> = ({
|
|||||||
subModelType = 'array',
|
subModelType = 'array',
|
||||||
collection,
|
collection,
|
||||||
buildCreateModelOptions,
|
buildCreateModelOptions,
|
||||||
|
items,
|
||||||
appendItems,
|
appendItems,
|
||||||
onModelAdded,
|
onModelAdded,
|
||||||
}) => {
|
}) => {
|
||||||
@ -117,7 +122,7 @@ export const AddFieldButton: React.FC<AddFieldButtonProps> = ({
|
|||||||
};
|
};
|
||||||
}, [model, subModelBaseClass, fields, buildCreateModelOptions]);
|
}, [model, subModelBaseClass, fields, buildCreateModelOptions]);
|
||||||
|
|
||||||
const items = useMemo(() => {
|
const fieldItems = useMemo(() => {
|
||||||
return mergeSubModelItems([buildFieldItems, appendItems], { addDividers: true });
|
return mergeSubModelItems([buildFieldItems, appendItems], { addDividers: true });
|
||||||
}, [buildFieldItems, appendItems]);
|
}, [buildFieldItems, appendItems]);
|
||||||
|
|
||||||
@ -126,7 +131,7 @@ export const AddFieldButton: React.FC<AddFieldButtonProps> = ({
|
|||||||
model={model}
|
model={model}
|
||||||
subModelKey={subModelKey}
|
subModelKey={subModelKey}
|
||||||
subModelType={subModelType}
|
subModelType={subModelType}
|
||||||
items={items}
|
items={items ?? fieldItems}
|
||||||
onModelAdded={onModelAdded}
|
onModelAdded={onModelAdded}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user