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

hotfix(ScheduleDirection): fix line diagram for routes with repeated stops #1760

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
34 changes: 22 additions & 12 deletions apps/site/assets/ts/schedule/components/ScheduleDirection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Alert, DirectionId, EnhancedRoute } from "../../__v3api";
import {
RoutePatternsByDirection,
EnhancedRoutePattern,
StopTree
StopTree,
RouteStop
} from "./__schedule";
import ScheduleDirectionMenu from "./direction/ScheduleDirectionMenu";
import ScheduleDirectionButton from "./direction/ScheduleDirectionButton";
Expand All @@ -18,15 +19,15 @@ import {
} from "../../models/route";
import LineDiagram from "./line-diagram/LineDiagram";
import { fromStopTreeData } from "./ScheduleLoader";
import { isEmptyTree } from "../../helpers/stop-tree";

export interface Props {
route: EnhancedRoute;
directionId: DirectionId;
routePatternsByDirection: RoutePatternsByDirection;
mapData?: MapData;
staticMapData?: StaticMapData;
stopTree: StopTree;
stopTree: StopTree | null;
routeStopLists: RouteStop[][] | null;
alerts: Alert[];
busVariantId: string | null;
}
Expand Down Expand Up @@ -78,11 +79,11 @@ export const fetchLineData = (
if (response.ok) return response.json();
throw new Error(response.statusText);
})
.then(({ stop_tree }) => {
const stopTree: StopTree = fromStopTreeData(stop_tree);
.then(({ stop_tree, route_stop_lists }) => {
const stopTree = stop_tree ? fromStopTreeData(stop_tree) : null;
dispatch({
type: "FETCH_COMPLETE",
payload: { stopTree }
payload: { stopTree, routeStopLists: route_stop_lists }
});
})
// @ts-ignore
Expand All @@ -97,6 +98,7 @@ const ScheduleDirection = ({
mapData,
staticMapData,
stopTree: initialStopTree,
routeStopLists: initialRouteStopLists,
alerts,
busVariantId
}: Props): ReactElement<HTMLElement> => {
Expand Down Expand Up @@ -186,7 +188,8 @@ const ScheduleDirection = ({

const [lineState, dispatchLineData] = useReducer(fetchReducer, {
data: {
stopTree: initialStopTree
stopTree: initialStopTree,
routeStopLists: initialRouteStopLists
},
isLoading: false,
error: false
Expand All @@ -200,7 +203,12 @@ const ScheduleDirection = ({
);
}, [route, state.directionId, busVariantId, currentRoutePatternIdForData]);

const hasValidTree = lineState.data && !isEmptyTree(lineState.data.stopTree);
const routeStopList =
lineState.data && lineState.data.routeStopLists
? (lineState.data.routeStopLists as RouteStop[][]).find(
rsList => !!rsList.find(rs => rs.branch === state.routePattern.name)
) || []
: [];
return (
<>
<div className="m-schedule-direction">
Expand All @@ -221,9 +229,10 @@ const ScheduleDirection = ({
<ScheduleDirectionButton dispatch={dispatch} />
) : null}
</div>
{isSubwayRoute(route) && hasValidTree && (
{isSubwayRoute(route) && (
<LineDiagram
stopTree={lineState.data.stopTree}
stopTree={lineState.data && lineState.data.stopTree}
routeStopList={routeStopList}
route={route}
directionId={state.directionId}
alerts={alerts}
Expand Down Expand Up @@ -255,9 +264,10 @@ const ScheduleDirection = ({
</a>
</>
)}
{!isSubwayRoute(route) && hasValidTree && (
{!isSubwayRoute(route) && (
<LineDiagram
stopTree={lineState.data.stopTree}
stopTree={lineState.data && lineState.data.stopTree}
routeStopList={routeStopList}
route={route}
directionId={state.directionId}
alerts={alerts}
Expand Down
7 changes: 5 additions & 2 deletions apps/site/assets/ts/schedule/components/ScheduleLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ export const ScheduleLoader = ({
schedule_note: scheduleNote,
today,
stop_tree,
route_stop_lists: routeStopLists,
alerts,
variant: busVariantId
} = schedulePageData;
const stopTree: StopTree = fromStopTreeData(stop_tree);

const stopTree: StopTree | null = stop_tree
? fromStopTreeData(stop_tree)
: null;
const routeIsSuspended = Object.keys(routePatternsByDirection).length === 0;

const currentState = getCurrentState();
Expand Down Expand Up @@ -319,6 +321,7 @@ export const ScheduleLoader = ({
directionId={readjustedDirectionId}
route={route}
routePatternsByDirection={routePatternsByDirection}
routeStopLists={routeStopLists}
mapData={mapData}
staticMapData={staticMapData}
stopTree={stopTree}
Expand Down
3 changes: 2 additions & 1 deletion apps/site/assets/ts/schedule/components/__schedule.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export interface SchedulePageData {
stops: SimpleStopMap;
direction_id: DirectionId;
route_patterns: RoutePatternsByDirection;
stop_tree: StopTreeData;
stop_tree: StopTreeData | null;
route_stop_lists: RouteStop[][];
alerts: Alert[];
today: string;
variant: string | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const { stop_tree } = (lineDiagramData as unknown) as {
stop_tree: StopTreeData;
};
const stopTree: StopTree = fromStopTreeData(stop_tree);
const testRouteStopList = Object.values(stopTree.byId).map(node => node.value);

const route = {
type: 3,
Expand Down Expand Up @@ -170,6 +171,7 @@ const getComponent = () => (
routePatternsByDirection={routePatternsByDirection}
mapData={mapData}
stopTree={stopTree}
routeStopLists={[testRouteStopList]}
alerts={[]}
busVariantId={null}
/>
Expand All @@ -182,6 +184,7 @@ const getSingleDirectionComponent = () => (
routePatternsByDirection={routePatternsByDirection}
mapData={mapData}
stopTree={stopTree}
routeStopLists={[testRouteStopList]}
alerts={[]}
busVariantId={null}
/>
Expand All @@ -194,6 +197,7 @@ const getSubwayComponent = () => (
directionId={directionId}
routePatternsByDirection={routePatternsByDirection}
stopTree={stopTree}
routeStopLists={[testRouteStopList]}
alerts={[]}
busVariantId={null}
/>
Expand All @@ -206,6 +210,7 @@ const getCRComponent = () => (
routePatternsByDirection={routePatternsByDirection}
mapData={mapData}
stopTree={stopTree}
routeStopLists={[testRouteStopList]}
alerts={[]}
busVariantId={null}
/>
Expand All @@ -218,6 +223,7 @@ const getStaticMapComponent = () => (
directionId={directionId}
routePatternsByDirection={routePatternsByDirection}
stopTree={stopTree}
routeStopLists={[testRouteStopList]}
alerts={[]}
busVariantId={null}
/>
Expand Down Expand Up @@ -246,6 +252,7 @@ const getGreenLineComponent = () => {
directionId={directionId}
routePatternsByDirection={routePatternsByDirection}
stopTree={stopTree}
routeStopLists={[testRouteStopList]}
alerts={[]}
busVariantId={null}
/>
Expand All @@ -259,6 +266,7 @@ const getVariantComponent = () => (
routePatternsByDirection={routePatternsByDirection}
mapData={mapData}
stopTree={stopTree}
routeStopLists={[testRouteStopList]}
alerts={[]}
busVariantId="pattern-3"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const stops = {
const { stop_tree: stopTreeData } = (lineDiagramData as unknown) as {
stop_tree: StopTreeData;
};
const testRouteStopList = Object.values(stopTreeData.by_id).map(
node => node.value
);

const fares = [
{
Expand Down Expand Up @@ -243,6 +246,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -275,6 +279,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -319,6 +324,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -352,6 +358,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -395,6 +402,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -435,6 +443,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -468,6 +477,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -520,6 +530,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -587,6 +598,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -633,6 +645,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -688,6 +701,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -727,6 +741,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -784,6 +799,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -831,6 +847,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -876,6 +893,7 @@ describe("ScheduleLoader", () => {
route_patterns: routes,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -1006,6 +1024,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down Expand Up @@ -1049,6 +1068,7 @@ describe("ScheduleLoader", () => {
route_patterns: routePatternsByDirection,
today: "2019-12-05",
stop_tree: stopTreeData,
route_stop_lists: [testRouteStopList],
alerts: [],
variant: null
}}
Expand Down
Loading