mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[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:
parent
c28e23b1cb
commit
32a3f9c9ef
@ -408,6 +408,15 @@ describe('TaskFormCloudComponent', () => {
|
||||
|
||||
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', () => {
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
import {
|
||||
Component, EventEmitter, Input, OnChanges,
|
||||
Output, SimpleChanges, OnInit, ViewEncapsulation
|
||||
Output, SimpleChanges, OnInit, ViewEncapsulation, OnDestroy
|
||||
} from '@angular/core';
|
||||
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
|
||||
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 { DropdownCloudWidgetComponent } from '../../../form/components/widgets/dropdown/dropdown-cloud.widget';
|
||||
import { DateCloudWidgetComponent } from '../../../form/components/widgets/date/date-cloud.widget';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-cloud-task-form',
|
||||
@ -32,7 +34,7 @@ import { DateCloudWidgetComponent } from '../../../form/components/widgets/date/
|
||||
styleUrls: ['./task-form-cloud.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class TaskFormCloudComponent implements OnInit, OnChanges {
|
||||
export class TaskFormCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
|
||||
/** App id to fetch corresponding form and values. */
|
||||
@Input()
|
||||
@ -104,12 +106,16 @@ export class TaskFormCloudComponent implements OnInit, OnChanges {
|
||||
@Output()
|
||||
executeOutcome = new EventEmitter<FormOutcomeEvent>();
|
||||
|
||||
@Output()
|
||||
onTaskLoaded = new EventEmitter<TaskDetailsCloudModel>(); /* eslint-disable-line */
|
||||
|
||||
taskDetails: TaskDetailsCloudModel;
|
||||
|
||||
candidateUsers: string[] = [];
|
||||
candidateGroups: string[] = [];
|
||||
|
||||
loading: boolean = false;
|
||||
onDestroy$ = new Subject<boolean>();
|
||||
|
||||
constructor(
|
||||
private taskCloudService: TaskCloudService,
|
||||
@ -141,12 +147,12 @@ export class TaskFormCloudComponent implements OnInit, OnChanges {
|
||||
|
||||
private loadTask() {
|
||||
this.loading = true;
|
||||
|
||||
this.taskCloudService
|
||||
.getTaskById(this.appName, this.taskId)
|
||||
.getTaskById(this.appName, this.taskId).pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe(details => {
|
||||
this.taskDetails = details;
|
||||
this.loading = false;
|
||||
this.onTaskLoaded.emit(this.taskDetails);
|
||||
});
|
||||
|
||||
this.taskCloudService
|
||||
@ -229,4 +235,9 @@ export class TaskFormCloudComponent implements OnInit, OnChanges {
|
||||
onFormExecuteOutcome(outcome: FormOutcomeEvent) {
|
||||
this.executeOutcome.emit(outcome);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.onDestroy$.next(true);
|
||||
this.onDestroy$.complete();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user