Skip to content

Commit 938e4be

Browse files
committed
add node order
1 parent da16e0d commit 938e4be

18 files changed

Lines changed: 226 additions & 60 deletions

File tree

flow-engine-framework/src/main/java/com/codingapi/flow/manager/FlowNodeState.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.Getter;
66

77
import java.util.ArrayList;
8+
import java.util.Comparator;
89
import java.util.List;
910
import java.util.stream.Stream;
1011

@@ -31,7 +32,7 @@ public FlowNodeState(IFlowNode node) {
3132
this.branchNodeTypes.add(NodeType.PARALLEL_BRANCH.name());
3233
}
3334

34-
public boolean isEndNode(){
35+
public boolean isEndNode() {
3536
return this.node.getType().equals(NodeType.END.name());
3637
}
3738

@@ -65,8 +66,8 @@ public String getName() {
6566
}
6667

6768
public List<IFlowNode> getFirstBlocks() {
68-
List<IFlowNode> blocks = this.node.blocks();
69-
if (blocks != null && !blocks.isEmpty()) {
69+
List<IFlowNode> blocks = this.node.blocks().stream().sorted(Comparator.comparingInt(IFlowNode::getOrder)).toList();
70+
if (!blocks.isEmpty()) {
7071
return Stream.of(blocks.get(0)).toList();
7172
}
7273
return new ArrayList<>();

flow-engine-framework/src/main/java/com/codingapi/flow/node/nodes/ConditionNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void addDefaultBranch(int count){
3737
List<IFlowNode> branches = new ArrayList<>();
3838
for (int i=0;i<count;i++){
3939
ConditionBranchNode branchNode = new ConditionBranchNode();
40+
branchNode.setOrder(i+1);
4041
branches.add(branchNode);
4142
}
4243
this.setBlocks(branches);

flow-engine-framework/src/main/java/com/codingapi/flow/node/nodes/InclusiveNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public void addDefaultBranch(int count){
4040
List<IFlowNode> branches = new ArrayList<>();
4141
for (int i=0;i<count;i++){
4242
InclusiveBranchNode branchNode = new InclusiveBranchNode();
43+
branchNode.setOrder(i+1);
4344
branches.add(branchNode);
4445
}
4546
this.setBlocks(branches);

flow-engine-framework/src/main/java/com/codingapi/flow/node/nodes/ParallelNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void addDefaultBranch(int count){
3838
List<IFlowNode> branches = new ArrayList<>();
3939
for (int i=0;i<count;i++){
4040
ParallelBranchNode branchNode = new ParallelBranchNode();
41+
branchNode.setOrder(i+1);
4142
branches.add(branchNode);
4243
}
4344
this.setBlocks(branches);

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

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

frontend/packages/flow-pc/flow-pc-design/src/components/design-editor/hooks/use-editor-props.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ import {FlowDocumentJSON, FlowNodeRegistry} from "@/components/design-editor/typ
1313
import {Adder} from "@/components/design-editor/components/node-adder";
1414
import {BranchAdder} from "@/components/design-editor/components/branch-adder";
1515
import {Collapse} from "../components/collapse";
16+
import {useDesignContext} from "@/components/design-panel/hooks/use-design-context";
1617

1718
export function useEditorProps(initialData: FlowDocumentJSON, nodeRegistries: FlowNodeRegistry[]): FixedLayoutProps {
1819

1920
const {token} = theme.useToken();
2021

22+
const {context} = useDesignContext();
23+
24+
const presenter = context.getPresenter();
25+
2126
return useMemo<FixedLayoutProps>(
2227
() => ({
2328
/**
@@ -150,6 +155,8 @@ export function useEditorProps(initialData: FlowDocumentJSON, nodeRegistries: Fl
150155
// Listen change to trigger auto save
151156
const data = ctx.document.toJSON();
152157
console.log('flow-engine auto save: ', data);
158+
presenter.syncNodes(data.nodes);
159+
153160
}, 100),
154161
},
155162
/**

frontend/packages/flow-pc/flow-pc-design/src/components/design-editor/node-components/header/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ export const NodeHeader: React.FC<NodeHeaderProps> = (props) => {
112112
/>
113113
)}
114114
</Field>
115+
{!isSidebar && (
116+
<Field name="order">
117+
{({field: {value, onChange}}: FieldRenderProps<string>) => {
118+
if (nodeType === 'INCLUSIVE_BRANCH' || nodeType === 'CONDITION_BRANCH' || nodeType === 'PARALLEL_BRANCH') {
119+
return (
120+
<>优先级:{value}</>
121+
)
122+
}
123+
return (
124+
<></>
125+
);
126+
}}
127+
</Field>
128+
)}
115129
</Space>
116130

117131
{isSidebar && (
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import React from "react";
22
import {GroovyScriptConvertorUtil} from "@flow-engine/flow-core";
33
import {Field, FieldRenderProps} from "@flowgram.ai/fixed-layout-editor";
4+
import {Text} from "@flow-engine/flow-pc-ui";
45

5-
interface NodeHintProps{
6-
fieldName:string;
6+
interface NodeHintProps {
7+
fieldName: string;
78
}
89

9-
export const NodeHint:React.FC<NodeHintProps> = (props) => {
10+
export const NodeHint: React.FC<NodeHintProps> = (props) => {
1011
return (
11-
<span>
12-
<Field
13-
name={props.fieldName}
14-
render={({ field: { value, onChange } }: FieldRenderProps<any>) => (
15-
<>
16-
{GroovyScriptConvertorUtil.getScriptTitle(value)}
17-
</>
18-
)}
19-
/>
20-
</span>
12+
<Field
13+
name={props.fieldName}
14+
render={({field: {value, onChange}}: FieldRenderProps<any>) => (
15+
<Text
16+
suffixCount={100}
17+
key={value}
18+
>
19+
{GroovyScriptConvertorUtil.getScriptTitle(value)}
20+
</Text>
21+
)}
22+
/>
2123
)
2224
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from "react";
2+
import {Field, FieldRenderProps} from "@flowgram.ai/fixed-layout-editor";
3+
import {Form, Input} from "antd";
4+
5+
6+
export const NodeOrder = () => {
7+
const [form] = Form.useForm();
8+
9+
return (
10+
<Form
11+
form={form}
12+
style={{
13+
width: '100%',
14+
}}
15+
layout="vertical"
16+
>
17+
<Form.Item
18+
label={"优先级"}
19+
name={"order"}
20+
tooltip={"数字越小优先级越高"}
21+
>
22+
<Field
23+
name={"order"}
24+
render={({field: {value, onChange}}: FieldRenderProps<any>) => (
25+
<Input
26+
type="number"
27+
value={value}
28+
placeholder={"请输入优先级"}
29+
onChange={(event) => {
30+
onChange(event.target.value);
31+
}}
32+
/>
33+
)}
34+
/>
35+
</Form.Item>
36+
</Form>
37+
)
38+
}

frontend/packages/flow-pc/flow-pc-design/src/components/design-editor/nodes/condition-branch/form-meta.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import {NodePanel} from "@/components/design-editor/node-components/panel";
88
import {ConditionScript} from "@/components/design-editor/node-components/condition";
99
import React from "react";
1010
import {NodeHint} from "@/components/design-editor/node-components/node-hint";
11+
import {NodeOrder} from "@/components/design-editor/node-components/node-order";
1112

1213
export const renderForm = (data: FormRenderProps<FlowNodeJSON['data']>) => {
1314
const isSidebar = useIsSidebar();
1415
if (isSidebar) {
1516
return (
1617
<NodePanel data={data}>
1718
<NodeHeader/>
19+
<NodeOrder/>
1820
<ConditionScript/>
1921
</NodePanel>
2022
);

0 commit comments

Comments
 (0)