add line filtering for alert places - #783
Conversation
rwaskiewicz
left a comment
There was a problem hiding this comment.
When testing this out, it looked like "Ferry" was auto selected as filter, which doesn't seem to be happening on main. Could you take a look?
Screen.Recording.2026-07-15.at.10.10.02.mov
| @@ -37,9 +37,17 @@ const AlertDetails: ComponentType = () => { | |||
|
|
|||
| const validAlertId = id && allAPIAlertIds.includes(id) ? id : undefined; | |||
|
|
|||
| if (!alerts || !places) { | |||
| return null; | |||
| } | |||
There was a problem hiding this comment.
Does it make sense to hoist the letter cahnge above the definition of foundAlert? That would eliminate the need for the change to add nullish coalescing to alerts (Note: GitHub is rendering this suggestion in a nonsensical way on my end, hopefully it comes out the other side looking better):
| if (!alerts || !places) { | |
| return null; | |
| } | |
| const foundAlert = alerts.find((alert) => alert.id === id); | |
| useEffect(() => { | |
| if (foundAlert) { | |
| setSelectedAlert(foundAlert); | |
| } | |
| }, [foundAlert]); | |
| const validAlertId = id && allAPIAlertIds.includes(id) ? id : undefined; |
There was a problem hiding this comment.
Unfortunately we can't do that because that would conditionally short-circuit the useEffect, which isn't allowed.
| const allPlaceRoutes = fp.uniq(places.flatMap(({ routes }) => routes)); | ||
| const modeOptions = MODES_AND_LINES.filter(({ ids }) => { | ||
| return ids[0] === "All" || fp.intersection(ids, allPlaceRoutes).length > 0; | ||
| }); |
There was a problem hiding this comment.
No action required - FWIW, we could accomplish this without lodash (but would require us to update our TS config for 2024's Set methods):
const allPlaceRoutes = new Set(places.flatMap(({ routes }) => routes));
const modeOptions = MODES_AND_LINES.filter(({ ids }) => {
return ids[0] === "All" || allPlaceRoutes.intersection(new Set(ids)).size > 0;
});| ? fp | ||
| .reverse(PLACES_PAGE_MODES_AND_LINES) | ||
| .find( | ||
| ({ ids }) => | ||
| ids[0] === "All" || | ||
| places.every( | ||
| (place) => fp.intersection(ids, place.routes).length > 0, | ||
| ), | ||
| )! |
There was a problem hiding this comment.
No action required - Similar comment above RE doing this in vanilla JS:
? PLACES_PAGE_MODES_AND_LINES.toReversed().find(
({ ids }) =>
ids[0] === "All" ||
places.every(
(place) =>
new Set(ids).intersection(new Set(place.routes)).size > 0,
),
)!;|
Ah, that Ferry behavior is happening because the list of places is empty, so the |
Asana task: Screenplay: Sort/filter stations in Posted Alerts
This adds the line/mode filter to the places list on the alert detail page. The filter defaults to a certain line if all places are on the same line, and uses the corresponding station sort order. Otherwise, it defaults to All, and uses alphabetical sorting. In either case, the filter can be changed to see a subset of the impacted places.
Note that several pages now wait until the places and alerts are loaded before displaying their content, which is necessary to properly initialize the defaults, and has the side effect of removing some flashes of empty content, e.g. the erroneous "not found" message on the alert details page.