Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into callback-disable-…
Browse files Browse the repository at this point in the history
…all-submodes
  • Loading branch information
josh-willis-arcadis committed Sep 25, 2024
2 parents f147b68 + 975c06f commit 4ea8036
Show file tree
Hide file tree
Showing 35 changed files with 93 additions and 45 deletions.
2 changes: 1 addition & 1 deletion packages/base-map/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/base-map",
"version": "3.2.2",
"version": "4.0.0",
"description": "Base Map Component",
"author": "@binh-dam-ibigroup",
"homepage": "https://github.com/opentripplanner/otp-ui/#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/building-blocks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/building-blocks",
"version": "1.2.3",
"version": "2.0.0",
"description": "Styling and UI Component Library",
"author": "@binh-dam-ibigroup",
"homepage": "https://github.com/opentripplanner/otp-ui/#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/core-utils",
"version": "11.4.4",
"version": "12.0.0",
"description": "Core functionality that is shared among numerous UI components",
"engines": {
"node": ">=13"
Expand Down
16 changes: 16 additions & 0 deletions packages/core-utils/src/__tests__/itinerary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
getLegRouteLongName,
getLegRouteName,
getLegRouteShortName,
isFlex,
isTransit,
mapOldElevationComponentToNew
} from "../itinerary";

const bikeRentalItinerary = require("./__mocks__/bike-rental-itinerary.json");
const tncItinerary = require("./__mocks__/tnc-itinerary.json");
const fareProductItinerary = require("./__mocks__/fare-products-itinerary.json");
const flexItinerary = require("../../../itinerary-body/src/__mocks__/itineraries/flex-itinerary.json");

const basePlace = {
lat: 0,
Expand All @@ -40,6 +42,20 @@ describe("util > itinerary", () => {
});
});

describe("isFlex", () => {
it("should detect flex if present", () => {
fareProductItinerary.legs.forEach(leg => expect(isFlex(leg)).toBe(false));
tncItinerary.legs.forEach(leg => expect(isFlex(leg)).toBe(false));
expect(isFlex(flexItinerary.legs[0])).toBe(false);
expect(isFlex(flexItinerary.legs[1])).toBe(false);
expect(isFlex(flexItinerary.legs[2])).toBe(false);
expect(isFlex(flexItinerary.legs[3])).toBe(false);
expect(isFlex(flexItinerary.legs[4])).toBe(false);
expect(isFlex(flexItinerary.legs[5])).toBe(true);
expect(isFlex(flexItinerary.legs[6])).toBe(false); // Does not exist
expect(isFlex(flexItinerary.legs[7])).toBe(false); // Does not exist
});
});
describe("isTransit", () => {
it("should work", () => {
expect(isTransit("CAR")).toBeFalsy();
Expand Down
46 changes: 35 additions & 11 deletions packages/core-utils/src/itinerary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export function getTransitModes(config: Config): string[] {
);
}

export function isTransitLeg(leg: Leg): boolean {
return leg.transitLeg;
}

export function isTransit(mode: string): boolean {
return transitModes.includes(mode) || mode === "TRANSIT";
}
Expand All @@ -52,7 +56,7 @@ export function isTransit(mode: string): boolean {
* property which encodes this info.
*/
export function isReservationRequired(leg: Leg): boolean {
return leg.boardRule === "mustPhone" || leg.alightRule === "mustPhone";
return leg?.boardRule === "mustPhone" || leg?.alightRule === "mustPhone";
}
/**
* Returns true if a user must ask the driver to let the user off
Expand All @@ -61,25 +65,45 @@ export function isReservationRequired(leg: Leg): boolean {
*/
export function isCoordinationRequired(leg: Leg): boolean {
return (
leg.boardRule === "coordinateWithDriver" ||
leg.alightRule === "coordinateWithDriver"
leg?.boardRule === "coordinateWithDriver" ||
leg?.alightRule === "coordinateWithDriver"
);
}
/**
* The two rules checked by the above two functions are the only values
* returned by OTP when a leg is a flex leg.
*/
export function isFlex(leg: Leg): boolean {
return isReservationRequired(leg) || isCoordinationRequired(leg);
}

export function containsGeometry(place: Place): boolean {
return (
place?.stop?.geometries !== null && place?.stop?.geometries !== undefined
);
}
export function endsWithGeometry(leg: Leg): boolean {
return containsGeometry(leg?.to);
}
export function startsWithGeometry(leg: Leg): boolean {
return containsGeometry(leg?.from);
}
export function legContainsGeometry(leg: Leg): boolean {
return endsWithGeometry(leg) || startsWithGeometry(leg);
}
export function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {
return info?.latestBookingTime?.daysPrior > 0;
}
export function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {
return isAdvanceBookingRequired(leg.dropOffBookingInfo);
return isAdvanceBookingRequired(leg?.dropOffBookingInfo);
}

/**
* The two rules checked by the above two functions are the only values
* returned by OTP when a leg is a flex leg.
*/
export function isFlex(leg: Leg): boolean {
return (
isReservationRequired(leg) ||
isCoordinationRequired(leg) ||
legDropoffRequiresAdvanceBooking(leg) ||
isAdvanceBookingRequired(leg?.pickupBookingInfo) ||
legContainsGeometry(leg)
);
}
export function isRideshareLeg(leg: Leg): boolean {
return !!leg.rideHailingEstimate?.provider?.id;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoints-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/endpoints-overlay",
"version": "2.1.4",
"version": "3.0.0",
"description": "A map overlay to show the from and to locations of an itinerary",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/from-to-location-picker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/from-to-location-picker",
"version": "2.1.14",
"version": "3.0.0",
"description": "Location Picker Component",
"author": "@binh-dam-ibigroup",
"homepage": "https://github.com/opentripplanner/otp-ui/#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/icons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/icons",
"version": "2.0.13",
"version": "3.0.0",
"description": "Icons for otp-ui",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/itinerary-body/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/itinerary-body",
"version": "5.3.7",
"version": "6.0.0",
"description": "A component for displaying an itinerary body of a trip planning result",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/location-field/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/location-field",
"version": "2.0.24",
"version": "3.0.0",
"description": "A component for display and finding a location",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/map-popup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/map-popup",
"version": "4.0.1",
"version": "5.0.0",
"description": "A component for displaying map popup contents",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/map-popup/src/__snapshots__/MapPopup.story.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exports[`Map Popup FloatingCarEntity smoke-test 1`] = `

exports[`Map Popup FloatingVehicleEntity smoke-test 1`] = `
<div class="styled__MapOverlayPopup-sc-12kjso7-1 idXkMr">
<div id="focus-bike_6861-popup-focus-trap"
<div id="focus-22bike_686122-popup-focus-trap"
role="presentation"
>
<header class="styled__PopupTitle-sc-12kjso7-3 cjkEhb">
Expand Down Expand Up @@ -116,7 +116,7 @@ exports[`Map Popup FloatingVehicleEntity smoke-test 1`] = `

exports[`Map Popup StationEntity smoke-test 1`] = `
<div class="styled__MapOverlayPopup-sc-12kjso7-1 idXkMr">
<div id="focus-hub_1580-popup-focus-trap"
<div id="focus-22hub_158022-popup-focus-trap"
role="presentation"
>
<header class="styled__PopupTitle-sc-12kjso7-3 cjkEhb">
Expand Down
4 changes: 2 additions & 2 deletions packages/map-popup/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function entityIsStation(entity: Entity): entity is Station {
/**
* Renders a map popup for a stop, scooter, or shared bike
*/
export function MapPopup({ closePopup = null, configCompanies, entity, getEntityName, setLocation, setViewedStop }: Props): JSX.Element {
export function MapPopup({ closePopup = () => {}, configCompanies, entity, getEntityName, setLocation, setViewedStop }: Props): JSX.Element {
const intl = useIntl()
if (!entity) return <></>

Expand All @@ -115,7 +115,7 @@ export function MapPopup({ closePopup = null, configCompanies, entity, getEntity
const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(":")[1] || entity.id

// Double quotes make the query invalid, so remove them from the id just in case
const id = `focus-${entity.id}-popup`.replace(/"/g, "")
const id = `focus-${encodeURIComponent(entity.id).replace(/%/g, "")}-popup`

return (
<Styled.MapOverlayPopup>
Expand Down
2 changes: 1 addition & 1 deletion packages/otp2-tile-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/otp2-tile-overlay",
"version": "1.0.15",
"version": "2.0.0",
"description": "Render data from OTP2's vector tile server",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
17 changes: 16 additions & 1 deletion packages/otp2-tile-overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ const OTP2TileLayerWithPopup = ({
onMapClick,
setLocation,
setViewedStop,
stopsWhitelist,
type
}: {
color?: string;
/**
* Optional configuration item which allows for customizing properties of scooter and
* bikeshare companies. If this is provided, scooter/bikeshare company names can be rendered in the
* default scooter/bike popup.
*/
color?: string;
configCompanies?: ConfiguredCompany[]
id: string
name?: string
Expand All @@ -56,6 +57,11 @@ const OTP2TileLayerWithPopup = ({
* not passed, the stop viewer link will not be shown.
*/
setViewedStop?: StopEventHandler
/**
* A list of GTFS stop ids (with agency prepended). If specified, all stops that
* are NOT in this list will be HIDDEN.
*/
stopsWhitelist?: string[]
/**
* Determines which layer of the OTP2 tile data to display. Also determines icon color.
*/
Expand Down Expand Up @@ -135,6 +141,9 @@ const OTP2TileLayerWithPopup = ({
if (type === "stops" || type === "areaStops") {
filter = ["all", ["!", ["has", "parentStation"]], ["!=", ["get", "routes"], ["literal", "[]"]]]
}
if (stopsWhitelist) {
filter = ["in", ["get", "gtfsId"], ["literal", stopsWhitelist]]
}

const isArea = AREA_TYPES.includes(type)
return (
Expand All @@ -148,6 +157,7 @@ const OTP2TileLayerWithPopup = ({
}}
source-layer={type}
source={SOURCE_ID}
minzoom={stopsWhitelist ? 2 : 14}
type="fill"
/>}
{isArea && <Layer
Expand All @@ -169,6 +179,7 @@ const OTP2TileLayerWithPopup = ({
key={id}
paint={generateLayerPaint(color)[type]}
source={SOURCE_ID}
minzoom={stopsWhitelist ? 2 : 14}
source-layer={type}
type="circle"
/>}
Expand All @@ -181,6 +192,7 @@ const OTP2TileLayerWithPopup = ({
onClose={() => setClickedEntity(null)}
>
<EntityPopup
closePopup={() => setClickedEntity(null)}
configCompanies={configCompanies}
entity={{ ...clickedEntity, id: clickedEntity?.id || clickedEntity?.gtfsId }}
setLocation={setLocation ? (location) => { setClickedEntity(null); setLocation(location) } : null}
Expand All @@ -202,6 +214,7 @@ const OTP2TileLayerWithPopup = ({
* @param endpoint The OTP endpoint to make the requests to
* @param setLocation An optional method to make from/to buttons functional. See component for more detail.
* @param setViewedStop An optional method to make stop viewer button functional. See component for more detail.
* @param stopsWhitelist An optional list of stops to display singularly. See component for more detail.
* @param configCompanies An optional list of companies used to prettify network information.
* @returns Array of <Source> and <OTP2TileLayerWithPopup> components
*/
Expand All @@ -210,6 +223,7 @@ const generateOTP2TileLayers = (
endpoint: string,
setLocation?: (location: MapLocationActionArg) => void,
setViewedStop?: (stop: Stop) => void,
stopsWhitelist?: string[],
configCompanies?: ConfiguredCompany[]
): JSX.Element[] => {
return [
Expand All @@ -236,6 +250,7 @@ const generateOTP2TileLayers = (
network={network}
setLocation={setLocation}
setViewedStop={setViewedStop}
stopsWhitelist={stopsWhitelist}
type={type}
visible={initiallyVisible}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/park-and-ride-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/park-and-ride-overlay",
"version": "2.0.9",
"version": "3.0.0",
"description": "A map overlay to show park and rides",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/printable-itinerary/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/printable-itinerary",
"version": "2.0.23",
"version": "3.0.0",
"description": "A component for displaying a printable itinerary body of a trip planning result",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/route-viewer-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/route-viewer-overlay",
"version": "2.0.17",
"version": "3.0.0",
"description": "A map overlay to show a transit route",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/stop-viewer-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/stop-viewer-overlay",
"version": "2.0.10",
"version": "3.0.0",
"description": "A map overlay to show a stop",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/stops-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/stops-overlay",
"version": "5.3.3",
"version": "6.0.0",
"description": "A map overlay to show transit stops",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/transit-vehicle-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/transit-vehicle-overlay",
"version": "4.0.13",
"version": "5.0.0",
"description": "Realtime Transit Vehicles Component",
"author": "Frank Purcell",
"homepage": "https://github.com/opentripplanner/otp-ui/tree/master/packages/transit-vehicle-overlay/#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/transitive-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/transitive-overlay",
"version": "3.0.22",
"version": "4.0.0",
"description": "A map overlay to show an itinerary based on transitive.js",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/trip-details/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/trip-details",
"version": "5.0.15",
"version": "6.0.0",
"description": "A component for displaying details about a trip planning itinerary",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
1 change: 0 additions & 1 deletion packages/trip-form/i18n/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ otpUi:
walkTolerance-labelHigh: Más caminar
walkTolerance-labelLow: Menos caminar
wheelchair-label: Acceso con discapacidades
settingsLabel: Ajustes para {mode}
SettingsSelectorPanel:
bikeOnly: Solo bicicleta
escooterOnly: Solo scooters eléctricos
Expand Down
1 change: 0 additions & 1 deletion packages/trip-form/i18n/ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ otpUi:
walkTolerance-labelHigh: 더 많이 걷기
walkTolerance-labelLow: 덜 걷기
wheelchair-label: 액세스 가능한 라우팅
settingsLabel: "{mode} 설정"
SettingsSelectorPanel:
bikeOnly: 자전거 전용
escooterOnly: 전동스쿠터 전용
Expand Down
Loading

0 comments on commit 4ea8036

Please sign in to comment.