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

feat(core): changes condition script for passed by and coming in clauses #14

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(add)="openPopup(types.GROUP)"
(remove)="onGroupRemove(i)"
(eventAdded)="onEventAdded($event)"
(eventRemoved)="onEventRemoved()"
(nodeRemoved)="onNodeRemoved()"
(actionAdded)="onActionAdded($event)"
(itemChanged)="onItemChanged($event)"
></workflow-group>
Expand All @@ -29,6 +29,7 @@
[templateMap]="templateMap"
[allColumns]="allColumns"
(eventAdded)="onEventAdded($event)"
(nodeRemoved)="onNodeRemoved()"
(actionAdded)="onActionAdded($event)"
(itemChanged)="onItemChanged($event)"
></workflow-group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
}
.container {
min-width: 46%;
min-width: 52%;
max-width: max-content;
color: rgb(50, 51, 56);
margin: auto;
Expand Down
143 changes: 119 additions & 24 deletions projects/workflows-creator/src/lib/builder/builder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ import {
} from '../classes';
import {AbstractBaseGroup} from '../classes/nodes';
import {BuilderService, ElementService, NodeService} from '../classes/services';
import {EventTypes, LocalizedStringKeys, NodeTypes, ValueTypes} from '../enum';
import {
ActionTypes,
ConditionTypes,
EventTypes,
LocalizedStringKeys,
NUMBER,
NodeTypes,
NotificationRecipientTypesEnum,
ValueTypes,
} from '../enum';
import {InvalidEntityError} from '../errors/base.error';
import {
ActionAddition,
Expand All @@ -38,6 +47,11 @@ import {
WorkflowNode,
} from '../types';
import {LocalizationProviderService} from '../services/localization-provider.service';
import {
ReadColumnValue,
TriggerWhenColumnChanges,
} from '../services/bpmn/elements/tasks';
import {GatewayElement} from '../services/bpmn/elements/gateways';

@Component({
selector: 'workflow-builder',
Expand Down Expand Up @@ -78,7 +92,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
stateChange = new EventEmitter<StateMap<RecordOfAnyType>>();

@Output()
diagramChange = new EventEmitter<string>();
diagramChange = new EventEmitter<Object>();

@Output()
eventAdded = new EventEmitter<EventAddition<E>>();
Expand Down Expand Up @@ -217,7 +231,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
this.updateDiagram();
this.updateState(event.node, event.newNode.inputs);
this.elseBlockHidden =
!this.eventGroups[0]?.children?.length &&
this.eventGroups[0]?.children?.length === 1 &&
(event.node.getIdentifier() === EventTypes.OnIntervalEvent ||
event.node.getIdentifier() === EventTypes.OnAddItemEvent);
}
Expand All @@ -226,16 +240,9 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
* The function is called when an event is removed from the workflow.
* Hides the else block when it is not needed.
*/
onEventRemoved() {
const events = this.eventGroups[0].children;

this.elseBlockHidden =
events.length === 1 &&
(events[0].node.getIdentifier() === EventTypes.OnIntervalEvent ||
events[0].node.getIdentifier() === EventTypes.OnAddItemEvent ||
(events[0].node.getIdentifier() === EventTypes.OnChangeEvent &&
(events[0].node.state.get('value') === ValueTypes.AnyValue ||
events[0].node.state.get('valueType') === ValueTypes.AnyValue)));
onNodeRemoved() {
this.updateDiagram();
if (this.eventGroups[0]?.children?.length) this.hideElseBlockIfRequired();
}

/**
Expand Down Expand Up @@ -264,19 +271,32 @@ 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();
}

/**
* 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 type is a group, then get the groups, otherwise throw an error."
*
Expand Down Expand Up @@ -346,6 +366,31 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
value: AllowedValues | AllowedValuesMap,
select = false,
) {
if (
(input.getIdentifier() === 'ValueTypeInput' ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should ideally not have any reference to input type here in this component

input.getIdentifier() === 'ValueInput') &&
element.node.getIdentifier() === 'OnChangeEvent'
) {
if (
((value as AllowedValuesMap)?.value as AllowedValuesMap)?.value ===
ValueTypes.AnyValue ||
(value as AllowedValuesMap)?.value === ValueTypes.AnyValue
) {
/**
* Remove node on changes event
*/
element.node.elements.splice(-NUMBER.TWO, NUMBER.TWO);
// element.inputs[1].prefix = '';
//this.enableActionIcon = false;
} else {
element.node.elements = [
TriggerWhenColumnChanges.identifier,
ReadColumnValue.identifier,
GatewayElement.identifier,
];
}
}

if (select && isSelectInput(input)) {
element.node.state.change(
`${input.inputKey}Name`,
Expand Down Expand Up @@ -429,8 +474,58 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
* It builds a new diagram, emits the new diagram, and then tells Angular to update the view
*/
async updateDiagram() {
const nodes = [
...this.eventGroups[0].children,
...this.actionGroups[0].children,
...this.elseActionGroups[0].children,
];
let isValid =
!!this.eventGroups[0].children.length &&
(!!this.actionGroups[0].children.length ||
!!this.elseActionGroups[0].children.length);
if (isValid) {
for (const node of nodes) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for validation, we can use a separate service that gets the current state of diagram and just returns true or false and use that here, and this should be based on the default inputs provided. Anyone using the library should be able to replace it to write there own logic according to there own custom events/actions/inputs

switch (node.node.getIdentifier()) {
case EventTypes.OnChangeEvent:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned, the builder component should not have any code specific to event types

case EventTypes.OnValueEvent:
case ActionTypes.ChangeColumnValueAction:
const columnExists = !!node.node.state.get('column');
const valueExists =
node.node.state.get('condition') === ConditionTypes.PastToday
? true
: !!node.node.state.get('value');
const valueTypeIsSufficient = [
ValueTypes.AnyValue,
ValueTypes.Today,
ValueTypes.PastToday,
].includes(node.node.state.get('valueType'));
isValid = columnExists && (valueExists || valueTypeIsSufficient);
break;
case EventTypes.OnIntervalEvent:
const intervalExists = !!node.node.state.get('interval');
const intervalValueExists = !!node.node.state.get('value');
isValid = intervalValueExists && intervalExists;
break;
case ActionTypes.SendEmailAction:
const email = !!node.node.state.get('email');
const emailTo = !!node.node.state.get('emailTo');
const specificRecipientsRequired = [
NotificationRecipientTypesEnum.NotifySpecificColumn,
NotificationRecipientTypesEnum.NotifySpecificPeople,
].includes(node.node.state.get('emailTo'));
const recipients = !!node.node.state.get('specificRecepient');
isValid = specificRecipientsRequired
? email && emailTo && recipients
: email && emailTo;
break;
}
if (!isValid) {
break; // exit the loop since we found an invalid input
}
}
}
this.diagram = await this.build();
this.diagramChange.emit(this.diagram);
this.diagramChange.emit({diagram: this.diagram, isValid: isValid});
this.cdr.detectChanges();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@
emailInput: emailInput,
appendEmailBody: appendEmailBody,
setFocusKey: setFocusKey,
hide: hidePopper()
hide: hidePopper(),
setFocusOutPos: setFocusOutPos
}
"
></ng-container>
Expand Down Expand Up @@ -284,6 +285,7 @@
let-appendEmailBody="appendEmailBody"
let-setFocusKey="setFocusKey"
let-hide="hide"
let-setFocusOutPos="setFocusOutPos"
>
<div class="email-template" (document:click)="hide()">
<input
Expand All @@ -292,14 +294,15 @@
id="email-subject"
autofocus
(focus)="setFocusKey(emailInput, 'subject')"
(focusout)="setFocusOutPos(emailInput, $event.target.selectionStart)"
[placeholder]="typeSubjectPlaceholder"
[(ngModel)]="emailInput.subject"
/>
<textarea
[placeholder]="typeEmailPlaceholder"
id="email-body"
class="email-input email-body-input"
(focus)="setFocusKey(emailInput, 'body')"
(focusout)="setFocusOutPos(emailInput, $event.target.selectionStart)"
[(ngModel)]="emailInput.body"
></textarea>
<div class="auto-populate">
Expand All @@ -315,7 +318,7 @@
(click)="callback(emailInput)"
[disabled]="!emailInput.subject || !emailInput.body"
>
{{ localizedStringKeys.SetLbl | localization }}
{{ setLbl }}
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
.value-text {
display: inline-block;
overflow: hidden;
max-width: 45%;
max-width: 15rem;
text-decoration: inherit;
text-overflow: ellipsis;
vertical-align: top;
Expand Down
Loading