Skip to content

Commit bda6e52

Browse files
committed
add else node
1 parent 8d1e928 commit bda6e52

9 files changed

Lines changed: 154 additions & 1 deletion

File tree

packages/flow-design/src/components/design-editor/components/branch-adder/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export const BranchAdderRender: React.FC<BranchAdderProps> = (props) => {
3636
operation.addBlock(
3737
node,
3838
block,
39+
{
40+
index: block.data.order - 1,
41+
}
3942
);
4043
setTimeout(() => {
4144
handleClose();

packages/flow-design/src/components/design-editor/components/node-icon/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export const NodeIcon: React.FC<NodeIconProps> = (props) => {
4141
if (icon === 'CONDITION_BRANCH') {
4242
return <BranchesOutlined style={style}/>
4343
}
44+
if (icon === 'CONDITION_ELSE_BRANCH') {
45+
return <BranchesOutlined style={style}/>
46+
}
4447
if (icon === 'DELAY') {
4548
return <ClockCircleOutlined style={style}/>
4649
}
@@ -62,6 +65,9 @@ export const NodeIcon: React.FC<NodeIconProps> = (props) => {
6265
if (icon === 'INCLUSIVE_BRANCH') {
6366
return <MergeOutlined style={style}/>
6467
}
68+
if (icon === 'INCLUSIVE_ELSE_BRANCH') {
69+
return <MergeOutlined style={style}/>
70+
}
6571
if (icon === 'NOTIFY') {
6672
return <BellOutlined style={style}/>
6773
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {provideJsonSchemaOutputs, syncVariableTitle,} from '@flowgram.ai/form-materials';
2+
import {FormMeta, FormRenderProps, ValidateTrigger,} from '@flowgram.ai/fixed-layout-editor';
3+
4+
import {FlowNodeJSON} from '../../typings';
5+
import {NodePanel} from "@/components/design-editor/node-components/panel";
6+
import React from "react";
7+
import {NodeIcon} from "@/components/design-editor/components/node-icon";
8+
import {Space} from "antd";
9+
10+
export const renderForm = (data: FormRenderProps<FlowNodeJSON['data']>) => {
11+
return (
12+
<NodePanel data={data}>
13+
<Space style={
14+
{
15+
width: 100,
16+
textAlign: 'center',
17+
padding: 5
18+
}
19+
}
20+
>
21+
<NodeIcon type={"CONDITION_ELSE_BRANCH"}/>
22+
<span>其他情况</span>
23+
</Space>
24+
</NodePanel>
25+
);
26+
};
27+
28+
export const formMeta: FormMeta<FlowNodeJSON['data']> = {
29+
render: renderForm,
30+
validateTrigger: ValidateTrigger.onChange,
31+
validate: {
32+
title: ({value}: { value: string }) => (value ? undefined : 'Title is required'),
33+
},
34+
effect: {
35+
title: syncVariableTitle,
36+
outputs: provideJsonSchemaOutputs,
37+
},
38+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {FlowNodeRegistry} from '../../typings';
2+
import {formMeta} from './form-meta';
3+
import {nanoid} from "nanoid";
4+
5+
export const ConditionElseBranchNodeRegistry: FlowNodeRegistry = {
6+
type: 'CONDITION_ELSE_BRANCH',
7+
extend: 'block',
8+
meta: {
9+
copyDisable: true,
10+
addDisable: true,
11+
deleteDisable: true,
12+
sidebarDisable:true,
13+
style:{
14+
width: '100%',
15+
}
16+
},
17+
info: {
18+
icon: 'CONDITION_ELSE_BRANCH',
19+
description: '分支else节点',
20+
},
21+
/**
22+
* Render node via formMeta
23+
*/
24+
formMeta,
25+
onAdd(ctx, from) {
26+
return {
27+
id: `condition_branch_${nanoid(5)}`,
28+
type: 'CONDITION_ELSE_BRANCH',
29+
data: {
30+
title: `条件else分支节点`,
31+
value: 'branch Value'
32+
},
33+
};
34+
}
35+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {provideJsonSchemaOutputs, syncVariableTitle,} from '@flowgram.ai/form-materials';
2+
import {FormMeta, FormRenderProps, ValidateTrigger,} from '@flowgram.ai/fixed-layout-editor';
3+
4+
import {FlowNodeJSON} from '../../typings';
5+
import {NodePanel} from "@/components/design-editor/node-components/panel";
6+
import React from "react";
7+
import {NodeIcon} from "@/components/design-editor/components/node-icon";
8+
import {Space} from "antd";
9+
10+
export const renderForm = (data: FormRenderProps<FlowNodeJSON['data']>) => {
11+
12+
return (
13+
<NodePanel data={data}>
14+
<Space style={
15+
{
16+
width: 100,
17+
textAlign: 'center',
18+
padding: 5
19+
}
20+
}
21+
>
22+
<NodeIcon type={"INCLUSIVE_ELSE_BRANCH"}/>
23+
<span>其他情况</span>
24+
</Space>
25+
</NodePanel>
26+
);
27+
};
28+
29+
export const formMeta: FormMeta<FlowNodeJSON['data']> = {
30+
render: renderForm,
31+
validateTrigger: ValidateTrigger.onChange,
32+
validate: {
33+
title: ({value}: { value: string }) => (value ? undefined : 'Title is required'),
34+
},
35+
effect: {
36+
title: syncVariableTitle,
37+
outputs: provideJsonSchemaOutputs,
38+
},
39+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {FlowNodeRegistry} from '../../typings';
2+
import {formMeta} from './form-meta';
3+
4+
export const InclusiveElseBranchNodeRegistry: FlowNodeRegistry = {
5+
type: 'INCLUSIVE_ELSE_BRANCH',
6+
extend: 'block',
7+
meta: {
8+
copyDisable: true,
9+
addDisable: true,
10+
sidebarDisable:true,
11+
deleteDisable: true,
12+
style:{
13+
width: '100%',
14+
}
15+
},
16+
info: {
17+
icon: 'INCLUSIVE_ELSE_BRANCH',
18+
description: '包容else分支',
19+
},
20+
/**
21+
* Render node via formMeta
22+
*/
23+
formMeta,
24+
};

packages/flow-design/src/components/design-editor/nodes/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ import {SubProcessNodeRegistry} from "@/components/design-editor/nodes/sub-proce
1616
import {TriggerNodeRegistry} from "@/components/design-editor/nodes/trigger";
1717
import {ManualNodeRegistry} from "@/components/design-editor/nodes/manual";
1818
import {ManualBranchNodeRegistry} from "@/components/design-editor/nodes/manual-branch";
19+
import {ConditionElseBranchNodeRegistry} from "@/components/design-editor/nodes/condition-else-branch";
20+
import {InclusiveElseBranchNodeRegistry} from "@/components/design-editor/nodes/inclusive-else-branch";
1921

2022
export const FlowNodeRegistries: FlowNodeRegistry[] = [
2123
ApprovalNodeRegistry,
2224
ConditionNodeRegistry,
2325
ConditionBranchNodeRegistry,
26+
ConditionElseBranchNodeRegistry,
2427
DelayNodeRegistry,
2528
EndNodeRegistry,
2629
HandleNodeRegistry,
2730
InclusiveNodeRegistry,
2831
InclusiveBranchNodeRegistry,
32+
InclusiveElseBranchNodeRegistry,
2933
ManualNodeRegistry,
3034
ManualBranchNodeRegistry,
3135
NotifyNodeRegistry,

packages/flow-design/src/components/design-panel/presenters/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class Presenter {
158158
const block = nodeManager.toItemRender(flowNode);
159159
if (currentNode) {
160160
if (currentNode.blocks) {
161-
const order = currentNode.blocks.length + 1;
161+
const order = currentNode.blocks.length;
162162
return {
163163
...block,
164164
data: {

packages/flow-types/src/types/flow-design.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export type NodeType =
88
"CONDITION" |
99
// 分支节点
1010
"CONDITION_BRANCH" |
11+
// else分支节点
12+
"CONDITION_ELSE_BRANCH" |
1113
// 延迟节点
1214
"DELAY" |
1315
// 结束
@@ -18,6 +20,8 @@ export type NodeType =
1820
"INCLUSIVE" |
1921
// 包容分支
2022
"INCLUSIVE_BRANCH" |
23+
// else包容分支
24+
"INCLUSIVE_ELSE_BRANCH" |
2125
// 人工控制
2226
"MANUAL" |
2327
// 人工分支

0 commit comments

Comments
 (0)