Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit fb153de

Browse files
committed
fix: show locked but allocated in proper section
1 parent 8aa5773 commit fb153de

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

apps/admin-ui/src/spa/recurring-reservations/application-rounds/[id]/allocation/ApplicationEvents.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ function ApplicationSectionColumn({
205205
// allocations are not specific to the reservation unit
206206
const isAllocated = (as: ApplicationSectionNode) =>
207207
as.allocations != null && as.allocations > 0;
208+
209+
const isAllocatedToThisUnit = (as: ApplicationSectionNode) =>
210+
as.reservationUnitOptions
211+
.filter((ruo) => ruo.reservationUnit.pk === reservationUnit.pk)
212+
?.map((ruo) => ruo.allocatedTimeSlots.length > 0)
213+
.some(Boolean);
214+
208215
// Locked is specific to this reservation unit
209216
const isLocked = (as: ApplicationSectionNode) =>
210217
as.reservationUnitOptions
@@ -218,19 +225,28 @@ function ApplicationSectionColumn({
218225
.some(Boolean);
219226

220227
const sections = filterNonNullable(applicationSections);
221-
const allocated = sections.filter(
222-
(as) => as.status === ApplicationSectionStatusChoice.Handled
223-
);
224228

225-
const partiallyAllocated = sections.filter(
229+
// one of:
230+
// - handled or
231+
// - allocated and here and locked
232+
const allocated = sections.filter(
226233
(as) =>
227-
as.status !== ApplicationSectionStatusChoice.Handled &&
228-
isAllocated(as) &&
229-
!isLocked(as) &&
230-
!isRejected(as)
234+
as.status === ApplicationSectionStatusChoice.Handled ||
235+
(isAllocated(as) && isAllocatedToThisUnit(as) && isLocked(as))
231236
);
232237

233-
const locked = sections.filter((as) => isLocked(as) || isRejected(as));
238+
const isPartiallyAllocated = (as: ApplicationSectionNode) =>
239+
as.status !== ApplicationSectionStatusChoice.Handled &&
240+
isAllocated(as) &&
241+
!isLocked(as) &&
242+
!isRejected(as);
243+
244+
const partiallyAllocated = sections.filter(isPartiallyAllocated);
245+
246+
// locked or rejected but not in the allocated list
247+
const locked = sections
248+
.filter((x) => allocated.find((y) => x.pk === y.pk) == null)
249+
.filter((as) => isLocked(as) || isRejected(as));
234250

235251
// take certain states and omit colliding application events
236252
const unallocatedApplicationEvents = (applicationSections ?? []).filter(

0 commit comments

Comments
 (0)