Skip to content

Commit

Permalink
fix(core): fix retain else block
Browse files Browse the repository at this point in the history
fix retain else block on edit button

GH-71
  • Loading branch information
Deepika516 committed Mar 1, 2024
1 parent a91ebd7 commit d54b8be
Show file tree
Hide file tree
Showing 2 changed files with 85,334 additions and 102,084 deletions.
35 changes: 25 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,31 @@ 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;
let value = events[0].node.state.get('value');
if (typeof value === 'object') {
value = value.value;
}
if (events.length !== 1) {
this.elseBlockHidden = false;
} else {
this.elseBlockHidden =
events[0].node.getIdentifier() === EventTypes.OnIntervalEvent ||
events[0].node.getIdentifier() === EventTypes.OnAddItemEvent ||
(events[0].node.getIdentifier() === EventTypes.OnChangeEvent &&
(value === ValueTypes.AnyValue ||
events[0].node.state.get('valueType') === 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 +296,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 +310,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
Loading

0 comments on commit d54b8be

Please sign in to comment.