Skip to content

Commit

Permalink
fix(core): resolve Valid workflow issues (#47)
Browse files Browse the repository at this point in the history
resolve issues so that it can create valid workflow

GH-42
  • Loading branch information
Deepika516 authored Feb 16, 2024
1 parent 1776c3b commit 8f2571d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
57 changes: 54 additions & 3 deletions projects/workflows-creator/src/lib/builder/builder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ import {
} from '../classes';
import {AbstractBaseGroup} from '../classes/nodes';
import {BuilderService, ElementService, NodeService} from '../classes/services';
import {EventTypes, LocalizedStringKeys, NodeTypes, ValueTypes} from '../enum';
import {
ActionTypes,
EventTypes,
LocalizedStringKeys,
NodeTypes,
NotificationRecipientTypesEnum,
ValueTypes,
} from '../enum';
import {InvalidEntityError} from '../errors/base.error';
import {
ActionAddition,
Expand Down Expand Up @@ -100,7 +107,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
@Output()
stateChange = new EventEmitter<StateMap<RecordOfAnyType>>();
@Output()
diagramChange = new EventEmitter<string>();
diagramChange = new EventEmitter<Object>();
@Output()
eventAdded = new EventEmitter<EventAddition<E>>();
@Output()
Expand Down Expand Up @@ -437,8 +444,52 @@ 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) {
switch (node.node.getIdentifier()) {
case EventTypes.OnChangeEvent:
case EventTypes.OnValueEvent:
case ActionTypes.ChangeColumnValueAction:
const columnExists = !!node.node.state.get('column');
const valueExists = !!node.node.state.get('value');
const valueTypeIsAnyValue =
node.node.state.get('valueType') === ValueTypes.AnyValue;
isValid = columnExists && (valueExists || valueTypeIsAnyValue);
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
5 changes: 5 additions & 0 deletions projects/workflows-creator/src/lib/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export enum EventTypes {
OnValueEvent = 'OnValueEvent',
}

export enum ActionTypes {
ChangeColumnValueAction = 'ChangeColumnValueAction',
SendEmailAction = 'SendEmailAction',
}

export enum StartElementTypes {
BasicStartElement = 'StartElement',
StartOnIntervalElement = 'StartOnIntervalElement',
Expand Down

0 comments on commit 8f2571d

Please sign in to comment.