Skip to content

Commit 85af483

Browse files
authored
Merge pull request #2184 from bcgov/feature/ALCS-2029-sort-improvement
ALCS-2029 Improve sort logic
2 parents 141f898 + 40ae11f commit 85af483

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

alcs-frontend/src/app/features/application/decision/decision-v2/decision-input/decision-conditions/decision-condition-order-dialog/decision-condition-order-dialog.component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ export class DecisionConditionOrderDialogComponent implements OnInit {
7777

7878
sendToBottom(record: ApplicationDecisionConditionDto) {
7979
const currentIndex = this.conditionsToOrder.findIndex((item) => item.uuid === record.uuid);
80-
this.moveItem(currentIndex, this.conditionsToOrder.length - 1);
80+
this.conditionsToOrder.sort((a,b) => a.order - b.order).forEach((item) => {
81+
if (item.order > currentIndex) {
82+
item.order--;
83+
}
84+
});
85+
this.conditionsToOrder[currentIndex].order = this.conditionsToOrder.length;
86+
this.dataSource.data = this.conditionsToOrder.sort((a,b) => a.order - b.order);
8187
this.overlayRef?.detach();
8288
this.selectedRecord = undefined;
8389
}
@@ -101,8 +107,18 @@ export class DecisionConditionOrderDialogComponent implements OnInit {
101107
}
102108

103109
private moveItem(currentIndex: number, targetIndex: number) {
110+
this.conditionsToOrder.sort((a,b) => a.order - b.order).forEach((item) => {
111+
if (currentIndex > targetIndex) {
112+
if (item.order < currentIndex && item.order >= targetIndex) {
113+
item.order++;
114+
}
115+
} else if (item.order > currentIndex) {
116+
if (item.order <= targetIndex) {
117+
item.order--;
118+
}
119+
}
120+
});
104121
this.conditionsToOrder[currentIndex].order = targetIndex;
105-
this.conditionsToOrder[targetIndex].order = currentIndex;
106122
this.dataSource.data = this.conditionsToOrder.sort((a,b) => a.order - b.order);
107123
}
108124

0 commit comments

Comments
 (0)