From e988691d0a683479b1f17e789082388b01bdf87a Mon Sep 17 00:00:00 2001 From: Vito Date: Thu, 7 Jun 2018 14:25:57 +0100 Subject: [PATCH] [ADF-3120] fixed sorting for tasklist and process list (#3435) * [ADF-3120] fixed sorting for tasklist and process list * [ADF-3120] removed commented code * [ADF-3120] fixing another randomly failing test --- .../task-attachment-list.component.spec.ts | 2 +- .../components/process-list.component.html | 2 +- .../components/process-list.component.spec.ts | 6 ------ .../components/process-list.component.ts | 16 ++++++++-------- .../components/task-list.component.html | 2 +- .../components/task-list.component.spec.ts | 6 ------ .../task-list/components/task-list.component.ts | 16 ++++++++-------- 7 files changed, 19 insertions(+), 31 deletions(-) diff --git a/lib/process-services/attachment/task-attachment-list.component.spec.ts b/lib/process-services/attachment/task-attachment-list.component.spec.ts index a21ad07e4d..d337493775 100644 --- a/lib/process-services/attachment/task-attachment-list.component.spec.ts +++ b/lib/process-services/attachment/task-attachment-list.component.spec.ts @@ -214,7 +214,7 @@ describe('TaskAttachmentList', () => { })); let change = new SimpleChange(null, '123', true); component.ngOnChanges({ 'taskId': change }); - + fixture.detectChanges(); fixture.whenStable().then(() => { fixture.detectChanges(); expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER'); diff --git a/lib/process-services/process-list/components/process-list.component.html b/lib/process-services/process-list/components/process-list.component.html index 6a1dcb4056..8d0fecea57 100644 --- a/lib/process-services/process-list/components/process-list.component.html +++ b/lib/process-services/process-list/components/process-list.component.html @@ -1,6 +1,6 @@ { expect(component.getCurrentId()).toBeNull(); }); - it('should return the sorting order if sort is defined', () => { - component.sort = 'fakeKey-fakeOrder'; - fixture.detectChanges(); - expect(component.dataSort).toEqual(['fakeKey', 'fakeOrder']); - }); - it('should return selected true for the selected process', () => { component.data = new ObjectDataTableAdapter( [ diff --git a/lib/process-services/process-list/components/process-list.component.ts b/lib/process-services/process-list/components/process-list.component.ts index 2965f8532b..ec0285ec31 100644 --- a/lib/process-services/process-list/components/process-list.component.ts +++ b/lib/process-services/process-list/components/process-list.component.ts @@ -174,10 +174,18 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit ngOnChanges(changes: SimpleChanges) { if (this.isPropertyChanged(changes)) { + if (this.isSortChanged(changes)) { + this.sorting = this.sort ? this.sort.split('-') : this.sorting; + } this.reload(); } } + private isSortChanged(changes: SimpleChanges): boolean { + const actualSort = changes['sort']; + return actualSort && actualSort.currentValue && actualSort.currentValue !== actualSort.previousValue; + } + private isPropertyChanged(changes: SimpleChanges): boolean { let changed: boolean = false; @@ -293,14 +301,6 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit } } - /** - * Sort the process based on current value of 'sort' property - * Return the sorting order - */ - get dataSort(): any[] { - return this.sort ? this.sort.split('-') : this.sorting; - } - /** * Return the current id */ diff --git a/lib/process-services/task-list/components/task-list.component.html b/lib/process-services/task-list/components/task-list.component.html index 08498d67ce..57f1c51854 100644 --- a/lib/process-services/task-list/components/task-list.component.html +++ b/lib/process-services/task-list/components/task-list.component.html @@ -4,7 +4,7 @@ [data]="data" [rows]="rows" [columns]="columns" - [sorting]="dataSort" + [sorting]="sorting" [loading]="isLoading" [selectFirstRow]="selectFirstRow" [multiselect]="multiselect" diff --git a/lib/process-services/task-list/components/task-list.component.spec.ts b/lib/process-services/task-list/components/task-list.component.spec.ts index 8db7943f7b..664ef3f329 100644 --- a/lib/process-services/task-list/components/task-list.component.spec.ts +++ b/lib/process-services/task-list/components/task-list.component.spec.ts @@ -230,12 +230,6 @@ describe('TaskListComponent', () => { expect(component.getCurrentId()).toBeNull(); }); - it('should return the sorting order if sort is defined', () => { - component.sort = 'fakeKey-fakeOrder'; - fixture.detectChanges(); - expect(component.dataSort).toEqual(['fakeKey', 'fakeOrder']); - }); - it('should return selected id for the selected task', () => { component.rows = [ { id: '999', name: 'Fake-name' }, diff --git a/lib/process-services/task-list/components/task-list.component.ts b/lib/process-services/task-list/components/task-list.component.ts index 462bb668ea..8d9040cca1 100644 --- a/lib/process-services/task-list/components/task-list.component.ts +++ b/lib/process-services/task-list/components/task-list.component.ts @@ -183,10 +183,18 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft ngOnChanges(changes: SimpleChanges) { if (this.isPropertyChanged(changes)) { + if (this.isSortChanged(changes)) { + this.sorting = this.sort ? this.sort.split('-') : this.sorting; + } this.reload(); } } + private isSortChanged(changes: SimpleChanges): boolean { + const actualSort = changes['sort']; + return actualSort && actualSort.currentValue && actualSort.currentValue !== actualSort.previousValue; + } + private isPropertyChanged(changes: SimpleChanges): boolean { let changed: boolean = true; @@ -262,14 +270,6 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft } } - /** - * Return the sorting order - * Sort the tasks based on current value of 'sort' property - */ - get dataSort(): any[] { - return this.sort ? this.sort.split('-') : this.sorting; - } - /** * Return the current id */