mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +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 { css } from '@emotion/css';
|
||||
import {
|
||||
AddActionButton,
|
||||
AddActionModel,
|
||||
AddFieldButton,
|
||||
Collection,
|
||||
@ -83,7 +84,10 @@ export class TableModel extends BlockFlowModel<S> {
|
||||
extraContext={{ currentModel: this, currentResource: this.resource }}
|
||||
/>
|
||||
))}
|
||||
<AddActionModel
|
||||
<AddActionButton model={this} subModelBaseClass="ActionModel">
|
||||
<Button icon={<SettingOutlined />}>Configure actions</Button>
|
||||
</AddActionButton>
|
||||
{/* <AddActionModel
|
||||
model={this}
|
||||
subModelKey={'actions'}
|
||||
items={() => [
|
||||
@ -104,7 +108,7 @@ export class TableModel extends BlockFlowModel<S> {
|
||||
]}
|
||||
>
|
||||
<Button icon={<SettingOutlined />}>Configure actions</Button>
|
||||
</AddActionModel>
|
||||
</AddActionModel> */}
|
||||
</Space>
|
||||
<Table
|
||||
className={css`
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { AddSubModelButton } from './AddSubModelButton';
|
||||
import { AddSubModelButton, SubModelItemsType } from './AddSubModelButton';
|
||||
import { FlowModel } from '../../models/flowModel';
|
||||
import { ModelConstructor } from '../../types';
|
||||
import { Button } from 'antd';
|
||||
@ -32,6 +32,14 @@ interface AddActionButtonProps {
|
||||
* 按钮文本
|
||||
*/
|
||||
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',
|
||||
children = <Button>Configure actions</Button>,
|
||||
subModelType = 'array',
|
||||
items,
|
||||
filter,
|
||||
onModelAdded,
|
||||
}) => {
|
||||
const items = useMemo(() => {
|
||||
const blockClasses = model.flowEngine.filterModelClassByParent(subModelBaseClass);
|
||||
const allActionsItems = useMemo(() => {
|
||||
const actionClasses = model.flowEngine.filterModelClassByParent(subModelBaseClass);
|
||||
const registeredBlocks = [];
|
||||
for (const [className, ModelClass] of blockClasses) {
|
||||
for (const [className, ModelClass] of actionClasses) {
|
||||
if (filter && !filter(ModelClass, className)) {
|
||||
continue;
|
||||
}
|
||||
const item = {
|
||||
key: className,
|
||||
label: ModelClass.meta?.title || className,
|
||||
@ -76,7 +89,7 @@ export const AddActionButton: React.FC<AddActionButtonProps> = ({
|
||||
model={model}
|
||||
subModelKey={subModelKey}
|
||||
subModelType={subModelType}
|
||||
items={items}
|
||||
items={items ?? allActionsItems}
|
||||
onModelAdded={onModelAdded}
|
||||
>
|
||||
{children}
|
||||
|
@ -34,13 +34,13 @@ interface AddBlockButtonProps {
|
||||
*/
|
||||
children?: React.ReactNode;
|
||||
/**
|
||||
* 自定义 items(如果提供,将覆盖默认的数据源选择行为)
|
||||
* 自定义 items(如果提供,将覆盖默认的区块菜单)
|
||||
*/
|
||||
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>,
|
||||
subModelType = 'array',
|
||||
items,
|
||||
filterBlocks,
|
||||
filter: filterBlocks,
|
||||
appendItems,
|
||||
onModelAdded,
|
||||
}) => {
|
||||
|
@ -42,6 +42,10 @@ export interface AddFieldButtonProps {
|
||||
* 显示的UI组件
|
||||
*/
|
||||
children?: React.ReactNode;
|
||||
/**
|
||||
* 自定义 items(如果提供,将覆盖默认的字段菜单)
|
||||
*/
|
||||
items?: SubModelItemsType;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,6 +67,7 @@ export const AddFieldButton: React.FC<AddFieldButtonProps> = ({
|
||||
subModelType = 'array',
|
||||
collection,
|
||||
buildCreateModelOptions,
|
||||
items,
|
||||
appendItems,
|
||||
onModelAdded,
|
||||
}) => {
|
||||
@ -117,7 +122,7 @@ export const AddFieldButton: React.FC<AddFieldButtonProps> = ({
|
||||
};
|
||||
}, [model, subModelBaseClass, fields, buildCreateModelOptions]);
|
||||
|
||||
const items = useMemo(() => {
|
||||
const fieldItems = useMemo(() => {
|
||||
return mergeSubModelItems([buildFieldItems, appendItems], { addDividers: true });
|
||||
}, [buildFieldItems, appendItems]);
|
||||
|
||||
@ -126,7 +131,7 @@ export const AddFieldButton: React.FC<AddFieldButtonProps> = ({
|
||||
model={model}
|
||||
subModelKey={subModelKey}
|
||||
subModelType={subModelType}
|
||||
items={items}
|
||||
items={items ?? fieldItems}
|
||||
onModelAdded={onModelAdded}
|
||||
>
|
||||
{children}
|
||||
|
Loading…
x
Reference in New Issue
Block a user