Skip to content

Commit b11027b

Browse files
authored
Merge pull request #5232 from HSLdevcom/fix-summary-length
DT-5952 - Fix summary length issue with interlining legs
2 parents 1d88729 + 3966243 commit b11027b

File tree

2 files changed

+59
-37
lines changed

2 files changed

+59
-37
lines changed

app/component/itinerary/Itinerary.js

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
getLegBadgeProps,
2222
isCallAgencyLeg,
2323
getInterliningLegs,
24+
isFirstInterliningLeg,
2425
getTotalDistance,
2526
getRouteText,
2627
legTime,
@@ -361,9 +362,6 @@ const Itinerary = (
361362
let waitLength;
362363
const startMs = legTime(leg.start);
363364
const endMs = legTime(leg.end);
364-
const isNextLegLast = i + 1 === compressedLegs.length - 1;
365-
const shouldRenderLastLeg =
366-
isNextLegLast && lastLegLength < renderBarThreshold;
367365
const previousLeg = i > 0 ? compressedLegs[i - 1] : null;
368366
const nextLeg =
369367
i < compressedLegs.length - 1 ? compressedLegs[i + 1] : null;
@@ -387,24 +385,37 @@ const Itinerary = (
387385
}
388386
}
389387

390-
const [interliningLines, interliningLegs] = getInterliningLegs(
391-
compressedLegs,
392-
i,
393-
);
394-
395-
const lastLegWithInterline = interliningLegs[interliningLegs.length - 1];
396-
if (lastLegWithInterline) {
388+
if (isFirstInterliningLeg(compressedLegs, i)) {
389+
const [interliningLines, interliningLegs] = getInterliningLegs(
390+
compressedLegs,
391+
i,
392+
);
397393
interliningWithRoute = interliningLines.join(' / ');
398-
legLength =
399-
((legTime(lastLegWithInterline.end) - startMs) / durationWithoutSlack) *
400-
100;
394+
const lastLegWithInterline = interliningLegs[interliningLegs.length - 1];
395+
legLength = relativeLength(legTime(lastLegWithInterline.end) - startMs);
396+
if (
397+
compressedLegs.length - 2 === i + interliningLegs.length &&
398+
lastLegLength < renderBarThreshold
399+
) {
400+
// If the last interlining leg is the next to last leg and
401+
// if the last leg is too short add its length to the interlining leg.
402+
legLength += lastLegLength;
403+
}
404+
} else if (leg.interlineWithPreviousLeg) {
405+
// Interlining legs after the first one should be skipped, this skips to the next index.
406+
return;
407+
} else if (
408+
compressedLegs.length - 2 === i &&
409+
lastLegLength < renderBarThreshold
410+
) {
411+
// Interlining legs handle this addition differently.
412+
// If this leg is the next to last leg and
413+
// if the last leg is too short add its length to the leg before it.
414+
legLength += lastLegLength;
401415
}
416+
402417
legLength += addition;
403418
addition = 0;
404-
405-
if (shouldRenderLastLeg) {
406-
legLength += lastLegLength; // if the last leg is too short add its length to the leg before it
407-
}
408419
if (legLength < renderBarThreshold && isLegOnFoot(leg)) {
409420
// don't render short legs that are on foot at all
410421
renderBar = false;
@@ -593,25 +604,23 @@ const Itinerary = (
593604
legLength > renderRouteNumberThreshold &&
594605
!longName &&
595606
transitLegCount < 7;
596-
if (!leg.interlineWithPreviousLeg) {
597-
legs.push(
598-
<RouteLeg
599-
key={`${leg.mode}_${startMs}`}
600-
leg={leg}
601-
fitRouteNumber={
602-
(fitAllRouteNumbers && !longName) || renderRouteNumberForALongLeg
603-
}
604-
interliningWithRoute={interliningWithRoute}
605-
intl={intl}
606-
legLength={legLength}
607-
large={breakpoint === 'large'}
608-
withBicycle={withBicycle}
609-
withCar={withCar}
610-
hasOneTransitLeg={hasOneTransitLeg(itinerary)}
611-
shortenLabels={shortenLabels}
612-
/>,
613-
);
614-
}
607+
legs.push(
608+
<RouteLeg
609+
key={`${leg.mode}_${startMs}`}
610+
leg={leg}
611+
fitRouteNumber={
612+
(fitAllRouteNumbers && !longName) || renderRouteNumberForALongLeg
613+
}
614+
interliningWithRoute={interliningWithRoute}
615+
intl={intl}
616+
legLength={legLength}
617+
large={breakpoint === 'large'}
618+
withBicycle={withBicycle}
619+
withCar={withCar}
620+
hasOneTransitLeg={hasOneTransitLeg(itinerary)}
621+
shortenLabels={shortenLabels}
622+
/>,
623+
);
615624
vehicleNames.push(
616625
formatMessage(
617626
{

app/util/legUtils.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export function getRouteText(route, config, interliningWithRoute) {
201201
}
202202

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

223+
/**
224+
* Checks if the given index is the first interlining leg in a set of interlining legs.
225+
* @param {*} legs An array of itinerary legs
226+
* @param {*} index Current index on the array
227+
*/
228+
export function isFirstInterliningLeg(legs, i) {
229+
return (
230+
i + 1 < legs.length &&
231+
!legs[i].interlineWithPreviousLeg &&
232+
legs[i + 1].interlineWithPreviousLeg
233+
);
234+
}
235+
223236
function bikingEnded(leg1) {
224237
return leg1.from.vehicleRentalStation && leg1.mode === 'WALK';
225238
}

0 commit comments

Comments
 (0)