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

fix: show more nearby stops that are not part of station #4870

Merged
merged 5 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 8 additions & 7 deletions app/component/StopNearYou.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const StopNearYou = (
{ stop, desc, stopId, currentTime, currentMode, relay },
{ config, intl },
) => {
if (!stop.stoptimesWithoutPatterns) {
return null;
}
const [capacityModalOpen, setCapacityModalOpen] = useState(false);
const stopOrStation = stop.parentStation ? stop.parentStation : stop;
const stopMode = stopOrStation.stoptimesWithoutPatterns[0]?.trip.route.mode;
const stopMode = stop.stoptimesWithoutPatterns[0]?.trip.route.mode;
useEffect(() => {
let id = stop.gtfsId;
if (stopId) {
Expand All @@ -31,9 +33,8 @@ const StopNearYou = (
}
}, [currentTime, currentMode]);
const description = desc || stop.desc;
const isStation = !!stop.parentStation || !!stopId;
const gtfsId =
(stop.parentStation && stop.parentStation.gtfsId) || stop.gtfsId;
const isStation = stop.locationType === 'STATION';
const { gtfsId } = stop;
const urlEncodedGtfsId = gtfsId.replace('/', '%2F');
const linkAddress = isStation
? `/${PREFIX_TERMINALS}/${urlEncodedGtfsId}`
Expand All @@ -49,7 +50,7 @@ const StopNearYou = (
<span role="listitem">
<div className="stop-near-you-container">
<StopNearYouHeader
stop={stopOrStation}
stop={stop}
desc={description}
isStation={isStation}
linkAddress={linkAddress}
Expand Down Expand Up @@ -82,7 +83,7 @@ const StopNearYou = (
<StopNearYouDepartureRowContainer
currentTime={currentTime}
mode={stopMode}
stopTimes={stopOrStation.stoptimesWithoutPatterns}
stopTimes={stop.stoptimesWithoutPatterns}
isStation={isStation && stopMode !== 'SUBWAY'}
setCapacityModalOpen={() => setCapacityModalOpen(true)}
/>
Expand Down
58 changes: 6 additions & 52 deletions app/component/StopNearYouContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const containerComponent = createRefetchContainer(
}
zoneId
platformCode
locationType
stoptimesWithoutPatterns(
startTime: $startTime
omitNonPickups: $omitNonPickups
Expand Down Expand Up @@ -67,58 +68,6 @@ const containerComponent = createRefetchContainer(
}
}
}
parentStation {
id
name
gtfsId
code
desc
lat
lon
zoneId
platformCode
alerts {
alertSeverityLevel
alertDescriptionText
}
stoptimesWithoutPatterns(
startTime: $startTime
omitNonPickups: $omitNonPickups
) {
stop {
platformCode
}
realtimeDeparture
realtime
serviceDay
headsign
trip {
gtfsId
occupancy {
occupancyStatus
}
pattern {
code
route {
gtfsId
}
}
route {
alerts {
alertSeverityLevel
}
type
shortName
longName
gtfsId
mode
patterns {
headsign
}
}
}
}
}
}
`,
},
Expand All @@ -132,6 +81,11 @@ const containerComponent = createRefetchContainer(
...StopNearYouContainer_stop
@arguments(startTime: $startTime, omitNonPickups: $omitNonPickups)
}

station(id: $stopId) {
optionsome marked this conversation as resolved.
Show resolved Hide resolved
...StopNearYouContainer_stop
@arguments(startTime: $startTime, omitNonPickups: $omitNonPickups)
}
}
`,
);
Expand Down
55 changes: 9 additions & 46 deletions app/component/StopsNearYouContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class StopsNearYouContainer extends React.Component {

static getDerivedStateFromProps = (nextProps, prevState) => {
let newState = null;
const terminals = [];
if (
!prevState.currentPosition ||
(!prevState.currentPosition.address &&
Expand All @@ -70,36 +69,18 @@ class StopsNearYouContainer extends React.Component {
currentPosition: nextProps.position,
};
}
const checkStops = (t, n) => {
return n.every(stop => {
return (
stop.node.place.parentStation &&
t.indexOf(stop.node.place.parentStation.name) !== -1
);
});
};
if (nextProps.stopPatterns) {
const stopsForFiltering = [...nextProps.stopPatterns.nearest.edges];
const newestStops = stopsForFiltering.splice(
stopsForFiltering.length - 5,
);
stopsForFiltering.forEach(stop => {
const node = stop.node.place;
if (
node.parentStation &&
terminals.indexOf(node.parentStation.name) === -1
) {
terminals.push(node.parentStation.name);
}
});
if (
(newestStops.every(stop => {
newestStops.every(stop => {
return (
stop.node.place.stoptimesWithoutPatterns &&
stop.node.place.stoptimesWithoutPatterns.length === 0
);
}) ||
checkStops(terminals, newestStops)) &&
}) &&
prevState.refetches < prevState.maxRefetches
) {
newState = {
Expand Down Expand Up @@ -199,7 +180,6 @@ class StopsNearYouContainer extends React.Component {
const walkRoutingThreshold =
mode === 'RAIL' || mode === 'SUBWAY' || mode === 'FERRY' ? 3000 : 1500;
const stopPatterns = this.props.stopPatterns.nearest.edges;
const terminalNames = [];
const isCityBikeView = this.props.match.params.mode === 'CITYBIKE';
let sortedPatterns;
if (isCityBikeView) {
Expand Down Expand Up @@ -232,27 +212,13 @@ class StopsNearYouContainer extends React.Component {
stop.stoptimesWithoutPatterns.length > 0
) {
if (!this.props.prioritizedStops?.includes(stop.gtfsId)) {
if (stop.parentStation) {
if (terminalNames.indexOf(stop.parentStation.name) === -1) {
terminalNames.push(stop.parentStation.name);
return (
<StopNearYouContainer
key={`${stop.gtfsId}`}
stop={stop}
currentMode={this.props.match.params.mode}
stopIsStation
/>
);
}
} else {
return (
<StopNearYouContainer
key={`${stop.gtfsId}`}
stop={stop}
currentMode={this.props.match.params.mode}
/>
);
}
return (
<StopNearYouContainer
key={`${stop.gtfsId}`}
stop={stop}
currentMode={this.props.match.params.mode}
/>
);
}
}
break;
Expand Down Expand Up @@ -414,9 +380,6 @@ const refetchContainer = createPaginationContainer(
) {
scheduledArrival
}
parentStation {
name
}
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions app/component/StopsNearYouFavoritesMapContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ const containerComponent = createFragmentContainer(StopsNearYouMapWithStores, {
lat
lon
name
parentStation {
lat
lon
name
gtfsId
}
patterns {
route {
gtfsId
Expand Down
10 changes: 1 addition & 9 deletions app/component/StopsNearYouFavouritesContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,12 @@ function StopsNearYouFavouritesContainer({
const stopElements = stopList.map(stop => {
switch (stop.type) {
case 'stop':
return (
<StopNearYouContainer
key={stop.gtfsId}
stop={stop}
currentMode="FAVORITE"
/>
);
case 'station':
return (
<StopNearYouContainer
key={stop.gtfsId}
stop={stop}
desc={stop.stops[0].desc}
stopId={stop.stops[0].gtfsId}
currentMode="FAVORITE"
/>
);
case 'vehicleRentalStation':
Expand Down
40 changes: 29 additions & 11 deletions app/component/StopsNearYouMapContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ const containerComponent = createPaginationContainer(
lat
lon
name
parentStation {
lat
lon
name
gtfsId
}
patterns {
route {
gtfsId
Expand All @@ -95,6 +89,21 @@ const containerComponent = createPaginationContainer(
points
}
}
stops {
patterns {
route {
gtfsId
shortName
mode
type
}
code
directionId
patternGeometry {
points
}
}
}
stoptimesWithoutPatterns(
startTime: $startTime
omitNonPickups: $omitNonPickups
Expand All @@ -115,11 +124,20 @@ const containerComponent = createPaginationContainer(
lat
lon
name
parentStation {
lat
lon
name
gtfsId
stops {
patterns {
route {
gtfsId
shortName
mode
type
}
code
directionId
patternGeometry {
points
}
}
}
patterns {
route {
Expand Down
2 changes: 1 addition & 1 deletion app/component/StopsNearYouPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class StopsNearYouPage extends React.Component {

getQueryVariables = mode => {
const { searchPosition } = this.state;
let placeTypes = 'STOP';
let placeTypes = ['STOP', 'STATION'];
let modes = [mode];
if (mode === 'CITYBIKE') {
placeTypes = 'BICYCLE_RENT';
Expand Down
14 changes: 1 addition & 13 deletions app/component/map/StopsNearYouMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { graphql, fetchQuery } from 'react-relay';
import moment from 'moment';
import uniqBy from 'lodash/uniqBy';
import compact from 'lodash/compact';
import indexOf from 'lodash/indexOf';
import isEqual from 'lodash/isEqual';
import polyline from 'polyline-encoded';
import distance from '@digitransit-search-util/digitransit-search-util-distance';
Expand Down Expand Up @@ -37,20 +36,9 @@ const locationMarkerModules = {
importLazy(import(/* webpackChunkName: "map" */ './LocationMarker')),
};
const handleStopsAndStations = edges => {
const terminalNames = [];
const stopsAndStations = edges.map(({ node }) => {
const stop = { ...node.place, distance: node.distance };
if (
stop.parentStation &&
indexOf(terminalNames, stop.parentStation.name) === -1
) {
terminalNames.push(stop.parentStation.name);
return { ...stop.parentStation, distance: node.distance };
}
if (!stop.parentStation) {
return stop;
}
return null;
return stop;
});
return compact(stopsAndStations);
};
Expand Down
11 changes: 3 additions & 8 deletions app/util/sortUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,16 @@ export const sortNearbyRentalStations = favouriteRentalStationsIds => {
};

/**
* Sorts favourite stops or stations first. Prioritizes stations if they are within
* a given distance
* Sorts favourite stops or stations first.
*
* @param {Set} favouriteStopIds gtfsIds of favourite stops and stations.
* @param distanceThreshold maximum distance with which the stops are priorized
*/
export const sortNearbyStops = (favouriteStopIds, distanceThreshold) => {
return (first, second) => {
const firstStopOrStationId = first.node.place.parentStation
? first.node.place.parentStation.gtfsId
: first.node.place.gtfsId;
const firstStopOrStationId = first.node.place.gtfsId;
const firstStopOrStationIsClose = first.node.distance < distanceThreshold;
const secondStopOrStationId = second.node.place.parentStation
? second.node.place.parentStation.gtfsId
: second.node.place.gtfsId;
const secondStopOrStationId = second.node.place.gtfsId;
const secondStopOrStationIsClose = second.node.distance < distanceThreshold;
const firstIsFavourite =
favouriteStopIds.has(firstStopOrStationId) && firstStopOrStationIsClose;
Expand Down
Loading