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

DT-5952 - Fix summary length issue with interlining legs #5232

Merged
merged 1 commit into from
Jan 17, 2025
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
81 changes: 45 additions & 36 deletions app/component/itinerary/Itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getLegBadgeProps,
isCallAgencyLeg,
getInterliningLegs,
isFirstInterliningLeg,
getTotalDistance,
getRouteText,
legTime,
Expand Down Expand Up @@ -361,9 +362,6 @@ const Itinerary = (
let waitLength;
const startMs = legTime(leg.start);
const endMs = legTime(leg.end);
const isNextLegLast = i + 1 === compressedLegs.length - 1;
const shouldRenderLastLeg =
isNextLegLast && lastLegLength < renderBarThreshold;
const previousLeg = i > 0 ? compressedLegs[i - 1] : null;
const nextLeg =
i < compressedLegs.length - 1 ? compressedLegs[i + 1] : null;
Expand All @@ -387,24 +385,37 @@ const Itinerary = (
}
}

const [interliningLines, interliningLegs] = getInterliningLegs(
compressedLegs,
i,
);

const lastLegWithInterline = interliningLegs[interliningLegs.length - 1];
if (lastLegWithInterline) {
if (isFirstInterliningLeg(compressedLegs, i)) {
const [interliningLines, interliningLegs] = getInterliningLegs(
compressedLegs,
i,
);
interliningWithRoute = interliningLines.join(' / ');
legLength =
((legTime(lastLegWithInterline.end) - startMs) / durationWithoutSlack) *
100;
const lastLegWithInterline = interliningLegs[interliningLegs.length - 1];
legLength = relativeLength(legTime(lastLegWithInterline.end) - startMs);
if (
compressedLegs.length - 2 === i + interliningLegs.length &&
lastLegLength < renderBarThreshold
) {
// If the last interlining leg is the next to last leg and
// if the last leg is too short add its length to the interlining leg.
legLength += lastLegLength;
}
} else if (leg.interlineWithPreviousLeg) {
// Interlining legs after the first one should be skipped, this skips to the next index.
return;
} else if (
compressedLegs.length - 2 === i &&
lastLegLength < renderBarThreshold
) {
// Interlining legs handle this addition differently.
// If this leg is the next to last leg and
// if the last leg is too short add its length to the leg before it.
legLength += lastLegLength;
}

legLength += addition;
addition = 0;

if (shouldRenderLastLeg) {
legLength += lastLegLength; // if the last leg is too short add its length to the leg before it
}
if (legLength < renderBarThreshold && isLegOnFoot(leg)) {
// don't render short legs that are on foot at all
renderBar = false;
Expand Down Expand Up @@ -593,25 +604,23 @@ const Itinerary = (
legLength > renderRouteNumberThreshold &&
!longName &&
transitLegCount < 7;
if (!leg.interlineWithPreviousLeg) {
legs.push(
<RouteLeg
key={`${leg.mode}_${startMs}`}
leg={leg}
fitRouteNumber={
(fitAllRouteNumbers && !longName) || renderRouteNumberForALongLeg
}
interliningWithRoute={interliningWithRoute}
intl={intl}
legLength={legLength}
large={breakpoint === 'large'}
withBicycle={withBicycle}
withCar={withCar}
hasOneTransitLeg={hasOneTransitLeg(itinerary)}
shortenLabels={shortenLabels}
/>,
);
}
legs.push(
<RouteLeg
key={`${leg.mode}_${startMs}`}
leg={leg}
fitRouteNumber={
(fitAllRouteNumbers && !longName) || renderRouteNumberForALongLeg
}
interliningWithRoute={interliningWithRoute}
intl={intl}
legLength={legLength}
large={breakpoint === 'large'}
withBicycle={withBicycle}
withCar={withCar}
hasOneTransitLeg={hasOneTransitLeg(itinerary)}
shortenLabels={shortenLabels}
/>,
);
vehicleNames.push(
formatMessage(
{
Expand Down
15 changes: 14 additions & 1 deletion app/util/legUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function getRouteText(route, config, interliningWithRoute) {
}

/**
* Returns all legs after a given index in which the user can wait in the vehilce for the next transit leg
* Returns all legs after a given index in which the user can wait in the vehicle for the next transit leg
* to start.
* @param {*} legs An array of itinerary legs
* @param {*} index Current index on the array
Expand All @@ -220,6 +220,19 @@ export function getInterliningLegs(legs, index) {
return [uniqueLines, interliningLegs];
}

/**
* Checks if the given index is the first interlining leg in a set of interlining legs.
* @param {*} legs An array of itinerary legs
* @param {*} index Current index on the array
*/
export function isFirstInterliningLeg(legs, i) {
return (
i + 1 < legs.length &&
!legs[i].interlineWithPreviousLeg &&
legs[i + 1].interlineWithPreviousLeg
);
}

function bikingEnded(leg1) {
return leg1.from.vehicleRentalStation && leg1.mode === 'WALK';
}
Expand Down
Loading