Skip to content

Commit

Permalink
Merge pull request #2027 from bcgov/feature/ALCS-2441
Browse files Browse the repository at this point in the history
Fix Sorting in Multiple Date Table in Conditions for Applications and NOIs
  • Loading branch information
Abradat authored Dec 17, 2024
2 parents f78af93 + ca66660 commit 0f509af
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h4 *ngIf="condition.type">{{ stringIndex }}. {{ condition.type.label }}</h4>
</ng-container>

<ng-container matColumnDef="due">
<th mat-header-cell *matHeaderCellDef mat-sort-header class="multiple-due">Due</th>
<th mat-header-cell *matHeaderCellDef class="multiple-due">Due</th>
<td mat-cell *matCellDef="let element">
<app-inline-datepicker
[value]="condition.dates[element.index - 1].date ?? undefined"
Expand All @@ -158,7 +158,7 @@ <h4 *ngIf="condition.type">{{ stringIndex }}. {{ condition.type.label }}</h4>
</ng-container>

<ng-container matColumnDef="completed">
<th mat-header-cell *matHeaderCellDef mat-sort-header class="multiple-completed">Completed</th>
<th mat-header-cell *matHeaderCellDef class="multiple-completed">Completed</th>
<td mat-cell *matCellDef="let element">
<app-inline-datepicker
[value]="condition.dates[element.index - 1].completedDate ?? undefined"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export class ConditionComponent implements OnInit, AfterViewInit {

this.loadLots();
this.loadPlanNumber();
this.dataSource = new MatTableDataSource<ApplicationDecisionConditionDateWithIndex>(this.addIndex(this.dates));
this.dataSource = new MatTableDataSource<ApplicationDecisionConditionDateWithIndex>(
this.addIndex(this.sortDates(this.dates)),
);
}
}

Expand Down Expand Up @@ -251,9 +253,11 @@ export class ConditionComponent implements OnInit, AfterViewInit {

sortDates(data: ApplicationDecisionConditionDateDto[]): ApplicationDecisionConditionDateDto[] {
return data.sort((a, b) => {
const dateA = a.date || a.completedDate || new Date(0);
const dateB = b.date || b.completedDate || new Date(0);
return new Date(dateA).getTime() - new Date(dateB).getTime();
if (a.date == null && b.date == null) return 0;
if (a.date == null) return 1;
if (b.date == null) return -1;

return new Date(a.date).getTime() - new Date(b.date).getTime();
});
}

Expand All @@ -262,7 +266,9 @@ export class ConditionComponent implements OnInit, AfterViewInit {

if (newDate) {
this.dates.push(newDate);
this.dataSource = new MatTableDataSource<ApplicationDecisionConditionDateWithIndex>(this.addIndex(this.dates));
this.dataSource = new MatTableDataSource<ApplicationDecisionConditionDateWithIndex>(
this.addIndex(this.sortDates(this.dates)),
);
}
}

Expand All @@ -281,6 +287,9 @@ export class ConditionComponent implements OnInit, AfterViewInit {

const response = await this.conditionService.updateDate(dateUuid, updatedDto);
this.dates[index] = response;
this.dataSource = new MatTableDataSource<ApplicationDecisionConditionDateWithIndex>(
this.addIndex(this.sortDates(this.dates)),
);
} else {
console.error('Date with specified UUID not found');
}
Expand All @@ -293,7 +302,9 @@ export class ConditionComponent implements OnInit, AfterViewInit {

if (index !== -1) {
this.dates.splice(index, 1);
this.dataSource = new MatTableDataSource<ApplicationDecisionConditionDateWithIndex>(this.addIndex(this.dates));
this.dataSource = new MatTableDataSource<ApplicationDecisionConditionDateWithIndex>(
this.addIndex(this.sortDates(this.dates)),
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h4 *ngIf="condition.type">{{ stringIndex }}. {{ condition.type.label }}</h4>
</ng-container>

<ng-container matColumnDef="due">
<th mat-header-cell *matHeaderCellDef mat-sort-header class="multiple-due">Due</th>
<th mat-header-cell *matHeaderCellDef class="multiple-due">Due</th>
<td mat-cell *matCellDef="let element">
<app-inline-datepicker
[value]="condition.dates[element.index - 1].date ?? undefined"
Expand All @@ -105,7 +105,7 @@ <h4 *ngIf="condition.type">{{ stringIndex }}. {{ condition.type.label }}</h4>
</ng-container>

<ng-container matColumnDef="completed">
<th mat-header-cell *matHeaderCellDef mat-sort-header class="multiple-completed">Completed</th>
<th mat-header-cell *matHeaderCellDef class="multiple-completed">Completed</th>
<td mat-cell *matCellDef="let element">
<app-inline-datepicker
[value]="condition.dates[element.index - 1].completedDate ?? undefined"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ export class ConditionComponent implements OnInit, AfterViewInit {
};

this.isThreeColumn = this.showAdmFeeField && this.showSecurityAmountField;
this.dataSource = new MatTableDataSource<NoticeOfIntentDecisionConditionDateWithIndex>(this.addIndex(this.dates));
this.dataSource = new MatTableDataSource<NoticeOfIntentDecisionConditionDateWithIndex>(
this.addIndex(this.sortDates(this.dates)),
);
}
}

Expand Down Expand Up @@ -167,9 +169,11 @@ export class ConditionComponent implements OnInit, AfterViewInit {

sortDates(data: NoticeOfIntentDecisionConditionDateDto[]): NoticeOfIntentDecisionConditionDateDto[] {
return data.sort((a, b) => {
const dateA = a.date || a.completedDate || new Date(0);
const dateB = b.date || b.completedDate || new Date(0);
return new Date(dateA).getTime() - new Date(dateB).getTime();
if (a.date == null && b.date == null) return 0;
if (a.date == null) return 1;
if (b.date == null) return -1;

return new Date(a.date).getTime() - new Date(b.date).getTime();
});
}

Expand All @@ -178,7 +182,9 @@ export class ConditionComponent implements OnInit, AfterViewInit {

if (newDate) {
this.dates.push(newDate);
this.dataSource = new MatTableDataSource<NoticeOfIntentDecisionConditionDateWithIndex>(this.addIndex(this.dates));
this.dataSource = new MatTableDataSource<NoticeOfIntentDecisionConditionDateWithIndex>(
this.addIndex(this.sortDates(this.dates)),
);
}
}

Expand All @@ -197,6 +203,9 @@ export class ConditionComponent implements OnInit, AfterViewInit {

const response = await this.conditionService.updateDate(dateUuid, updatedDto);
this.dates[index] = response;
this.dataSource = new MatTableDataSource<NoticeOfIntentDecisionConditionDateWithIndex>(
this.addIndex(this.sortDates(this.dates)),
);
} else {
console.error('Date with specified UUID not found');
}
Expand All @@ -210,7 +219,7 @@ export class ConditionComponent implements OnInit, AfterViewInit {
if (index !== -1) {
this.dates.splice(index, 1);
this.dataSource = new MatTableDataSource<NoticeOfIntentDecisionConditionDateWithIndex>(
this.addIndex(this.dates),
this.addIndex(this.sortDates(this.dates)),
);
}
}
Expand Down

0 comments on commit 0f509af

Please sign in to comment.