Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Values are not retained after saving for 'Else Do this' block #73

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
rohit-sourcefuse marked this conversation as resolved.
Show resolved Hide resolved
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"
}

Loading