docs/docs/en/flow-engine/add-sub-model.md
Used to add sub-models (subModel) to a specified FlowModel. Supports async loading, grouping, submenus, custom model inheritance rules, and various other configuration options.
interface AddSubModelButtonProps {
model: FlowModel;
subModelKey: string;
subModelType?: 'object' | 'array';
items?: SubModelItemsType;
subModelBaseClass?: string | ModelConstructor;
subModelBaseClasses?: Array<string | ModelConstructor>;
afterSubModelInit?: (subModel: FlowModel) => Promise<void>;
afterSubModelAdd?: (subModel: FlowModel) => Promise<void>;
afterSubModelRemove?: (subModel: FlowModel) => Promise<void>;
children?: React.ReactNode;
keepDropdownOpen?: boolean;
}
| Parameter | Type | Description |
|---|---|---|
model | FlowModel | Required. The target model to add sub-models to. |
subModelKey | string | Required. The key name of the sub-model in model.subModels. |
subModelType | 'object' | 'array' | The data structure type of the sub-model, defaults to 'array'. |
items | SubModelItem[] | (ctx) => SubModelItem[] | Promise<...> | Menu item definitions, supports static or async generation. |
subModelBaseClass | string | ModelConstructor | Specify a base class to list all models inheriting from it as menu items. |
subModelBaseClasses | (string | ModelConstructor)[] | Specify multiple base classes to automatically list inheriting models by group. |
afterSubModelInit | (subModel) => Promise<void> | Callback after sub-model initialization. |
afterSubModelAdd | (subModel) => Promise<void> | Callback after sub-model is added. |
afterSubModelRemove | (subModel) => Promise<void> | Callback after sub-model is removed. |
children | React.ReactNode | Button content, can be customized as text or an icon. |
keepDropdownOpen | boolean | Whether to keep the dropdown menu open after adding. Automatically closes by default. |
interface SubModelItem {
key?: string;
label?: string;
type?: 'group' | 'divider';
disabled?: boolean;
hide?: boolean | ((ctx: FlowModelContext) => boolean | Promise<boolean>);
icon?: React.ReactNode;
children?: SubModelItemsType;
useModel?: string;
createModelOptions?: {
props?: Record<string, any>;
stepParams?: Record<string, any>;
};
toggleable?: boolean | ((model: FlowModel) => boolean);
}
| Field | Type | Description |
|---|---|---|
key | string | Unique identifier. |
label | string | Display text. |
type | 'group' | 'divider' | Group or divider. Omitted for regular items or submenus. |
disabled | boolean | Whether to disable the current item. |
hide | boolean | (ctx) => boolean | Promise<boolean> | Dynamic hiding (returns true to hide). |
icon | React.ReactNode | Icon content. |
children | SubModelItemsType | Submenu items, used for nested groups or submenus. |
useModel | string | Specify the Model type (registered name) to use. |
createModelOptions | object | Parameters for model initialization. |
toggleable | boolean | (model: FlowModel) => boolean | Toggle mode — removes if already added, adds if not (only allows one instance). |
<AddSubModelButton /> to Add subModels<AddSubModelButton /> to add subModels; the button must be placed inside a FlowModel to work;model.mapSubModels() to iterate over subModels; the mapSubModels method handles missing items, sorting, and other issues;<FlowModelRenderer /> to render subModels.<Button>Add block</Button>, which can be placed anywhere;<PlusOutlined />;toggleable: true is sufficient — it searches by class name by default, allowing only one instance of the same class;toggleable: (model: FlowModel) => boolean.You can get dynamic items from the context, for example:
ctx.api.request();ctx.dataSourceManager;items and children support async calls.hide supports boolean or a function (supports async); returns true to hide;type: divider renders a divider;type: group with children renders a menu group;children but no type renders a submenu.subModelBaseClass will be listed;Model.define();hide: true are automatically hidden.subModelBaseClasses will be listed;subModelBaseClasses with deduplication.menuType=submenuModel.define({ menuType: 'submenu' });meta.sort.Model.defineChildren()Model.defineChildren()children that sets searchable: true will display a search box at that level;