[AAE-3563] getTaskById API is called multiple times when a task from … (#7877)

* [AAE-3563] getTaskById API is called multiple times when a task from cloud is opened

* Changes done as oer comments

* Added unit test

* Fixed eslint

* Resolved UT
This commit is contained in:
Sushmitha V 2022-10-27 16:52:43 +05:30 committed by GitHub
parent c28e23b1cb
commit 32a3f9c9ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -408,6 +408,15 @@ describe('TaskFormCloudComponent', () => {
expect(executeOutcomeSpy).toHaveBeenCalled(); expect(executeOutcomeSpy).toHaveBeenCalled();
}); });
it('should emit onTaskLoaded on initial load of component', () => {
component.appName = '';
spyOn(component.onTaskLoaded, 'emit');
component.ngOnInit();
fixture.detectChanges();
expect(component.onTaskLoaded.emit).toHaveBeenCalledWith(taskDetails);
});
}); });
it('should display task name as title on no form template if showTitle is true', () => { it('should display task name as title on no form template if showTitle is true', () => {

View File

@ -17,7 +17,7 @@
import { import {
Component, EventEmitter, Input, OnChanges, Component, EventEmitter, Input, OnChanges,
Output, SimpleChanges, OnInit, ViewEncapsulation Output, SimpleChanges, OnInit, ViewEncapsulation, OnDestroy
} from '@angular/core'; } from '@angular/core';
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model'; import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
import { TaskCloudService } from '../../services/task-cloud.service'; import { TaskCloudService } from '../../services/task-cloud.service';
@ -25,6 +25,8 @@ import { FormRenderingService, FormModel, ContentLinkModel, FormOutcomeEvent } f
import { AttachFileCloudWidgetComponent } from '../../../form/components/widgets/attach-file/attach-file-cloud-widget.component'; import { AttachFileCloudWidgetComponent } from '../../../form/components/widgets/attach-file/attach-file-cloud-widget.component';
import { DropdownCloudWidgetComponent } from '../../../form/components/widgets/dropdown/dropdown-cloud.widget'; import { DropdownCloudWidgetComponent } from '../../../form/components/widgets/dropdown/dropdown-cloud.widget';
import { DateCloudWidgetComponent } from '../../../form/components/widgets/date/date-cloud.widget'; import { DateCloudWidgetComponent } from '../../../form/components/widgets/date/date-cloud.widget';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
@Component({ @Component({
selector: 'adf-cloud-task-form', selector: 'adf-cloud-task-form',
@ -32,7 +34,7 @@ import { DateCloudWidgetComponent } from '../../../form/components/widgets/date/
styleUrls: ['./task-form-cloud.component.scss'], styleUrls: ['./task-form-cloud.component.scss'],
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class TaskFormCloudComponent implements OnInit, OnChanges { export class TaskFormCloudComponent implements OnInit, OnChanges, OnDestroy {
/** App id to fetch corresponding form and values. */ /** App id to fetch corresponding form and values. */
@Input() @Input()
@ -104,12 +106,16 @@ export class TaskFormCloudComponent implements OnInit, OnChanges {
@Output() @Output()
executeOutcome = new EventEmitter<FormOutcomeEvent>(); executeOutcome = new EventEmitter<FormOutcomeEvent>();
@Output()
onTaskLoaded = new EventEmitter<TaskDetailsCloudModel>(); /* eslint-disable-line */
taskDetails: TaskDetailsCloudModel; taskDetails: TaskDetailsCloudModel;
candidateUsers: string[] = []; candidateUsers: string[] = [];
candidateGroups: string[] = []; candidateGroups: string[] = [];
loading: boolean = false; loading: boolean = false;
onDestroy$ = new Subject<boolean>();
constructor( constructor(
private taskCloudService: TaskCloudService, private taskCloudService: TaskCloudService,
@ -141,12 +147,12 @@ export class TaskFormCloudComponent implements OnInit, OnChanges {
private loadTask() { private loadTask() {
this.loading = true; this.loading = true;
this.taskCloudService this.taskCloudService
.getTaskById(this.appName, this.taskId) .getTaskById(this.appName, this.taskId).pipe(takeUntil(this.onDestroy$))
.subscribe(details => { .subscribe(details => {
this.taskDetails = details; this.taskDetails = details;
this.loading = false; this.loading = false;
this.onTaskLoaded.emit(this.taskDetails);
}); });
this.taskCloudService this.taskCloudService
@ -229,4 +235,9 @@ export class TaskFormCloudComponent implements OnInit, OnChanges {
onFormExecuteOutcome(outcome: FormOutcomeEvent) { onFormExecuteOutcome(outcome: FormOutcomeEvent) {
this.executeOutcome.emit(outcome); this.executeOutcome.emit(outcome);
} }
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
} }