Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Elevator Screens #529

Merged
merged 9 commits into from
Oct 25, 2024
17 changes: 13 additions & 4 deletions assets/js/components/Dashboard/PlaceRowAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ import ScreenDetail from "Components/ScreenDetail";
import { sortScreens } from "../../util";
import { useUpdateAnimation } from "Hooks/useUpdateAnimation";
import classNames from "classnames";
import _ from "lodash";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were using lodash/fp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes thank you. (Although I dislike how bad it is at inferring types 😅)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is a notable downside of FP and maybe something we should have considered (if we'd had a better sense for it at the time) in our conversations about which "utility library" to use. I tend to avoid Lodash entirely and use vanilla JS where feasible, since built-in classes and functions have generally excellent types (except for you, JSON.parse, you're not invited to the party).


type ScreenGroup = {
screens: Screen[];
isInline: boolean;
};

const groupScreens = (screens: Screen[]): ScreenGroup[] => {
const inlineScreenTypes = ["busway_v2", "solari", "elevator_v2"];

const inlineScreens = screens.filter((screen) =>
["busway_v2", "solari", "elevator_v2"].includes(screen.type),
inlineScreenTypes.includes(screen.type),
);
const paEssScreens = screens.filter((screen) => screen.type === "pa_ess");
const otherScreens = screens.filter(
(screen) =>
!["busway_v2", "pa_ess", "solari", "elevator_v2"].includes(screen.type),
(screen) => ![...inlineScreenTypes, "pa_ess"].includes(screen.type),
);

const groups = otherScreens.map((screen) => ({
Expand All @@ -37,7 +39,14 @@ const groupScreens = (screens: Screen[]): ScreenGroup[] => {
}));

if (inlineScreens.length > 0) {
groups.push({ screens: inlineScreens, isInline: true });
const groupedInlineScreens = _.chain(inlineScreens)
.groupBy((screen) => screen.type)
.map((screens, _) => screens)
.value();

groupedInlineScreens.forEach((screens) =>
groups.push({ screens: screens, isInline: true }),
);
}

if (paEssScreens.length > 0) {
Expand Down
Loading