Skip to content

Commit

Permalink
fix(core): resolved customise bug
Browse files Browse the repository at this point in the history
resolved customise column issue of workflow

GH-41
  • Loading branch information
Deepika516 committed Feb 14, 2024
1 parent 3c806c8 commit e240b0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 45 deletions.
59 changes: 16 additions & 43 deletions projects/workflows-creator/src/lib/builder/builder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {AbstractBaseGroup} from '../classes/nodes';
import {BuilderService, ElementService, NodeService} from '../classes/services';
import {EventTypes, LocalizedStringKeys, NodeTypes, ValueTypes} from '../enum';
import {InvalidEntityError} from '../errors/base.error';

import {
ActionAddition,
ActionWithInput,
Expand All @@ -41,7 +40,6 @@ import {
} from '../types';
import {LocalizationProviderService} from '../services/localization-provider.service';
import {LocalizationPipe} from '../pipes/localization.pipe';

@Component({
selector: 'workflow-builder',
templateUrl: './builder.component.html',
Expand All @@ -60,8 +58,9 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
private readonly elements: ElementService<E>,
private readonly cdr: ChangeDetectorRef,
private readonly localizationSvc: LocalizationProviderService,
) {}

) {
this.localizationSvc.setLocalizedStrings(this.localizedStringMap);
}
private _state: StateMap<RecordOfAnyType> = {};
public get state(): StateMap<RecordOfAnyType> {
return this._state;
Expand All @@ -70,7 +69,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
public set state(value: StateMap<RecordOfAnyType>) {
this._state = value;
}

private _localizedStringMap: RecordOfAnyType = {};
public get localizedStringMap() {
return this._localizedStringMap;
Expand All @@ -79,10 +77,8 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
public set localizedStringMap(value: RecordOfAnyType) {
this._localizedStringMap = value;
}

@Input()
public diagram: string = '';

private _templateMap: {
[key: string]: TemplateRef<RecordOfAnyType>;
};
Expand All @@ -101,30 +97,22 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
public get allColumns() {
return this._allColumns;
}

@Output()
stateChange = new EventEmitter<StateMap<RecordOfAnyType>>();

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

@Output()
eventAdded = new EventEmitter<EventAddition<E>>();

@Output()
actionAdded = new EventEmitter<ActionAddition<E>>();

@Output()
itemChanged = new EventEmitter<InputChanged<E>>();

selectedElseActions: ActionWithInput<E>[] = [];
selectedEvents: EventWithInput<E>[] = [];
selectedActions: ActionWithInput<E>[] = [];

eventGroups: AbstractBaseGroup<E>[] = [];
actionGroups: AbstractBaseGroup<E>[] = [];
elseActionGroups: AbstractBaseGroup<E>[] = [];

nodeList: AbstractBaseGroup<E>[] = [];
processId: string;
// sonarignore:start
Expand All @@ -133,13 +121,18 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
elseBlockHidden = false;
elseBlockRemoved = false;
public types = NodeTypes;

localizedStringKeys = LocalizedStringKeys;

/**
* We're getting all the groups from the node service, and then we're adding them to the list of groups
*/
ngOnInit(): void {
this.initiateNode();
}
initiateNode() {
this.localizationSvc.setLocalizedStrings(this.localizedStringMap);
this.eventGroups = [];
this.actionGroups = [];
this.elseActionGroups = [];
this.nodes
.getGroups(true, NodeTypes.EVENT)
.forEach(group => this.onGroupAdd(group));
Expand All @@ -149,21 +142,23 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
this.nodes
.getGroups(true, NodeTypes.ACTION, true)
.forEach(group => this.elseActionGroups.push(group));

this.localizationSvc.setLocalizedStrings(this.localizedStringMap);
this.cdr.detectChanges();
}

/**
* > If the diagram and state have changed, restore the diagram and state from the builder
* @param {SimpleChanges} changes - SimpleChanges - the changes that have occurred in the component
*/
async ngOnChanges(changes: SimpleChanges) {
if (changes['localizedStringMap'] && this.localizedStringMap) {
this.localizationSvc.setLocalizedStrings(this.localizedStringMap);
this.initiateNode();
this.updateDiagram();
}
if (changes['diagram'] && changes['state'] && this.diagram && this.state) {
const {events, actions, elseActions, groups, process, state} =
await this.builder.restore(this.diagram);
this.processId = process.id;
this.selectedActions = actions;
this.selectedActions = actions;
this.selectedEvents = events;
this.selectedElseActions = elseActions;
if (this.selectedActions.length) this.actionGroups = [];
Expand Down Expand Up @@ -203,12 +198,7 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
});
this.updateDiagram();
}
if (changes['localizedStringMap'] && this.localizedStringMap) {
this.localizationSvc.setLocalizedStrings(this.localizedStringMap);
this.updateDiagram();
}
}

/**
* 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 All @@ -223,7 +213,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
throw new Error('Invalid Group');
}
}

/**
* The function takes in an index number, and then removes the event group at that index from the
* eventGroups array
Expand All @@ -232,11 +221,9 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
onGroupRemove(index: number) {
this.eventGroups.splice(index, 1);
}

removeElseBlock() {
this.elseBlockRemoved = true;
}

/**
* The function is called when an event is added to the workflow. It emits an eventAdded event,
* updates the diagram, updates the state, and shows the else block
Expand All @@ -254,14 +241,12 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
(event.node.getIdentifier() === EventTypes.OnIntervalEvent ||
event.node.getIdentifier() === EventTypes.OnAddItemEvent);
}

/**
* 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 ||
Expand All @@ -270,7 +255,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
(events[0].node.state.get('value') === ValueTypes.AnyValue ||
events[0].node.state.get('valueType') === ValueTypes.AnyValue)));
}

/**
* When an action is added, emit an event with the name of the action and the action itself, update
* the diagram, and update the state of the action
Expand All @@ -284,7 +268,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
this.updateDiagram();
this.updateState(action.node, action.newNode.inputs);
}

/**
* The function is called when an item is changed in the UI. It emits an event to the parent
* component, updates the state of the item, and updates the diagram
Expand All @@ -309,7 +292,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
ValueTypes.AnyValue);
this.updateDiagram();
}

/**
* "If the type is a group, then get the groups, otherwise throw an error."
*
Expand All @@ -323,7 +305,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
throw new InvalidEntityError('' + type);
}
}

/**
* It takes a state object, merges it with the current state, and then loops through the state object
* and adds the values to the inputs
Expand Down Expand Up @@ -361,7 +342,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
});
this.cdr.detectChanges();
}

/**
* It takes a node, an input, a value, and a boolean, and if the boolean is true and the input is a
* select input, it sets the node's state to the value's listNameField, emits an event, sets the
Expand Down Expand Up @@ -401,7 +381,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
this.updateState(element.node, element.inputs);
this.updateDiagram();
}

/**
* It takes the state of the workflow and creates a new statement from it
* @returns A function that takes a state and returns a boolean.
Expand All @@ -412,7 +391,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
if (this.processId) {
statement.processId = this.processId;
}

[...this.eventGroups, ...this.actionGroups].forEach(group => {
if (group.name === 'and') {
group.children
Expand Down Expand Up @@ -442,7 +420,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
throw new Error('Invalid Node type');
}
});

if (this.elseActionGroups[0].children.length > 0) {
this.elseActionGroups.forEach(group => {
group.children
Expand All @@ -457,7 +434,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
}
return this.builder.build(statement, elseStatement);
}

/**
* It builds a new diagram, emits the new diagram, and then tells Angular to update the view
*/
Expand All @@ -466,7 +442,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
this.diagramChange.emit(this.diagram);
this.cdr.detectChanges();
}

/**
* It updates the state of the workflow
* @param node - WorkflowNode<E> - The node that is being updated.
Expand All @@ -488,7 +463,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
}
this.stateChange.emit(this.state);
}

/**
* > If the user has already entered data for a subsequent input, remove it
* @param element - NodeWithInput<E>
Expand All @@ -509,7 +483,6 @@ export class BuilderComponent<E> implements OnInit, OnChanges {
element.node.state.remove(`${nextKey}Name`);
}
}

/**
* It takes two objects, and merges the second object into the first object
* @param stateA - The state that is currently in the store.
Expand Down
4 changes: 2 additions & 2 deletions projects/workflows-element/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"access": "public",
"directory": "dist"
},
"hash": "c36a84f0e5452b8cb9611769c2fdaca50fc2399bde3214b6a2c0cb327644ccd4"
}
"hash": "01d1d33b78cc9d44c2c5427e055968cdcce3fc69e693611974be19246ddb0b37"
}

0 comments on commit e240b0b

Please sign in to comment.