Skip to content

Commit

Permalink
fix: don't show times in allocation if rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed May 6, 2024
1 parent 0d6274a commit 1e93fc6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ function ApplicationSectionColumn({
>): JSX.Element {
const { t } = useTranslation();

// TODO how is Rejected supposed to be shown? or is it ever shown in this list (or any other list)?
// there are no possible actions on this page for it, but do we filter out completely or disable all actions?

// allocations are not specific to the reservation unit
const isAllocated = (as: ApplicationSectionNode) =>
as.allocations != null && as.allocations > 0;
Expand All @@ -216,6 +213,11 @@ function ApplicationSectionColumn({
.filter((ruo) => ruo.reservationUnit.pk === reservationUnit.pk)
?.map((ruo) => ruo.locked)
.some(Boolean);
const isRejected = (as: ApplicationSectionNode) =>
as.reservationUnitOptions
.filter((ruo) => ruo.reservationUnit.pk === reservationUnit.pk)
?.map((ruo) => ruo.rejected)
.some(Boolean);

const sections = filterNonNullable(applicationSections);
const allocated = sections.filter(
Expand All @@ -226,14 +228,15 @@ function ApplicationSectionColumn({
(as) =>
as.status !== ApplicationSectionStatusChoice.Handled &&
isAllocated(as) &&
!isLocked(as)
!isLocked(as) &&
!isRejected(as)
);

const locked = sections.filter((as) => isLocked(as));
const locked = sections.filter((as) => isLocked(as) || isRejected(as));

// take certain states and omit colliding application events
const unallocatedApplicationEvents = (applicationSections ?? []).filter(
(as) => !isAllocated(as)
(as) => !isAllocated(as) && !isLocked(as) && !isRejected(as)
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,31 +381,54 @@ function ApplicationRoundAllocation({
// for calendar / right hand side we do more extensive filtering later.
const applicationSections = filterNonNullable(
appEventsData?.applicationSections?.edges.map((e) => e?.node)
).filter((section) => {
const opts = section?.reservationUnitOptions?.filter((r) => {
if (r?.reservationUnit == null) {
return false;
}
if (
r.allocatedTimeSlots.filter(
(ats) => ats.reservationUnitOption?.pk === r.pk
).length > 0
) {
)
.filter((section) => {
const opts = section?.reservationUnitOptions?.filter((r) => {
if (r?.reservationUnit == null) {
return false;
}
if (
r.allocatedTimeSlots.filter(
(ats) => ats.reservationUnitOption?.pk === r.pk
).length > 0
) {
return true;
}
if (preferredOrderFilterQuery.length > 0) {
const includedInPreferredOrder =
preferredOrderFilterQuery.includes(r.preferredOrder) ||
(includePreferredOrder10OrHigher && (r.preferredOrder ?? 0) >= 10);
const orderFiltered =
includedInPreferredOrder &&
r.reservationUnit.pk === reservationUnitFilterQuery;
return orderFiltered;
}
return r?.reservationUnit.pk === reservationUnitFilterQuery;
});
return opts.length > 0;
})
.map((section) => {
// query includes locked and rejected show we can show them in the left column
// but no allocation can be made to those
// which are made using suitableTimeRanges so filter them out
const opts = section?.reservationUnitOptions?.filter((r) => {
if (r.reservationUnit.pk !== reservationUnitFilterQuery) {
return false;
}
if (r?.locked || r?.rejected) {
return false;
}
return true;
});

if (opts.length === 0) {
return {
...section,
suitableTimeRanges: [],
};
}
if (preferredOrderFilterQuery.length > 0) {
const includedInPreferredOrder =
preferredOrderFilterQuery.includes(r.preferredOrder) ||
(includePreferredOrder10OrHigher && (r.preferredOrder ?? 0) >= 10);
const orderFiltered =
includedInPreferredOrder &&
r.reservationUnit.pk === reservationUnitFilterQuery;
return orderFiltered;
}
return r?.reservationUnit.pk === reservationUnitFilterQuery;
return section;
});
return opts.length > 0;
});

const priorityOptions = ([300, 200] as const).map((n) => ({
value: n,
Expand Down

0 comments on commit 1e93fc6

Please sign in to comment.