Skip to content

Commit

Permalink
fix: add condition to check whether passengers should stay seated bet…
Browse files Browse the repository at this point in the history
…ween leg interchanges. (#312)

* Extend trip schema with the property staySeated to identify whether the passengers shall stay seated during interchanges.

* Extended trip details with a message box informing about line number change and not having to change bus.

* Extract condition to make code more readable.

* Add null check and remove exessive function.

* Add null type to staySeated property.
  • Loading branch information
jonasbrunvoll authored Jul 22, 2024
1 parent 7050017 commit 9f187a2
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 49 deletions.
1 change: 1 addition & 0 deletions src/page-modules/assistant/details/trip-section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export default function TripSection({
interchangeDetails={interchangeDetails}
publicCode={leg.line?.publicCode}
maximumWaitTime={leg.interchangeTo?.maximumWaitTime}
staySeated={leg.interchangeTo?.staySeated}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type InterchangeSectionProps = {
interchangeDetails: InterchangeDetails;
publicCode?: string | null;
maximumWaitTime?: number;
staySeated: boolean | undefined | null;
};

export function InterchangeSection(props: InterchangeSectionProps) {
Expand All @@ -43,6 +44,7 @@ function useInterchangeTextTranslation({
publicCode,
interchangeDetails,
maximumWaitTime = 0,
staySeated,
}: InterchangeSectionProps) {
const { t, language } = useTranslation();

Expand All @@ -59,6 +61,16 @@ function useInterchangeTextTranslation({
].join(' ')
: text;

if (publicCode && staySeated) {
return appendWaitTime(
t(
PageText.Assistant.details.tripSection.lineChangeStaySeated(
interchangeDetails.publicCode,
publicCode,
),
),
);
}
if (publicCode) {
return appendWaitTime(
t(
Expand Down
6 changes: 6 additions & 0 deletions src/page-modules/assistant/server/journey-planner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ export function createJourneyApi(
? {
guaranteed: leg.interchangeTo.guaranteed ?? false,
maximumWaitTime: leg.interchangeTo.maximumWaitTime ?? 0,
staySeated: leg.interchangeTo.staySeated,
toServiceJourney: {
id: leg.interchangeTo.toServiceJourney.id,
},
Expand Down Expand Up @@ -565,6 +566,11 @@ function mapResultToTrips(
: null,
}
: null,
interchangeTo: leg.interchangeTo?.staySeated
? {
staySeated: leg.interchangeTo.staySeated,
}
: null,
};
}),
compressedQuery: generateSingleTripQueryString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ query TripsWithDetails(
interchangeTo {
guaranteed
maximumWaitTime
staySeated
toServiceJourney {
id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ fragment tripPattern on TripPattern {
}
}
transportSubmode
interchangeTo {
staySeated
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ query ViaTripsWithDetails(
interchangeTo {
guaranteed
maximumWaitTime
staySeated
toServiceJourney {
id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export const legSchema = z.object({
situations: z.array(situationSchema),
fromPlace: placeSchema,
serviceJourney: serviceJourneySchema.nullable(),
interchangeTo: z
.object({
staySeated: z.boolean().nullable(),
})
.nullable()
.optional(),
});

export const tripPatternSchema = z.object({
Expand Down Expand Up @@ -139,6 +145,7 @@ export const tripPatternWithDetailsSchema = z.object({
.object({
guaranteed: z.boolean(),
maximumWaitTime: z.number(),
staySeated: z.boolean().optional(),
toServiceJourney: z.object({ id: z.string() }),
})
.nullable(),
Expand Down
117 changes: 68 additions & 49 deletions src/page-modules/assistant/trip/trip-pattern/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ export default function TripPattern({
[style['tripPattern--old']]: tripIsInPast,
});

const staySeated = (idx: number) => {
const leg = expandedLegs[idx];
return leg && leg.interchangeTo?.staySeated === true;
};

const isNotLastLeg = (i: number) => {
return i < expandedLegs.length - 1 || collapsedLegs.length > 0;
};

return (
<motion.a
href={`/assistant/${tripPattern.compressedQuery}?filter=${router.query.filter}`}
Expand Down Expand Up @@ -98,61 +107,71 @@ export default function TripPattern({
<div className={style.legs__expandedLegs} ref={legsContentRef}>
{expandedLegs.map((leg, i) => (
<Fragment key={`leg-${leg.expectedStartTime}-${i}`}>
<div className={style.legs__leg}>
{leg.mode ? (
<TransportIconWithLabel
mode={{
transportMode: leg.mode,
transportSubModes: leg.transportSubmode
? [leg.transportSubmode]
: undefined,
}}
label={leg.line?.publicCode ?? undefined}
duration={leg.mode === 'foot' ? leg.duration : undefined}
isFlexible={isLineFlexibleTransport(leg.line)}
/>
) : (
<div className={style.legs__leg__walkIcon}>
<MonoIcon icon="transportation/Walk" />
</div>
)}

<div
className={style.timeStartContainer}
data-testid={`timeStartContainer-${i}`}
>
{secondsBetween(leg.aimedStartTime, leg.expectedStartTime) >
DEFAULT_THRESHOLD_AIMED_EXPECTED_IN_SECONDS ? (
<>
<Typo.span textType="body__tertiary">
{formatToClock(
leg.expectedStartTime,
language,
'floor',
)}
</Typo.span>
{staySeated(i - 1) ? null : (
<div className={style.legs__leg}>
{leg.mode ? (
<TransportIconWithLabel
mode={{
transportMode: leg.mode,
transportSubModes: leg.transportSubmode
? [leg.transportSubmode]
: undefined,
}}
label={leg.line?.publicCode ?? undefined}
duration={
leg.mode === 'foot' ? leg.duration : undefined
}
isFlexible={isLineFlexibleTransport(leg.line)}
/>
) : (
<div className={style.legs__leg__walkIcon}>
<MonoIcon icon="transportation/Walk" />
</div>
)}

<div
className={style.timeStartContainer}
data-testid={`timeStartContainer-${i}`}
>
{secondsBetween(
leg.aimedStartTime,
leg.expectedStartTime,
) > DEFAULT_THRESHOLD_AIMED_EXPECTED_IN_SECONDS ? (
<>
<Typo.span textType="body__tertiary">
{formatToClock(
leg.expectedStartTime,
language,
'floor',
)}
</Typo.span>
<Typo.span
textType="body__tertiary--strike"
className={style.outdatet}
>
{formatToClock(
leg.aimedStartTime,
language,
'floor',
)}
</Typo.span>
</>
) : (
<Typo.span
textType="body__tertiary--strike"
className={style.outdatet}
textType={
isCancelled
? 'body__tertiary--strike'
: 'body__tertiary'
}
>
{formatToClock(leg.aimedStartTime, language, 'floor')}
</Typo.span>
</>
) : (
<Typo.span
textType={
isCancelled
? 'body__tertiary--strike'
: 'body__tertiary'
}
>
{formatToClock(leg.aimedStartTime, language, 'floor')}
</Typo.span>
)}
)}
</div>
</div>
</div>
)}

{(i < expandedLegs.length - 1 || collapsedLegs.length > 0) && (
{isNotLastLeg(i) && !staySeated(i) && (
<div className={style.legs__legLineContainer}>
<div className={style.legs__legLine} />
<div className={style.legs__legLine} />
Expand Down
6 changes: 6 additions & 0 deletions src/translations/pages/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@ const AssistantInternal = {
`Kva er ${publicCode}?`,
),
},
lineChangeStaySeated: (fromPublicCode: string, toPublicCode: string) =>
_(
`Bli sittende. Linjenummeret endres fra ${fromPublicCode} til ${toPublicCode}.`,
`Stay seated. The line number is changing from ${fromPublicCode} to ${toPublicCode}.`,
`Bli sittande. Linjenummeret endrar seg frå ${fromPublicCode} til ${toPublicCode}.`,
),
},
ticketBooking: {
globalMessage: _(
Expand Down

0 comments on commit 9f187a2

Please sign in to comment.