Skip to content

Commit 52d6098

Browse files
committed
Use only order to re-order items
- Index not needed - Simplify updating/sorting
1 parent 0280886 commit 52d6098

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
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

+8-18
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,20 @@ export class DecisionConditionOrderDialogComponent implements OnInit {
8989
}
9090

9191
sendToBottom(record: ApplicationDecisionConditionDto) {
92-
const currentIndex = this.conditionsToOrder.findIndex((item) => item.uuid === record.uuid);
93-
this.conditionsToOrder
94-
.sort((a, b) => a.order - b.order)
95-
.forEach((item) => {
96-
if (item.order > currentIndex) {
97-
item.order--;
98-
}
99-
});
100-
this.conditionsToOrder[currentIndex].order = this.conditionsToOrder.length;
92+
this.conditionsToOrder.forEach((item) => {
93+
item.order--;
94+
});
95+
record.order = this.conditionsToOrder.length - 1;
10196
this.dataSource.data = this.conditionsToOrder.sort((a, b) => a.order - b.order);
10297
this.overlayRef?.detach();
10398
this.selectedRecord = undefined;
10499
}
105100

106101
sendToTop(record: ApplicationDecisionConditionDto) {
107-
const currentIndex = this.conditionsToOrder.findIndex((item) => item.uuid === record.uuid);
108-
this.conditionsToOrder
109-
.sort((a, b) => a.order - b.order)
110-
.forEach((item) => {
111-
if (item.order < currentIndex) {
112-
item.order++;
113-
}
114-
});
115-
this.conditionsToOrder[currentIndex].order = 0;
102+
this.conditionsToOrder.forEach((item) => {
103+
item.order++;
104+
});
105+
record.order = 0;
116106
this.dataSource.data = this.conditionsToOrder.sort((a, b) => a.order - b.order);
117107
this.overlayRef?.detach();
118108
this.selectedRecord = undefined;

0 commit comments

Comments
 (0)