Skip to content

Commit 284545b

Browse files
authored
fix(core): Values are not retained after saving for 'Else Do this' block (#73)
* fix(core): fix retain else block fix retain else block on edit button GH-71 * fix(core): review chnages review chnages in fix of else column GH-71 * fix(core): fix of undefined value fix of value GH-71
1 parent 86c77a3 commit 284545b

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

projects/workflows-creator/src/lib/builder/builder.component.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,42 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
202202
});
203203
});
204204
this.updateDiagram();
205+
this.hideElseBlockIfRequired();
205206
}
206207
}
208+
/**
209+
* This function checks if the else block should be hidden based on the type and number of events in
210+
* the event group.
211+
*/
212+
213+
hideElseBlockIfRequired() {
214+
const events = this.eventGroups[0].children;
215+
const firstEvent = events[0]?.node;
216+
217+
if (events.length !== 1 || !firstEvent) {
218+
this.elseBlockHidden = false;
219+
return;
220+
}
221+
222+
// let value = firstEvent.state.get('value');
223+
let value = events.length > 0 ? firstEvent?.state.get('value') : undefined;
224+
225+
if (typeof value === 'object') {
226+
value = value.value;
227+
}
228+
229+
const eventType = firstEvent.getIdentifier();
230+
const eventValue = firstEvent.state.get('value');
231+
const eventValueType = firstEvent.state.get('valueType');
232+
233+
this.elseBlockHidden =
234+
eventType === EventTypes.OnIntervalEvent ||
235+
eventType === EventTypes.OnAddItemEvent ||
236+
(eventType === EventTypes.OnChangeEvent &&
237+
(eventValue === ValueTypes.AnyValue ||
238+
eventValueType === ValueTypes.AnyValue));
239+
}
240+
207241
/**
208242
* If the group is an event, add it to the eventGroups array, otherwise if it's an action, add it to
209243
* the actionGroups array
@@ -273,6 +307,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
273307
});
274308
this.updateDiagram();
275309
this.updateState(action.node, action.newNode.inputs);
310+
this.hideElseBlockIfRequired();
276311
}
277312
/**
278313
* The function is called when an item is changed in the UI. It emits an event to the parent
@@ -286,16 +321,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
286321
item: item.element.node,
287322
});
288323
this.updateState(item.element.node, item.element.inputs);
289-
// TODO: to be refactored
290-
// to hide else block when anything is selected in ValueInput or ValueTypeInput
291-
this.elseBlockHidden =
292-
this.eventGroups[0].children?.length === 1 &&
293-
this.eventGroups[0].children[0].node.getIdentifier() ===
294-
EventTypes.OnChangeEvent &&
295-
(this.eventGroups[0].children[0].node.state.get('value') ===
296-
ValueTypes.AnyValue ||
297-
this.eventGroups[0].children[0].node.state.get('valueType') ===
298-
ValueTypes.AnyValue);
324+
this.hideElseBlockIfRequired();
299325
this.updateDiagram();
300326
}
301327
/**

projects/workflows-element/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"access": "public",
1818
"directory": "dist"
1919
},
20-
"hash": "b3becb84440a55958bc16f9caf46b27fe1c7aab612e7fee3df4539591abee228"
20+
"hash": "2de169ac759548f51f2397daa81b6187fa75d7ca99c31f0f14e9ab95335919fb"
2121
}
2222

0 commit comments

Comments
 (0)