Skip to content

Commit

Permalink
Fixes based on PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wuahi committed Dec 14, 2022
1 parent 9aefcab commit 93aa06a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
3 changes: 3 additions & 0 deletions admin-ui/src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,6 @@ export const combineResults = (

return combined;
};

export const sortByName = (a?: string, b?: string): number =>
a && b ? a.toLowerCase().localeCompare(b.toLowerCase()) : !a ? 1 : -1;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { useTranslation } from "react-i18next";
import memoize from "lodash/memoize";
import { Select, SelectProps } from "hds-react";
import { sortByName } from "../../../common/util";

function SortedSelect<T>(
props: Partial<SelectProps<T>> & { sort?: boolean; label: string }
Expand All @@ -11,13 +12,7 @@ function SortedSelect<T>(
const sortedOpts = memoize((originalOptions) => {
const opts = [...originalOptions];
if (props.sort) {
opts.sort((a, b) =>
a.label && b.label
? a.label.toLowerCase().localeCompare(b.label.toLowerCase())
: !a.label
? 1
: -1
);
opts.sort((a, b) => sortByName(a.label, b.label));
}
return opts;
})(props.options);
Expand Down
6 changes: 3 additions & 3 deletions admin-ui/src/component/my-units/UnitCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import resourceEventStyleGetter, {
PRE_PAUSE,
} from "./resourceEventStyleGetter";
import { getReserveeName } from "../reservations/requested/util";
import { sortByName } from "../../common/util";

export type Resource = {
title: string;
Expand Down Expand Up @@ -295,9 +296,8 @@ const Events = ({

const sortByDraftStatusAndTitle = (resources: Resource[]) => {
return resources.sort((a, b) => {
const draftComparison = Number(a.isDraft) - Number(b.isDraft);
const titleComparison =
a.title && b.title ? a.title.localeCompare(b.title) : !a.title ? 1 : -1;
const draftComparison: number = Number(a.isDraft) - Number(b.isDraft);
const titleComparison = sortByName(a.title, b.title);

return draftComparison || titleComparison;
});
Expand Down

0 comments on commit 93aa06a

Please sign in to comment.