Skip to content

Commit

Permalink
Merge pull request #2184 from bcgov/feature/ALCS-2029-sort-improvement
Browse files Browse the repository at this point in the history
ALCS-2029 Improve sort logic
  • Loading branch information
fbarreta authored Feb 28, 2025
2 parents 141f898 + 40ae11f commit 85af483
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ export class DecisionConditionOrderDialogComponent implements OnInit {

sendToBottom(record: ApplicationDecisionConditionDto) {
const currentIndex = this.conditionsToOrder.findIndex((item) => item.uuid === record.uuid);
this.moveItem(currentIndex, this.conditionsToOrder.length - 1);
this.conditionsToOrder.sort((a,b) => a.order - b.order).forEach((item) => {
if (item.order > currentIndex) {
item.order--;
}
});
this.conditionsToOrder[currentIndex].order = this.conditionsToOrder.length;
this.dataSource.data = this.conditionsToOrder.sort((a,b) => a.order - b.order);
this.overlayRef?.detach();
this.selectedRecord = undefined;
}
Expand All @@ -101,8 +107,18 @@ export class DecisionConditionOrderDialogComponent implements OnInit {
}

private moveItem(currentIndex: number, targetIndex: number) {
this.conditionsToOrder.sort((a,b) => a.order - b.order).forEach((item) => {
if (currentIndex > targetIndex) {
if (item.order < currentIndex && item.order >= targetIndex) {
item.order++;
}
} else if (item.order > currentIndex) {
if (item.order <= targetIndex) {
item.order--;
}
}
});
this.conditionsToOrder[currentIndex].order = targetIndex;
this.conditionsToOrder[targetIndex].order = currentIndex;
this.dataSource.data = this.conditionsToOrder.sort((a,b) => a.order - b.order);
}

Expand Down

0 comments on commit 85af483

Please sign in to comment.