Skip to content

Commit

Permalink
refactor(Routes.Route): remove deprecated custom_route? value (#2112)
Browse files Browse the repository at this point in the history
* refactor(Routes.Route): remove deprecated custom_route? value

* fixup(Routes.Route): encode all fields

* fix the tests
  • Loading branch information
thecristen authored Jul 9, 2024
1 parent 1ce1440 commit 6fd2b77
Show file tree
Hide file tree
Showing 31 changed files with 399 additions and 771 deletions.
7 changes: 2 additions & 5 deletions assets/ts/schedule/components/__schedule.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,14 @@ export interface LineDiagramVehicle {
tooltip: string;
}

interface RouteStopRoute extends Route {
"custom_route?": boolean;
}
export interface RouteStop {
id: string;
name: string;
zone: string | null;
branch: string | null;
station_info: Stop & { parent_id: string | null; child_ids: string[] };
route: RouteStopRoute | null;
connections: RouteStopRoute[];
route: Route | null;
connections: Route[];
stop_features: string[];
"terminus?": boolean;
"is_beginning?": boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const route = {
1: "End"
},
description: "key_bus_route",
"custom_route?": false,
header: "",
alerts: [],
line_id: null
Expand All @@ -72,7 +71,6 @@ const oneDirectionRoute = {
1: "End"
},
description: "key_bus_route",
"custom_route?": false,
header: "",
alerts: [],
line_id: null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"stop_tree": {
"by_id": {
"by_id": {
"a": {
"id": "a",
"value": {
Expand Down Expand Up @@ -37,8 +37,7 @@
"id": "111",
"direction_names": { "0": "Outbound", "1": "Inbound" },
"direction_destinations": { "0": "Woodlawn", "1": "Haymarket" },
"description": "key_bus_route",
"custom_route?": false
"description": "key_bus_route"
},
"name": "Elm St opp Haskell Ave",
"terminus?": true,
Expand All @@ -51,9 +50,11 @@
"long_name": "Wonderland - Wellington",
"id": "110",
"direction_names": { "0": "Outbound", "1": "Inbound" },
"direction_destinations": { "0": "Wonderland", "1": "Wellington" },
"description": "local_bus",
"custom_route?": false
"direction_destinations": {
"0": "Wonderland",
"1": "Wellington"
},
"description": "local_bus"
}
],
"closed_stop_info": null,
Expand Down Expand Up @@ -96,8 +97,7 @@
"id": "111",
"direction_names": { "0": "Outbound", "1": "Inbound" },
"direction_destinations": { "0": "Woodlawn", "1": "Haymarket" },
"description": "key_bus_route",
"custom_route?": false
"description": "key_bus_route"
},
"name": "Elm St opp Haskell Ave",
"terminus?": true,
Expand All @@ -110,9 +110,11 @@
"long_name": "Wonderland - Wellington",
"id": "110",
"direction_names": { "0": "Outbound", "1": "Inbound" },
"direction_destinations": { "0": "Wonderland", "1": "Wellington" },
"description": "local_bus",
"custom_route?": false
"direction_destinations": {
"0": "Wonderland",
"1": "Wellington"
},
"description": "local_bus"
}
],
"closed_stop_info": null,
Expand Down Expand Up @@ -155,8 +157,7 @@
"id": "111",
"direction_names": { "0": "Outbound", "1": "Inbound" },
"direction_destinations": { "0": "Woodlawn", "1": "Haymarket" },
"description": "key_bus_route",
"custom_route?": false
"description": "key_bus_route"
},
"name": "Elm St opp Haskell Ave",
"terminus?": true,
Expand All @@ -169,9 +170,11 @@
"long_name": "Wonderland - Wellington",
"id": "110",
"direction_names": { "0": "Outbound", "1": "Inbound" },
"direction_destinations": { "0": "Wonderland", "1": "Wellington" },
"description": "local_bus",
"custom_route?": false
"direction_destinations": {
"0": "Wonderland",
"1": "Wellington"
},
"description": "local_bus"
}
],
"closed_stop_info": null,
Expand Down
20 changes: 5 additions & 15 deletions assets/ts/schedule/components/line-diagram/StopCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
isSubwayRoute
} from "../../../models/route";
import { Alert, Route } from "../../../__v3api";
import { RouteStop, RouteStopRoute, StopId, StopTree } from "../__schedule";
import { RouteStop, StopId, StopTree } from "../__schedule";
import { branchPosition, diagramWidth } from "./line-diagram-helpers";
import StopConnections from "./StopConnections";
import StopFeatures from "./StopFeatures";
Expand Down Expand Up @@ -64,20 +64,13 @@ const lineName = ({ name, route: routeStopRoute }: RouteStop): string => {
const hasLivePredictions = (liveData?: LiveData): boolean =>
!!liveData && liveData.headsigns.some(hasPredictionTime);

const connectionsFor = (
routeStop: RouteStop,
stopTree: StopTree
): RouteStopRoute[] => {
const connectionsFor = (routeStop: RouteStop, stopTree: StopTree): Route[] => {
const { connections } = routeStop;
const greenLineConnections = connections.filter(isAGreenLineRoute);
if (routeStop.route && hasBranches(stopTree) && greenLineConnections.length) {
// If we can connect to other Green Line routes, they can connect back to
// this route as well.
const routeStopRoute: RouteStopRoute = {
...routeStop.route,
"custom_route?": false
};
return [routeStopRoute, ...connections];
return [routeStop.route, ...connections];
}
return connections;
};
Expand All @@ -89,10 +82,7 @@ const visibleAlert = (alert: Alert): boolean => {
const hasHighPriorityAlert = (stopId: StopId, alerts: Alert[]): boolean =>
alertsByStop(alerts, stopId).filter(visibleAlert).length > 0;

const routeForStop = (
stopTree: StopTree,
stopId: StopId
): RouteStopRoute | null => {
const routeForStop = (stopTree: StopTree, stopId: StopId): Route | null => {
const { route } = stopForId(stopTree, stopId);
return route;
};
Expand All @@ -107,7 +97,7 @@ const hasUpcomingDeparturesIfSubway = (
return !!liveData && liveData.headsigns.length > 0;
};

const schedulesButtonLabel = (route: RouteStopRoute | null): string => {
const schedulesButtonLabel = (route: Route | null): string => {
return route && isSubwayRoute(route)
? "View upcoming departures"
: "View schedule";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import React from "react";
import { sortBy } from "lodash";
import { RouteStopRoute } from "../__schedule";
import { TooltipWrapper, modeIcon } from "../../../helpers/icon";
import { isABusRoute, isACommuterRailRoute } from "../../../models/route";
import { routeBgClass } from "../../../helpers/css";
import { Route } from "../../../__v3api";

const filteredConnections = (
connections: RouteStopRoute[]
): RouteStopRoute[] => {
const filteredConnections = (connections: Route[]): Route[] => {
const firstCRIndex = connections.findIndex(
connection => connection.type === 2
);
Expand Down Expand Up @@ -47,7 +44,7 @@ const connectionName = (connection: Route): string => {

const StopConnections = (
route_id: string,
connections: RouteStopRoute[]
connections: Route[]
): JSX.Element => (
<div className="m-schedule-diagram__connections">
{filteredConnections(connections).map((connectingRoute: Route) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const route = {
1: "End"
},
description: "key_bus_route",
"custom_route?": false,
header: "",
alerts: [],
line_id: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ const route = {
1: "End"
},
description: "key_bus_route",
"custom_route?": false,
header: "",
alerts: [],
line_id: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
HeadsignWithCrowding,
InformedEntitySet,
Prediction,
Route,
Schedule
} from "../../../../__v3api";
import { RouteStop, RouteStopRoute, StopTree } from "../../__schedule";
import { RouteStop, StopTree } from "../../__schedule";
import { TripPrediction } from "../../__trips";
import { createStopTreeCoordStore } from "../graphics/useTreeStopPositions";
import StopPredictions from "../StopPredictions";
Expand Down Expand Up @@ -159,7 +160,7 @@ describe("StopCard", () => {
jest.spyOn(StopTreeHelpers, "stopForId").mockImplementation(
() =>
(({
route: { type: 1 } as RouteStopRoute,
route: { type: 1 } as Route,
stop_features: [],
connections: []
} as unknown) as RouteStop)
Expand Down Expand Up @@ -188,7 +189,7 @@ describe("StopCard", () => {
jest.spyOn(StopTreeHelpers, "stopForId").mockImplementation(
() =>
(({
route: { type: 1 } as RouteStopRoute,
route: { type: 1 } as Route,
stop_features: [],
connections: []
} as unknown) as RouteStop)
Expand Down Expand Up @@ -216,7 +217,7 @@ describe("StopCard", () => {
jest.spyOn(StopTreeHelpers, "stopForId").mockImplementation(
() =>
(({
route: { type: 3 } as RouteStopRoute,
route: { type: 3 } as Route,
stop_features: [],
connections: []
} as unknown) as RouteStop)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[
{
"stop_data": [{ "type": "terminus", "branch": null, "has_disruption?": true }],
"stop_data": [
{ "type": "terminus", "branch": null, "has_disruption?": true }
],
"route_stop": {
"zone": null,
"stop_features": ["parking_lot"],
Expand Down Expand Up @@ -44,9 +46,7 @@
"severity": "3",
"effect": "detour",
"lifecycle": "ongoing",
"active_period": [
["2020-09-01 12:00", "2023-01-01 01:00"]
]
"active_period": [["2020-09-01 12:00", "2023-01-01 01:00"]]
}
]
},
Expand Down Expand Up @@ -89,8 +89,7 @@
"id": "Orange",
"direction_names": { "0": "Southbound", "1": "Northbound" },
"direction_destinations": { "0": "Forest Hills", "1": "Oak Grove" },
"description": "rapid_transit",
"custom_route?": false
"description": "rapid_transit"
},
{
"type": 0,
Expand All @@ -102,8 +101,7 @@
"0": "Cleveland Circle",
"1": "North Station"
},
"description": "rapid_transit",
"custom_route?": false
"description": "rapid_transit"
}
],
"closed_stop_info": null,
Expand Down Expand Up @@ -157,8 +155,7 @@
"0": "Bedford VA Hospital",
"1": "Alewife"
},
"description": "local_bus",
"custom_route?": false
"description": "local_bus"
},
{
"type": 3,
Expand All @@ -167,8 +164,7 @@
"id": "67",
"direction_names": { "0": "Outbound", "1": "Inbound" },
"direction_destinations": { "0": "Turkey Hill", "1": "Alewife" },
"description": "local_bus",
"custom_route?": false
"description": "local_bus"
}
],
"closed_stop_info": null,
Expand All @@ -181,7 +177,9 @@
]
},
{
"stop_data": [{ "type": "terminus", "branch": null, "has_disruption?": false }],
"stop_data": [
{ "type": "terminus", "branch": null, "has_disruption?": false }
],
"route_stop": {
"zone": null,
"stop_features": ["parking_lot", "access"],
Expand Down Expand Up @@ -219,8 +217,7 @@
"id": "BOAT-A",
"direction_names": { "0": "Outbound", "1": "Inbound" },
"direction_destinations": { "0": "Boston", "1": "Atlantis" },
"description": "ferry",
"custom_route?": false
"description": "ferry"
}
],
"closed_stop_info": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ describe("ScheduleModalContent", () => {
act(() => {
const ferryRoute = {
color: "008EAA",
"custom_route?": false,
description: "ferry",
direction_destinations: { 0: "Charlestown", 1: "Long Wharf" },
direction_names: { 0: "Outbound", 1: "Inbound" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"1": "Dudley"
},
"description": "key_bus_route",
"custom_route?": false,
"color": "FFC72C"
},
"realtime": {
Expand Down Expand Up @@ -85,7 +84,6 @@
"1": "Dudley"
},
"description": "key_bus_route",
"custom_route?": false,
"color": "FFC72C"
},
"realtime": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import renderer, { act } from "react-test-renderer";
import { ReactWrapper, mount } from "enzyme";
import { createReactRoot } from "../../../../../app/helpers/testUtils";
import * as dailyScheduleModule from "../DailySchedule";
import {
DatesNotes,
DirectionId,
Service,
ServiceTypicality
} from "../../../../../__v3api";
import { DatesNotes, Service, ServiceTypicality } from "../../../../../__v3api";
import { ServiceInSelector } from "../../../__schedule";
import { render, screen } from "@testing-library/react";

Expand Down Expand Up @@ -431,7 +426,6 @@ describe("parseResults", () => {
"1": "Nubian Station"
},
description: "key_bus_route",
"custom_route?": false,
color: "FFC72C"
},
departure: {
Expand Down Expand Up @@ -482,7 +476,6 @@ describe("parseResults", () => {
"1": "Nubian Station"
},
description: "key_bus_route",
"custom_route?": false,
color: "FFC72C"
},
departure: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const journey = ({
"0": "Stoughton or Wickford Junction",
"1": "South Station"
},
description: "commuter_rail",
"custom_route?": false
description: "commuter_rail"
},
departure: {
time: "05:30 AM",
Expand Down
Loading

0 comments on commit 6fd2b77

Please sign in to comment.