Skip to content

Commit 6328186

Browse files
committed
front: newAllowances: fix bug on empty allowances on first launch
1 parent c399fdc commit 6328186

File tree

1 file changed

+12
-10
lines changed
  • front/src/applications/operationalStudies/components/ManageTrainSchedule/Allowances

1 file changed

+12
-10
lines changed

front/src/applications/operationalStudies/components/ManageTrainSchedule/Allowances/helpers.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ export function findAllowanceOverlap({
1616
const after = allowances.findIndex(
1717
(allowance) => endPosition >= allowance.begin_position && endPosition <= allowance.end_position
1818
);
19-
return [
20-
before !== currentAllowanceSelected &&
21-
// Could be BEFORE the first allowance
22-
(beginPosition < allowances[0].begin_position ? 0 : before),
23-
after !== currentAllowanceSelected &&
24-
// Could be AFTER the last allowance
25-
(endPosition > allowances[allowances.length - 1].end_position
26-
? allowances.length - 1
27-
: after),
28-
];
19+
return allowances.length > 0
20+
? [
21+
before !== currentAllowanceSelected &&
22+
// Could be BEFORE the first allowance
23+
(beginPosition < allowances[0].begin_position ? 0 : before),
24+
after !== currentAllowanceSelected &&
25+
// Could be AFTER the last allowance
26+
(endPosition > allowances[allowances.length - 1].end_position
27+
? allowances.length - 1
28+
: after),
29+
]
30+
: [-1, -1];
2931
}
3032

3133
export default function getAllowanceValue(value?: AllowanceValue) {

0 commit comments

Comments
 (0)