Skip to content

Commit 9044c16

Browse files
authored
Merge pull request #656 from RealZimboGuy/feature/state-graph-indicating-workflow-progress
enhance graph to indicate workflow steps and show active state
2 parents d49b381 + defe3c1 commit 9044c16

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Support Azure AD authentication in Explorer (see nflow-explorer/src/config.js for configuration options)
1313
- Improve REST API error response handling
1414
- Sort state variables by name
15+
- indicate workflow states used in graph and show active state in graph
1516
- Use ReactJS 18.x, material UI 5.x
1617
- Replace Create React App -build by Vite
1718
- `nflow-engine`

nflow-explorer/src/component/StateGraph.jsx

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,53 @@ import './StateGraph.scss';
2020
// - zoom and pan state graph
2121

2222
// TODO move to service.ts?
23-
function createGraph(definition) {
23+
function createGraph(props) {
2424
const g = new dagreD3.graphlib.Graph().setGraph({});
25-
const states = definition.states;
25+
const states = props.definition.states;
2626
// create nodes
2727
for (let state of states) {
2828
g.setNode(state.id, {label: state.id, class: `node-${state.type}`});
2929
// Round the corners of the nodes
3030
const node = g.node(state.id);
3131
node.rx = node.ry = 5;
32+
33+
//if instance is provided, highlight with the .active
34+
//
35+
if (props.instance && props.instance.state === state.id) {
36+
node.class += ' current-state';
37+
38+
}
39+
40+
}
41+
42+
function hasNavigatedState(fromState, toState, instance) {
43+
//reverse iterate through the actions,
44+
//when we have two actions in sequence that match the from state and the to state we return true
45+
const actions = instance.actions;
46+
47+
for (let i = 0; i < actions.length - 1; i++) {
48+
// Check if the current action state matches the toState (since it's reversed)
49+
if (actions[i].state === toState && actions[i + 1].state === fromState) {
50+
return true;
51+
}
52+
}
53+
if(actions[0].state == fromState && toState == instance.state){
54+
//this is the final state where there is no action showing
55+
return true;
56+
}
57+
58+
return false;
3259
}
3360

3461
// create edges between nodes
3562
for (let state of states) {
3663
for (let transition of state.transitions || []) {
64+
var hasNavigated = false;
65+
if (props.instance) {
66+
hasNavigated = hasNavigatedState(state.id, transition, props.instance);
67+
}
3768
g.setEdge(state.id, transition, {
38-
class: 'edge-normal',
69+
class: 'edge-normal' + (hasNavigated ? ' active' : ''),
3970
curve: d3.curveBasis,
4071
arrowhead: 'normal'
4172
});
@@ -46,8 +77,8 @@ function createGraph(definition) {
4677
curve: d3.curveBasis,
4778
arrowhead: 'normal'
4879
});
49-
} else if (definition.onError) {
50-
g.setEdge(state.id, definition.onError, {
80+
} else if (props.definition.onError) {
81+
g.setEdge(state.id, props.definition.onError, {
5182
class: 'edge-error',
5283
curve: d3.curveBasis,
5384
arrowhead: 'normal'
@@ -84,8 +115,8 @@ function render(g, selector) {
84115

85116
function StateGraph(props) {
86117
useEffect(() => {
87-
console.info('StateGraph', props.definition);
88-
const g = createGraph(props.definition);
118+
console.info('StateGraph', props);
119+
const g = createGraph(props);
89120
render(g, 'svg#stategraph');
90121
return () => {
91122
// Remove svg element which is created in render(), since it is not managed by React

nflow-explorer/src/component/StateGraph.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
.edge-error.active,
133133
.edge-failure.active .edge-unexpected {
134134
stroke-width: 2px;
135+
stroke: blue;
135136
}
136137

137138
.edge-normal.selected,
@@ -166,6 +167,8 @@
166167
/* */
167168
g.current-state > g > g > text {
168169
text-decoration: underline;
170+
fill: blue;
171+
font-weight: bold;
169172
}
170173

171174
/*

nflow-explorer/src/workflow-instance/WorkflowInstanceDetailsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ const InstanceSummary = ({
161161
</Grid>
162162
</Grid>
163163
<Grid item xs={6} lg={6}>
164-
<StateGraph definition={definition} />
164+
<StateGraph definition={definition} instance={instance} />
165165
</Grid>
166166
</Grid>
167167
</Grid>

0 commit comments

Comments
 (0)