Skip to content

Commit

Permalink
fix(core): Values are not retained after saving for 'Else Do this' bl…
Browse files Browse the repository at this point in the history
…ock (#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
  • Loading branch information
Deepika516 authored Mar 26, 2024
1 parent 86c77a3 commit 284545b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
46 changes: 36 additions & 10 deletions projects/workflows-creator/src/lib/builder/builder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,42 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
});
});
this.updateDiagram();
this.hideElseBlockIfRequired();
}
}
/**
* This function checks if the else block should be hidden based on the type and number of events in
* the event group.
*/

hideElseBlockIfRequired() {
const events = this.eventGroups[0].children;
const firstEvent = events[0]?.node;

if (events.length !== 1 || !firstEvent) {
this.elseBlockHidden = false;
return;
}

// let value = firstEvent.state.get('value');
let value = events.length > 0 ? firstEvent?.state.get('value') : undefined;

if (typeof value === 'object') {
value = value.value;
}

const eventType = firstEvent.getIdentifier();
const eventValue = firstEvent.state.get('value');
const eventValueType = firstEvent.state.get('valueType');

this.elseBlockHidden =
eventType === EventTypes.OnIntervalEvent ||
eventType === EventTypes.OnAddItemEvent ||
(eventType === EventTypes.OnChangeEvent &&
(eventValue === ValueTypes.AnyValue ||
eventValueType === ValueTypes.AnyValue));
}

/**
* If the group is an event, add it to the eventGroups array, otherwise if it's an action, add it to
* the actionGroups array
Expand Down Expand Up @@ -273,6 +307,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
});
this.updateDiagram();
this.updateState(action.node, action.newNode.inputs);
this.hideElseBlockIfRequired();
}
/**
* The function is called when an item is changed in the UI. It emits an event to the parent
Expand All @@ -286,16 +321,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
item: item.element.node,
});
this.updateState(item.element.node, item.element.inputs);
// TODO: to be refactored
// to hide else block when anything is selected in ValueInput or ValueTypeInput
this.elseBlockHidden =
this.eventGroups[0].children?.length === 1 &&
this.eventGroups[0].children[0].node.getIdentifier() ===
EventTypes.OnChangeEvent &&
(this.eventGroups[0].children[0].node.state.get('value') ===
ValueTypes.AnyValue ||
this.eventGroups[0].children[0].node.state.get('valueType') ===
ValueTypes.AnyValue);
this.hideElseBlockIfRequired();
this.updateDiagram();
}
/**
Expand Down
2 changes: 1 addition & 1 deletion projects/workflows-element/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"access": "public",
"directory": "dist"
},
"hash": "b3becb84440a55958bc16f9caf46b27fe1c7aab612e7fee3df4539591abee228"
"hash": "2de169ac759548f51f2397daa81b6187fa75d7ca99c31f0f14e9ab95335919fb"
}

0 comments on commit 284545b

Please sign in to comment.