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

Nearby view support #655

Merged
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cef0cc2
feat(types): Add "stop" to Place type
daniel-heppner-ibigroup Aug 11, 2023
4857a56
feat(types): add otp2 types to stop type
daniel-heppner-ibigroup Aug 11, 2023
e85f08d
feat(itinerary-body): add full stop data to view stop button return
daniel-heppner-ibigroup Aug 11, 2023
fc1a706
fix(core-utils): add more data to stop object
daniel-heppner-ibigroup Aug 11, 2023
e58cf71
fix(map-popup): setViewedStop passes whole stop
daniel-heppner-ibigroup Aug 15, 2023
38aefe6
fix(otp2-tile-overlay): use new stop callback
daniel-heppner-ibigroup Aug 15, 2023
eb9b041
fix(stops-overlay): use new stop callback
daniel-heppner-ibigroup Aug 15, 2023
016f1d4
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Sep 13, 2023
97deeb8
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Sep 28, 2023
f52f435
fix: use alpha versions
daniel-heppner-ibigroup Sep 28, 2023
a4483f6
feat(stops-overlay): add highlighted stop support
daniel-heppner-ibigroup Oct 24, 2023
52cdc89
fix(stops-overlay): add support for custom highlight color
daniel-heppner-ibigroup Oct 25, 2023
b500a49
fix(stops-overlay): fix memoization on highlighted stop
daniel-heppner-ibigroup Oct 24, 2023
d3a51f5
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Nov 3, 2023
694575d
deps: update internal dependencies
daniel-heppner-ibigroup Nov 13, 2023
1354178
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Nov 13, 2023
d2ffb77
revert unneeded change to graphql query
daniel-heppner-ibigroup Nov 16, 2023
16b1e65
fix duplicate id in types
daniel-heppner-ibigroup Nov 16, 2023
7a178de
use new stopeventhandler
daniel-heppner-ibigroup Nov 16, 2023
8b59a21
add stopId to prevent breaking change
daniel-heppner-ibigroup Nov 16, 2023
bf4da86
fix(map-popup): use StopEventHandler
daniel-heppner-ibigroup Nov 16, 2023
f40bd02
fix(otp2-tile-overlay): use StopEventHandler
daniel-heppner-ibigroup Nov 16, 2023
e6fb544
fix(stops-overlay): use StopEventHandler type
daniel-heppner-ibigroup Nov 16, 2023
ff5b3db
deps: update internal dependencies
daniel-heppner-ibigroup Nov 18, 2023
b2cdbbf
deps: move deps into devdeps
daniel-heppner-ibigroup Nov 18, 2023
b6fa7aa
revert breaking change in itinerary body
daniel-heppner-ibigroup Nov 18, 2023
27ff939
sort props
daniel-heppner-ibigroup Nov 18, 2023
a710085
feat(map-popup): pass the whole Stop object on stop click
daniel-heppner-ibigroup Nov 20, 2023
8ba60ef
simplify types
daniel-heppner-ibigroup Nov 21, 2023
99213e1
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Nov 27, 2023
edbdc5d
deps: update internal dependencies
daniel-heppner-ibigroup Nov 27, 2023
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
2 changes: 1 addition & 1 deletion packages/base-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"react-map-gl": "^7.0.15"
},
"peerDependencies": {
"@opentripplanner/types": "^6.1.0",
"@opentripplanner/types": "^6.2.0",
"react": "^16.14.0",
"styled-components": "^5.3.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/building-blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"module": "esm/index.js",
"private": false,
"devDependencies": {
"@opentripplanner/types": "^6.2.0",
"@opentripplanner/core-utils": "^11.1.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@conveyal/lonlat": "^1.4.1",
"@mapbox/polyline": "^1.1.0",
"@opentripplanner/geocoder": "^1.4.2",
"@opentripplanner/geocoder": "^2.0.0",
"@styled-icons/foundation": "^10.34.0",
"@turf/along": "^6.0.1",
"chroma-js": "^2.4.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/endpoints-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
"url": "https://github.com/opentripplanner/otp-ui/issues"
},
"dependencies": {
"@opentripplanner/base-map": "^3.0.14",
"@opentripplanner/base-map": "^3.0.15",
"@opentripplanner/location-icon": "^1.4.1",
"@opentripplanner/core-utils": "^11.0.2",
"@opentripplanner/core-utils": "^11.1.3",
"flat": "^5.0.2",
"@styled-icons/fa-solid": "^10.34.0"
},
"devDependencies": {
"@opentripplanner/types": "^6.2.0",
"@types/flat": "^5.0.2"
},
"peerDependencies": {
"@opentripplanner/types": "^6.1.0",
"react": "^16.14.0",
"react-dom": "^16.8.6",
"react-intl": "^5.24.6",
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
Expand Up @@ -13,7 +13,7 @@
"flat": "^5.0.2"
},
"devDependencies": {
"@opentripplanner/types": "^6.1.0"
"@opentripplanner/types": "^6.2.0"
},
"peerDependencies": {
"react": "^16.14.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "MIT",
"private": false,
"dependencies": {
"@opentripplanner/core-utils": "^11.0.2",
"@opentripplanner/core-utils": "^11.1.3",
"prop-types": "^15.7.2"
},
"peerDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/itinerary-body/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"license": "MIT",
"private": false,
"dependencies": {
"@opentripplanner/core-utils": "^11.0.2",
"@opentripplanner/core-utils": "^11.1.3",
"@opentripplanner/humanize-distance": "^1.2.0",
"@opentripplanner/icons": "^2.0.5",
"@opentripplanner/icons": "^2.0.6",
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
"@opentripplanner/location-icon": "^1.4.1",
"@styled-icons/fa-solid": "^10.34.0",
"@styled-icons/foundation": "^10.34.0",
Expand All @@ -24,7 +24,7 @@
"string-similarity": "^4.0.4"
},
"devDependencies": {
"@opentripplanner/types": "^6.1.0",
"@opentripplanner/types": "^6.2.0",
"@types/flat": "^5.0.2"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function TransitLegSubheader({
}}
/>
{!isFlex(leg) && (
<ViewStopButton onStopClick={onStopClick} stopId={from.stopId} />
<ViewStopButton onStopClick={onStopClick} stop={from.stop} />
)}
</S.PlaceSubheader>
);
Expand Down
19 changes: 14 additions & 5 deletions packages/itinerary-body/src/otp-react-redux/view-stop-button.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import React, { Component, ReactElement } from "react";
import { Stop, StopEventHandler } from "@opentripplanner/types";
import { FormattedMessage } from "react-intl";

import * as S from "../styled";
import { defaultMessages } from "../util";

interface Props {
onStopClick: ({ stopId: string }) => void;
stopId: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this prop (as a fallback) otherwise it is a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it an either or type, let me know if that's good

interface PropsWithStopId {
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
onStopClick: StopEventHandler;
stopId?: string;
stop?: never;
}
interface PropsWithStop {
onStopClick: StopEventHandler;
stopId?: never;
stop?: Stop;
}

type Props = PropsWithStop | PropsWithStopId;

export default class ViewStopButton extends Component<Props> {
onClick = (): void => {
const { onStopClick, stopId } = this.props;
onStopClick({ stopId });
const { onStopClick, stop, stopId } = this.props;
onStopClick({ ...stop, stopId: "gtfsId" in stop ? stop.gtfsId : stopId });
};

render(): ReactElement {
Expand Down
3 changes: 2 additions & 1 deletion packages/itinerary-body/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Leg,
LegIconComponent,
Place,
Stop,
TransitOperator
} from "@opentripplanner/types";

Expand Down Expand Up @@ -84,7 +85,7 @@ export type SetViewedTripFunction = (tripSection: TripSection) => void;

export interface TransitLegSubheaderProps {
leg: Leg;
onStopClick?: ({ stopId: string }) => void;
onStopClick?: (stop: Stop) => void;
}

export interface TransitLegSummaryProps {
Expand Down
4 changes: 2 additions & 2 deletions packages/location-field/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"private": false,
"dependencies": {
"@conveyal/geocoder-arcgis-geojson": "^0.0.3",
"@opentripplanner/core-utils": "^11.0.2",
"@opentripplanner/geocoder": "^1.4.2",
"@opentripplanner/core-utils": "^11.1.3",
"@opentripplanner/geocoder": "^2.0.0",
"@opentripplanner/humanize-distance": "^1.2.0",
"@opentripplanner/location-icon": "^1.4.1",
"@styled-icons/fa-solid": "^10.34.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/map-popup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"license": "MIT",
"private": false,
"dependencies": {
"@opentripplanner/base-map": "^3.0.14",
"@opentripplanner/core-utils": "^11.0.2",
"@opentripplanner/from-to-location-picker": "^2.1.8",
"@opentripplanner/base-map": "^3.0.15",
"@opentripplanner/core-utils": "^11.1.3",
"@opentripplanner/from-to-location-picker": "^2.1.10",
"flat": "^5.0.2"
},
"devDependencies": {
"@opentripplanner/types": "^6.1.0"
"@opentripplanner/types": "^6.2.0"
},
"peerDependencies": {
"react": "^16.14.0",
Expand Down
38 changes: 23 additions & 15 deletions packages/map-popup/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useCallback } from "react";
import { Styled as BaseMapStyled } from "@opentripplanner/base-map";
import FromToLocationPicker from "@opentripplanner/from-to-location-picker";
// eslint-disable-next-line prettier/prettier
import type { Company, ConfiguredCompany, Location, Station, Stop } from "@opentripplanner/types";
import type { Company, ConfiguredCompany, Location, Station, Stop, StopEventHandler } from "@opentripplanner/types";

import { FormattedMessage, useIntl } from "react-intl";
import { flatten } from "flat";
Expand Down Expand Up @@ -61,16 +61,16 @@ const StationHubDetails = ({ station }: { station: Station }) => {
const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => void; }) => {
return (
<BaseMapStyled.PopupRow>
<strong>
<FormattedMessage
defaultMessage={defaultMessages["otpUi.MapPopup.stopId"]}
description="Displays the stop id"
id="otpUi.MapPopup.stopId"
values={{
stopId: id
}}
/>
</strong>
<strong>
<FormattedMessage
defaultMessage={defaultMessages["otpUi.MapPopup.stopId"]}
description="Displays the stop id"
id="otpUi.MapPopup.stopId"
values={{
stopId: id
}}
/>
</strong>
<S.ViewStopButton onClick={setViewedStop}>
<FormattedMessage
defaultMessage={defaultMessages["otpUi.MapPopup.stopViewer"]}
Expand All @@ -88,9 +88,13 @@ type Props = {
entity: Entity
getEntityName?: (entity: Entity, configCompanies: Company[],) => string;
setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;
setViewedStop?: ({ stopId }: { stopId: string }) => void;
setViewedStop?: StopEventHandler;
};

function entityIsStation(entity: Entity): entity is Station {
return "bikesAvailable" in entity
}

/**
* Renders a map popup for a stop, scooter, or shared bike
*/
Expand All @@ -102,9 +106,8 @@ export function MapPopup({ configCompanies, entity, getEntityName, setLocation,
const name = getNameFunc(entity, configCompanies);


const bikesAvailablePresent = "bikesAvailable" in entity
const bikesAvailablePresent = entityIsStation(entity)
const entityIsStationHub = bikesAvailablePresent && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;
// @ts-expect-error ts doesn't understand entityIsStop
const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(":")[1] || entity.id

return (
Expand All @@ -114,7 +117,12 @@ export function MapPopup({ configCompanies, entity, getEntityName, setLocation,
{entityIsStationHub && <StationHubDetails station={entity} />}

{/* render stop viewer link if available */}
{setViewedStop && !bikesAvailablePresent && <StopDetails id={stopId} setViewedStop={useCallback(() => setViewedStop({ stopId: entity.id }), [entity.id])} />}
{setViewedStop && !bikesAvailablePresent && (
<StopDetails
id={stopId}
setViewedStop={useCallback(() => setViewedStop(entity), [entity])}
/>
)}

{/* The "Set as [from/to]" ButtonGroup */}
{setLocation && (
Expand Down
6 changes: 3 additions & 3 deletions packages/otp2-tile-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"react-map-gl": "^7.0.15"
},
"dependencies": {
"@opentripplanner/map-popup": "^2.0.5"
"@opentripplanner/map-popup": "^2.0.7-alpha.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tile overlay package should probably be released from a separate PR after the map popup package is released.

},
"devDependencies": {
"@opentripplanner/base-map": "^3.0.14",
"@opentripplanner/types": "^6.1.0"
"@opentripplanner/base-map": "^3.0.15",
"@opentripplanner/types": "^6.2.0"
}
}
28 changes: 15 additions & 13 deletions packages/otp2-tile-overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import EntityPopup from "@opentripplanner/map-popup"
import {
ConfiguredCompany,
MapLocationActionArg,
Stop,
StopEventHandler,
} from "@opentripplanner/types"
// eslint-disable-next-line prettier/prettier
import type { EventData } from "mapbox-gl"
Expand Down Expand Up @@ -52,7 +54,7 @@ const OTP2TileLayerWithPopup = ({
* A method fired when the stop viewer is opened in the default popup. If this method is
* not passed, the stop viewer link will not be shown.
*/
setViewedStop?: ({ stopId }: { stopId: string }) => void
setViewedStop?: StopEventHandler
/**
* Determines which layer of the OTP2 tile data to display. Also determines icon color.
*/
Expand Down Expand Up @@ -119,10 +121,10 @@ const OTP2TileLayerWithPopup = ({
map?.on("click", id, onMapClick || defaultClickHandler)

return () => {
map?.off("mouseenter", id, onLayerEnter);
map?.off("mouseleave", id, onLayerLeave);
map?.off("click", id, onMapClick || defaultClickHandler);
};
map?.off("mouseenter", id, onLayerEnter);
map?.off("mouseleave", id, onLayerLeave);
map?.off("click", id, onMapClick || defaultClickHandler);
};
}, [id, map])

return (
Expand All @@ -144,13 +146,13 @@ const OTP2TileLayerWithPopup = ({
// TODO: only set null if the x is clicked, not a new stop
onClose={() => setClickedEntity(null)}
>
<EntityPopup
configCompanies={configCompanies}
entity={{ ...clickedEntity, id: clickedEntity?.id || clickedEntity?.gtfsId }}
setLocation={setLocation ? (location) => { setClickedEntity(null); setLocation(location) } : null}
setViewedStop={setViewedStop}
/>
<EntityPopup
configCompanies={configCompanies}
entity={{ ...clickedEntity, id: clickedEntity?.id || clickedEntity?.gtfsId }}
setLocation={setLocation ? (location) => { setClickedEntity(null); setLocation(location) } : null}
setViewedStop={setViewedStop}
/>

</Popup>
)}
</>
Expand All @@ -173,7 +175,7 @@ const generateOTP2TileLayers = (
layers: { color?: string; name?: string; network?: string; type: string, initiallyVisible?: boolean }[],
endpoint: string,
setLocation?: (location: MapLocationActionArg) => void,
setViewedStop?: ({ stopId }: { stopId: string }) => void,
setViewedStop?: (stop: Stop) => void,
configCompanies?: ConfiguredCompany[]
): JSX.Element[] => {
return [
Expand Down
4 changes: 2 additions & 2 deletions packages/park-and-ride-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"url": "https://github.com/opentripplanner/otp-ui/issues"
},
"dependencies": {
"@opentripplanner/base-map": "^3.0.14",
"@opentripplanner/from-to-location-picker": "^2.1.8"
"@opentripplanner/base-map": "^3.0.15",
"@opentripplanner/from-to-location-picker": "^2.1.10"
},
"peerDependencies": {
"react": "^16.14.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/printable-itinerary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"license": "MIT",
"private": false,
"dependencies": {
"@opentripplanner/core-utils": "^11.0.2",
"@opentripplanner/itinerary-body": "^5.0.7"
"@opentripplanner/core-utils": "^11.1.3",
"@opentripplanner/itinerary-body": "^5.1.2"
},
"devDependencies": {
"@opentripplanner/icons": "^2.0.5"
"@opentripplanner/icons": "^2.0.6"
},
"peerDependencies": {
"react": "^16.14.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/route-viewer-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
},
"dependencies": {
"@mapbox/polyline": "^1.1.0",
"@opentripplanner/base-map": "^3.0.14",
"@opentripplanner/core-utils": "^11.0.2",
"@opentripplanner/base-map": "^3.0.15",
"@opentripplanner/core-utils": "^11.1.3",
"point-in-polygon": "^1.1.0"
},
"devDependencies": {
"@opentripplanner/types": "^6.1.0",
"@opentripplanner/types": "^6.2.0",
"point-in-polygon": "^1.1.0"
},
"peerDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/stop-viewer-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"url": "https://github.com/opentripplanner/otp-ui/issues"
},
"dependencies": {
"@opentripplanner/base-map": "^3.0.14",
"@opentripplanner/core-utils": "^11.0.2"
"@opentripplanner/base-map": "^3.0.15",
"@opentripplanner/core-utils": "^11.1.3"
},
"devDependencies": {
"@opentripplanner/types": "^6.1.0"
"@opentripplanner/types": "^6.2.0"
},
"peerDependencies": {
"react": "^16.14.0",
Expand Down
Loading
Loading