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

Commit 9aefcab

Browse files
committed
Fixes a bug in sorting when reservationUnits title is empty
1 parent eabe5b2 commit 9aefcab

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

admin-ui/src/component/ReservationUnits/ReservationUnitEditor/SortedSelect.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ function SortedSelect<T>(
1212
const opts = [...originalOptions];
1313
if (props.sort) {
1414
opts.sort((a, b) =>
15-
a.label.toLowerCase().localeCompare(b.label.toLowerCase())
15+
a.label && b.label
16+
? a.label.toLowerCase().localeCompare(b.label.toLowerCase())
17+
: !a.label
18+
? 1
19+
: -1
1620
);
1721
}
1822
return opts;

admin-ui/src/component/my-units/UnitCalendar.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,13 @@ const Events = ({
294294
);
295295

296296
const sortByDraftStatusAndTitle = (resources: Resource[]) => {
297-
return resources.sort(
298-
(a, b) =>
299-
Number(a.isDraft) - Number(b.isDraft) || a.title.localeCompare(b.title)
300-
);
297+
return resources.sort((a, b) => {
298+
const draftComparison = Number(a.isDraft) - Number(b.isDraft);
299+
const titleComparison =
300+
a.title && b.title ? a.title.localeCompare(b.title) : !a.title ? 1 : -1;
301+
302+
return draftComparison || titleComparison;
303+
});
301304
};
302305

303306
const ResourceCalendar = ({ resources }: Props): JSX.Element => {

0 commit comments

Comments
 (0)