Skip to content

Commit

Permalink
Merge branch 'master' into pass-operator-logos-to-map-popup
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-corson-ibigroup authored Sep 23, 2024
2 parents 2eb968f + 44573c6 commit 1554391
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 20 deletions.
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": "11.5.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/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": "4.0.2",
"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
5 changes: 3 additions & 2 deletions packages/map-popup/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ 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, getEntityPrefix, setLocation, setViewedStop }: Props): JSX.Element {
export function MapPopup({ closePopup = () => {}, configCompanies, entity, getEntityName, getEntityPrefix, setLocation, setViewedStop }: Props): JSX.Element {

const intl = useIntl()
if (!entity) return <></>

Expand All @@ -116,7 +117,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": "1.0.17",
"description": "Render data from OTP2's vector tile server",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
19 changes: 17 additions & 2 deletions packages/otp2-tile-overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,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[]
getEntityPrefix?: (entity: Stop | Station) => JSX.Element
id: string
Expand All @@ -59,6 +60,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 @@ -138,6 +144,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 @@ -151,6 +160,7 @@ const OTP2TileLayerWithPopup = ({
}}
source-layer={type}
source={SOURCE_ID}
minzoom={stopsWhitelist ? 2 : 14}
type="fill"
/>}
{isArea && <Layer
Expand All @@ -172,6 +182,7 @@ const OTP2TileLayerWithPopup = ({
key={id}
paint={generateLayerPaint(color)[type]}
source={SOURCE_ID}
minzoom={stopsWhitelist ? 2 : 14}
source-layer={type}
type="circle"
/>}
Expand All @@ -184,6 +195,7 @@ const OTP2TileLayerWithPopup = ({
onClose={() => setClickedEntity(null)}
>
<EntityPopup
closePopup={() => setClickedEntity(null)}
configCompanies={configCompanies}
entity={{ ...clickedEntity, id: clickedEntity?.id || clickedEntity?.gtfsId }}
getEntityPrefix={getEntityPrefix}
Expand All @@ -206,6 +218,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 @@ -214,7 +227,8 @@ const generateOTP2TileLayers = (
endpoint: string,
setLocation?: (location: MapLocationActionArg) => void,
setViewedStop?: (stop: Stop) => void,
configCompanies?: ConfiguredCompany[],
stopsWhitelist?: string[],
configCompanies?: ConfiguredCompany[]
getEntityPrefix?: (entity: Stop | Station) => JSX.Element
): JSX.Element[] => {
return [
Expand Down Expand Up @@ -242,6 +256,7 @@ const generateOTP2TileLayers = (
network={network}
setLocation={setLocation}
setViewedStop={setViewedStop}
stopsWhitelist={stopsWhitelist}
type={type}
visible={initiallyVisible}
/>
Expand Down

0 comments on commit 1554391

Please sign in to comment.