Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion assets/ts/models/alert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isValid, parseISO, add } from "date-fns";
import { concat, isArray, mergeWith, reduce, some } from "lodash";
import { StopId } from "../schedule/components/__schedule";
import { Alert, TimePeriodPairs } from "../__v3api";
import { Alert, DirectionId, TimePeriodPairs } from "../__v3api";

const activePeriodToDates = (
activePeriod: TimePeriodPairs
Expand Down Expand Up @@ -250,3 +250,18 @@ export const isSuppressiveAlert = (
effect === "stop_closure";
return isCurrentLifecycle(alert) && isValidSuppressiveAlert;
};

export const matchesDirection = (
{ informed_entity }: Alert,
directionId: DirectionId
): boolean => {
const nonNullDirections = informed_entity.direction_id?.filter(
item => item !== null
);

if (nonNullDirections === undefined || nonNullDirections.length === 0) {
return true;
}

return nonNullDirections.includes(directionId);
};
10 changes: 8 additions & 2 deletions assets/ts/schedule/components/ScheduleDirection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "../../models/route";
import LineDiagram from "./line-diagram/LineDiagram";
import { fromStopTreeData } from "./SchedulePage";
import { matchesDirection } from "../../models/alert";

export interface Props {
alerts: Alert[];
Expand Down Expand Up @@ -222,6 +223,11 @@ const ScheduleDirection = ({
rsList => !!rsList.find(rs => rs.branch === state.routePattern.name)
) || []
: [];

const filteredAlerts = alerts.filter(alert =>
matchesDirection(alert, state.directionId)
);

return (
<>
<div className="m-schedule-direction">
Expand All @@ -242,7 +248,7 @@ const ScheduleDirection = ({
</div>
{isSubwayRoute(route) && lineState.data && (
<LineDiagram
alerts={alerts}
alerts={filteredAlerts}
directionId={state.directionId}
otherRouteStops={otherRouteStops}
route={route}
Expand Down Expand Up @@ -277,7 +283,7 @@ const ScheduleDirection = ({
)}
{!isSubwayRoute(route) && (
<LineDiagram
alerts={alerts}
alerts={filteredAlerts}
directionId={state.directionId}
otherRouteStops={otherRouteStops}
route={route}
Expand Down