-
Notifications
You must be signed in to change notification settings - Fork 1
add line filtering for alert places #783
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import { | |
| import { DirectionID } from "Models/direction_id"; | ||
| import { usePrevious } from "Hooks/usePrevious"; | ||
| import { sortByStationOrder } from "../../util"; | ||
| import fp from "lodash/fp"; | ||
|
|
||
| const getSortLabel = ( | ||
| modeLineFilterValue: { label: string }, | ||
|
|
@@ -36,6 +37,9 @@ const getSortLabel = ( | |
| const PlacesPage: ComponentType = () => { | ||
| const { places } = useScreenplayState(); | ||
|
|
||
| if (!places) { | ||
| return null; | ||
| } | ||
| return ( | ||
| <div className="places-page"> | ||
| <div className="page-content__header">Places</div> | ||
|
|
@@ -48,16 +52,16 @@ const PlacesPage: ComponentType = () => { | |
|
|
||
| interface PlacesListProps { | ||
| places: Place[]; | ||
| noModeFilter?: boolean; | ||
| isAlertPlacesList?: boolean; | ||
| showAnimationForNewPlaces?: boolean; | ||
| showLineMap?: boolean; | ||
| } | ||
|
|
||
| const PlacesList: ComponentType<PlacesListProps> = ({ | ||
| places, | ||
| noModeFilter, | ||
| isAlertPlacesList, | ||
| showAnimationForNewPlaces, | ||
| showLineMap = true, | ||
| }: PlacesListProps) => { | ||
| // ascending/southbound/westbound = 0, descending/northbound/eastbound = 1 | ||
| const { | ||
|
|
@@ -175,6 +179,11 @@ const PlacesList: ComponentType<PlacesListProps> = ({ | |
| statusFilterValue !== STATUSES[0] || | ||
| screenTypeFilterValue !== SCREEN_TYPES[0]; | ||
|
|
||
| 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; | ||
| }); | ||
|
Comment on lines
+182
to
+185
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No action required - FWIW, we could accomplish this without lodash (but would require us to update our TS config for 2024's 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;
}); |
||
|
|
||
| return ( | ||
| <> | ||
| <Container fluid> | ||
|
|
@@ -187,14 +196,12 @@ const PlacesList: ComponentType<PlacesListProps> = ({ | |
| /> | ||
| </Col> | ||
| <Col lg={3} className="d-flex justify-content-end pe-3"> | ||
| {!noModeFilter && ( | ||
| <FilterDropdown | ||
| list={MODES_AND_LINES} | ||
| onSelect={(value: any) => handleSelectModeOrLine(value)} | ||
| selectedValue={modeLineFilterValue} | ||
| className="modes-and-lines" | ||
| /> | ||
| )} | ||
| <FilterDropdown | ||
| list={modeOptions} | ||
| onSelect={(value: any) => handleSelectModeOrLine(value)} | ||
| selectedValue={modeLineFilterValue} | ||
| className="modes-and-lines" | ||
| /> | ||
| </Col> | ||
| <Col lg={3} className="place-screen-types pe-3"> | ||
| <FilterDropdown | ||
|
|
@@ -245,7 +252,9 @@ const PlacesList: ComponentType<PlacesListProps> = ({ | |
| } | ||
| activeEventKeys={activeEventKeys} | ||
| sortDirection={sortDirection} | ||
| filteredLine={isOnlyFilteredByRoute ? getFilteredLine() : null} | ||
| filteredLine={ | ||
| showLineMap && isOnlyFilteredByRoute ? getFilteredLine() : null | ||
| } | ||
| className={isFiltered || isAlertPlacesList ? "filtered" : ""} | ||
| /> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import { BannerAlert } from "../components/Dashboard/AlertBanner"; | |
| import { ActionOutcomeToastProps } from "../components/Dashboard/ActionOutcomeToast"; | ||
| import useSWR, { KeyedMutator } from "swr"; | ||
| import { getSuppressedPredictions } from "Utils/api"; | ||
| import fp from "lodash/fp"; | ||
|
|
||
| interface Props { | ||
| children: React.ReactNode; | ||
|
|
@@ -28,9 +29,9 @@ interface FilterValue { | |
| } | ||
|
|
||
| interface ScreenplayState { | ||
| places: Place[]; | ||
| places?: Place[]; | ||
| lineStops: LineStop[]; | ||
| alerts: Alert[]; | ||
| alerts?: Alert[]; | ||
| allAPIAlertIds: string[]; | ||
| screensByAlertMap: ScreensByAlert; | ||
| bannerAlert?: BannerAlert; | ||
|
|
@@ -55,9 +56,9 @@ const [useScreenplayState, ScreenplayStateProvider] = | |
| createGenericContext<ScreenplayState>(); | ||
|
|
||
| const ScreenplayStateContainer = ({ children }: Props) => { | ||
| const [places, setPlaces] = useState<Place[]>([]); | ||
| const [places, setPlaces] = useState<Place[]>(); | ||
| const [lineStops, setLineStops] = useState<LineStop[]>([]); | ||
| const [alerts, setAlerts] = useState<Alert[]>([]); | ||
| const [alerts, setAlerts] = useState<Alert[]>(); | ||
| const [allAPIAlertIds, setAllAPIAlertIds] = useState<string[]>([]); | ||
| const [screensByAlertMap, setScreensByAlertMap] = useState<ScreensByAlert>( | ||
| {}, | ||
|
|
@@ -156,10 +157,30 @@ interface PlacesListState { | |
| const [usePlacesListState, PlacesListStateProvider] = | ||
| createGenericContext<PlacesListState>(); | ||
|
|
||
| const PlacesListStateContainer = ({ children }: Props) => { | ||
| interface PlacesListStateContainerProps { | ||
| children: React.ReactNode; | ||
| places?: Place[]; | ||
| } | ||
|
|
||
| const PlacesListStateContainer = ({ | ||
| children, | ||
| places, | ||
| }: PlacesListStateContainerProps) => { | ||
| const [sortDirection, setSortDirection] = useState<DirectionID>(0); | ||
| const [modeLineFilterValue, setModeLineFilterValue] = useState<FilterValue>( | ||
| PLACES_PAGE_MODES_AND_LINES[0], | ||
| () => { | ||
| return places && places.length > 0 | ||
| ? fp | ||
| .reverse(PLACES_PAGE_MODES_AND_LINES) | ||
| .find( | ||
| ({ ids }) => | ||
| ids[0] === "All" || | ||
| places.every( | ||
| (place) => fp.intersection(ids, place.routes).length > 0, | ||
| ), | ||
| )! | ||
|
Comment on lines
+173
to
+181
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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,
),
)!; |
||
| : PLACES_PAGE_MODES_AND_LINES[0]; | ||
| }, | ||
| ); | ||
| const [screenTypeFilterValue, setScreenTypeFilterValue] = | ||
| useState<FilterValue>(SCREEN_TYPES[0]); | ||
|
|
||
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.
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 toalerts(Note: GitHub is rendering this suggestion in a nonsensical way on my end, hopefully it comes out the other side looking better):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.
Unfortunately we can't do that because that would conditionally short-circuit the
useEffect, which isn't allowed.