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

Commit 93aa06a

Browse files
committed
Fixes based on PR comments
1 parent 9aefcab commit 93aa06a

3 files changed

Lines changed: 8 additions & 10 deletions

File tree

admin-ui/src/common/util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,6 @@ export const combineResults = (
390390

391391
return combined;
392392
};
393+
394+
export const sortByName = (a?: string, b?: string): number =>
395+
a && b ? a.toLowerCase().localeCompare(b.toLowerCase()) : !a ? 1 : -1;

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import { useTranslation } from "react-i18next";
33
import memoize from "lodash/memoize";
44
import { Select, SelectProps } from "hds-react";
5+
import { sortByName } from "../../../common/util";
56

67
function SortedSelect<T>(
78
props: Partial<SelectProps<T>> & { sort?: boolean; label: string }
@@ -11,13 +12,7 @@ function SortedSelect<T>(
1112
const sortedOpts = memoize((originalOptions) => {
1213
const opts = [...originalOptions];
1314
if (props.sort) {
14-
opts.sort((a, b) =>
15-
a.label && b.label
16-
? a.label.toLowerCase().localeCompare(b.label.toLowerCase())
17-
: !a.label
18-
? 1
19-
: -1
20-
);
15+
opts.sort((a, b) => sortByName(a.label, b.label));
2116
}
2217
return opts;
2318
})(props.options);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import resourceEventStyleGetter, {
1919
PRE_PAUSE,
2020
} from "./resourceEventStyleGetter";
2121
import { getReserveeName } from "../reservations/requested/util";
22+
import { sortByName } from "../../common/util";
2223

2324
export type Resource = {
2425
title: string;
@@ -295,9 +296,8 @@ const Events = ({
295296

296297
const sortByDraftStatusAndTitle = (resources: Resource[]) => {
297298
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;
299+
const draftComparison: number = Number(a.isDraft) - Number(b.isDraft);
300+
const titleComparison = sortByName(a.title, b.title);
301301

302302
return draftComparison || titleComparison;
303303
});

0 commit comments

Comments
 (0)