-
Notifications
You must be signed in to change notification settings - Fork 13
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(StopPageDepartures): Omit uncommon Green Line branches/headsigns with no upcoming service #1786
feat(StopPageDepartures): Omit uncommon Green Line branches/headsigns with no upcoming service #1786
Conversation
79516bb
to
3eb9895
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a bunch of comments, but they're all "I would have done this differently" minor refactoring suggestions. It all makes sense and looks good.
} from "../stop/stop-redesign-loader"; | ||
import { DepartureInfo } from "./departureInfo"; | ||
|
||
type RoutePatternGroup = GroupedRoutePatterns[keyof GroupedRoutePatterns]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this file should define
export interface RoutePatternWithPolyline
extends Omit<RoutePattern, "representative_trip_polyline"> {
representative_trip_polyline: Polyline;
}
export type RoutePatternId = string; // I'm assuming the groups are by id but maybe it's by headsign?
export type RoutePatternGroup = Record<
RoutePatternId,
{
direction_id: DirectionId;
route_patterns: RoutePatternWithPolyline[];
},
>;
export type GroupedRoutePatterns = Record<string, RoutePatternGroup>;
and stop-redesign-loader
should reference this file. The types were defined there before cuz that's where they were used, but having this general model file reference that specific use case seems backwards.
Also, there's two layers of grouping RoutePatternGroup
and GroupedRoutePatterns
, and it's unclear what the difference is. Type aliases for the string keys could help, or putting some hint in the type name could help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the group keys to be references to the relevant objects (Route["id"]
and RoutePattern["headsign"]
in this case) and the end result should be way cleaner, thanks a million 🥳
export type RoutePatternGroupEntries = [ | ||
keyof RoutePatternGroup, | ||
RoutePatternGroup[keyof RoutePatternGroup] | ||
][]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a pattern you expect to use again, you could consider defining in some util file somewhere (maybe helpers/object.ts
)
export type ValueOf<T extends Object> = T[keyof T];
export type Entries<T extends Object> = [keyof T, ValueOf<T>];
].map(([, { route_patterns: routePatterns }]) => | ||
Math.min(...routePatterns.map(rp => rp.sort_order)) | ||
); | ||
return orderA - orderB; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would lodash
sortBy()
work for this?
return isNonCanonical && departures.length === 0; | ||
}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Sometimes the reason for disabling a lint rule is obvious, but this one isn't, and could use a comment.
@@ -19,24 +19,10 @@ const DepartureCard = ({ | |||
}: { | |||
alertsForRoute: Alert[]; | |||
departuresForRoute: DepartureInfo[]; | |||
routePatternsByHeadsign: GroupedRoutePatterns[keyof GroupedRoutePatterns]; | |||
routePatternsByHeadsign: RoutePatternGroupEntries; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR moves the filtering+sorting out of this component and into the caller. That means that it needs to take the entries type now instead of the record type, which I think is a bit more awkward. I tend to prefer passing around the more data-like record type as long as possible, and only transform it to the display-like sorted list as late as possible to be closer to where it's displayed (though this is a very loose rule and there could be good reasons I don't see to do the processing earlier).
|
||
const isNoncanonicalAndNoDepartures = ( | ||
routePatterns: RoutePatternWithPolyline[], | ||
departures: DepartureInfo[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't work purely on route patterns, it also uses departure info, so maybe it shouldn't belong in the general models/route-patterns
file. This calculation is pretty specific to what you want to show on the stops page, so maybe it should go with the stops page components instead.
8730c68
to
e539877
Compare
minBy(routePatterns, "sort_order")?.sort_order | ||
); | ||
|
||
export default { sortedGroupedRoutePatterns }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed when the definition above already has export const sortedGroupedRoutePatterns
?
e539877
to
61fa99e
Compare
Summary of changes
Asana Ticket: Omit uncommon Green Line branches/headsigns with no upcoming service
There are a couple extra commits because our code wasn't using the V3 API's
canonical
attribute for route patterns. Most of this PR's file changes are due to this.The main part of this PR, in the final commit, checks the
canonical
value for subway route patterns against the list of departures to determine whether to hide a specific headsign. Additionally, if all the headsigns for a given route card end up hidden, the route card itself will also be hidden.Before and After:
In the early morning when the other Green Line branches run trains this way, those schedules/predictions should show up on this page, though I haven't captured a screenshot for this yet.
General checks