Skip to content

Commit

Permalink
feat: quay public code prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Jan 15, 2025
1 parent 50bb34c commit 797d061
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/page-modules/assistant/details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function AssistantDetails({ tripPattern }: AssistantDetailsProps) {
interchangeDetails={getInterchangeDetails(
tripPattern.legs,
leg.interchangeTo?.toServiceJourney.id,
t
)}
legWaitDetails={getLegWaitDetails(leg, tripPattern.legs[index + 1])}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/page-modules/assistant/details/trip-section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default function TripSection({
>
<Typo.p textType="body__primary">
{getPlaceName(
t,
leg.fromPlace.name,
leg.fromPlace.quay?.name,
leg.fromPlace.quay?.publicCode,
Expand Down Expand Up @@ -213,6 +214,7 @@ export default function TripSection({
>
<Typo.p textType="body__primary">
{getPlaceName(
t,
leg.toPlace.name,
leg.toPlace.quay?.name,
leg.toPlace.quay?.publicCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MonoIcon } from '@atb/components/icon';
import { MessageBox } from '@atb/components/message-box';
import { TripPatternWithDetails } from '../../server/journey-planner/validators';
import { getPlaceName } from '../utils';
import { PageText, useTranslation } from '@atb/translations';
import { PageText, TranslateFunction, useTranslation } from '@atb/translations';

import style from './trip-section.module.css';
import { secondsToDuration } from '@atb/utils/date';
Expand Down Expand Up @@ -96,6 +96,7 @@ function useInterchangeTextTranslation({
export function getInterchangeDetails(
legs: TripPatternWithDetails['legs'],
id: string | undefined,
t: TranslateFunction,
): InterchangeDetails | undefined {
if (!id) return undefined;
const interchangeLeg = legs.find(
Expand All @@ -106,6 +107,7 @@ export function getInterchangeDetails(
return {
publicCode: interchangeLeg.line.publicCode,
fromPlace: getPlaceName(
t,
interchangeLeg.fromPlace.name,
interchangeLeg.fromPlace.quay?.name,
interchangeLeg.fromPlace.quay?.publicCode,
Expand Down
10 changes: 7 additions & 3 deletions src/page-modules/assistant/details/utils.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { fromCETToLocalTime } from '@atb/utils/date';
import { parseTripQueryString } from '../server/journey-planner';
import { TranslateFunction } from '@atb/translations';
import { Assistant } from '@atb/translations/pages';

export function formatQuayName(quayName?: string, publicCode?: string | null) {
export function formatQuayName(t: TranslateFunction, quayName?: string, publicCode?: string | null) {
if (!quayName) return;
if (!publicCode) return quayName;
return `${quayName} ${publicCode}`;
const prefix = t(Assistant.details.quayPublicCodePrefix);
return `${quayName}${prefix ? prefix : ' '}${publicCode}`;
}

export function getPlaceName(
t: TranslateFunction,
placeName?: string,
quayName?: string,
publicCode?: string | null,
): string {
const fallback = placeName ?? '';
return quayName ? formatQuayName(quayName, publicCode) ?? fallback : fallback;
return quayName ? formatQuayName(t, quayName, publicCode) ?? fallback : fallback;
}

export function formatLineName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,70 @@ describe('trip pattern header', function () {
});

it('should get quay name from quay', () => {
const quayName = getQuayName({
publicCode: '',
name: 'Quay',
id: 'NSR:Quay:1',
situations: [],
const Test = function () {
const { t } = useTranslation();
const quayName = getQuayName({
publicCode: '',
name: 'Quay',
id: 'NSR:Quay:1',
situations: [],
}, t);
return <div>{quayName}</div>;
};

customRender(<Test />, {
providerProps: {
initialCookies: {
darkmode: false,
language: 'no',
},
},
});

expect(quayName).toBe('Quay');
expect(screen.getByText('Quay')).toBeInTheDocument();
});

it('should get quay name with public code from quay', () => {
const quayName = getQuayName({
publicCode: '1',
name: 'Quay',
id: 'NSR:Quay:1',
situations: [],
const Test = function () {
const { t } = useTranslation();
const quayName = getQuayName({
publicCode: '1',
name: 'Quay',
id: 'NSR:Quay:1',
situations: [],
}, t);
return <div>{quayName}</div>;
};

customRender(<Test />, {
providerProps: {
initialCookies: {
darkmode: false,
language: 'no',
},
},
});

expect(quayName).toBe('Quay 1');
expect(screen.getByText('Quay 1')).toBeInTheDocument();
});

it('should get quay name from trip', () => {
const quayName = getQuayName(tripPatternFixture.legs[0].fromPlace.quay);
const Test = function () {
const { t } = useTranslation();
const quayName = getQuayName(tripPatternFixture.legs[0].fromPlace.quay, t);
return <div>{quayName}</div>;
};

customRender(<Test />, {
providerProps: {
initialCookies: {
darkmode: false,
language: 'no',
},
},
});

expect(quayName).toBe('From 1');
expect(screen.getByText('From 1')).toBeInTheDocument();
});

it('should get start mode and start place from trip', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RailReplacementBusMessage } from './rail-replacement-bus';
import { SituationOrNoticeIcon } from '@atb/modules/situations';
import { isSubModeBoat } from '@atb/modules/transport-mode';
import { ColorIcon } from '@atb/components/icon';
import { Assistant } from '@atb/translations/pages';

type TripPatternHeaderProps = {
tripPattern: TripPattern;
Expand Down Expand Up @@ -70,9 +71,9 @@ export function getStartModeAndPlaceText(

if (tripPattern.legs[0].mode === 'foot' && tripPattern.legs[1]) {
startLeg = tripPattern.legs[1];
tmpStartName = getQuayName(startLeg.fromPlace.quay);
tmpStartName = getQuayName(startLeg.fromPlace.quay, t);
} else if (tripPattern.legs[0].mode !== 'foot') {
tmpStartName = getQuayName(startLeg.fromPlace.quay);
tmpStartName = getQuayName(startLeg.fromPlace.quay, t);
}

const startName: string =
Expand Down Expand Up @@ -117,8 +118,12 @@ export function getStartModeAndPlaceText(
}
}

export function getQuayName(quay: Quay | null): string | null {
export function getQuayName(
quay: Quay | null,
t: TranslateFunction,
): string | null {
if (!quay) return null;
if (!quay.publicCode) return quay.name;
return `${quay.name} ${quay.publicCode}`;
const prefix = t(Assistant.trip.tripPattern.quayPublicCodePrefix);
return `${quay.name}${prefix ? prefix : ' '}${quay.publicCode}`;
}
4 changes: 2 additions & 2 deletions src/page-modules/assistant/trip/trip-pattern/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const tripSummary = (
let startText = '';

if (tripPattern.legs[0]?.mode === 'foot' && tripPattern.legs[1]) {
const quayName = getQuayName(tripPattern.legs[1]?.fromPlace.quay);
const quayName = getQuayName(tripPattern.legs[1]?.fromPlace.quay, t);

{
quayName
Expand All @@ -43,7 +43,7 @@ export const tripSummary = (
: undefined;
}
} else {
const quayName = getQuayName(tripPattern.legs[0]?.fromPlace.quay);
const quayName = getQuayName(tripPattern.legs[0]?.fromPlace.quay, t);
if (quayName) {
startText = t(
PageText.Assistant.trip.tripSummary.header.title(
Expand Down
3 changes: 2 additions & 1 deletion src/page-modules/departures/details/estimated-call-rows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ type EstimatedCallRowProps = {
collapseButton: JSX.Element | null;
situations: Situation[];
};

function EstimatedCallRow({
call,
mode,
Expand Down Expand Up @@ -171,7 +172,7 @@ function EstimatedCallRow({
href={`/departures/${call.quay.stopPlace.id}`}
>
<Typo.p textType="body__primary">
{formatQuayName(call.quay.name, call.quay.publicCode)}
{formatQuayName(t, call.quay.name, call.quay.publicCode)}
</Typo.p>
{!call.forAlighting && !call.metadata.isStartOfServiceJourney && (
<Typo.p textType="body__secondary" className={style.boardingInfo}>
Expand Down
11 changes: 9 additions & 2 deletions src/page-modules/departures/details/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ServiceJourneyData } from '../server/journey-planner/validators';
import { EstimatedCallMetadata, EstimatedCallWithMetadata } from '../types';
import { TranslateFunction } from '@atb/translations';
import { Departures } from '@atb/translations/pages';

export function addMetadataToEstimatedCalls(
estimatedCalls: ServiceJourneyData['estimatedCalls'][0][],
Expand Down Expand Up @@ -58,8 +60,13 @@ export function getSituationsToShowForCall(
);
}

export function formatQuayName(quayName?: string, publicCode?: string | null) {
export function formatQuayName(
t: TranslateFunction,
quayName?: string,
publicCode?: string | null,
) {
if (!quayName) return;
if (!publicCode) return quayName;
return `${quayName} ${publicCode}`;
const prefix = t(Departures.details.quayPublicCodePrefix);
return `${quayName}${prefix ? prefix : ' '}${publicCode}`;
}
10 changes: 6 additions & 4 deletions src/page-modules/departures/stop-place/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ import { nextDepartures } from '../client';
import style from './stop-place.module.css';
import { formatDestinationDisplay } from '../utils';
import { useTheme } from '@atb/modules/theme';
import { formatQuayName } from '@atb/page-modules/departures/details/utils';

export type StopPlaceProps = {
departures: DepartureData;
};

export function StopPlace({ departures }: StopPlaceProps) {
const { t } = useTranslation();
const { color: {interactive}} = useTheme();
const {
color: { interactive },
} = useTheme();
const router = useRouter();
const [isHoveringRefreshButton, setIsHoveringRefreshButton] = useState(false);

Expand Down Expand Up @@ -135,9 +139,7 @@ export function EstimatedCallList({ quay }: EstimatedCallListProps) {
className={style.textColor__secondary}
textType="body__secondary--bold"
>
{quay.publicCode
? [quay.name, quay.publicCode].join(' ')
: quay.name}
{formatQuayName(t, quay.name, quay.publicCode)}
</Typo.h3>
{quay.description && (
<Typo.span
Expand Down
2 changes: 1 addition & 1 deletion src/translations/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const dictionary = {
readMore: _('Les mer', 'Read more', `Les meir`),
close: _('Lukk', 'Close', 'Lukk'),
listConcatWord: _('og', 'and', 'og'),
via: _('via', 'via', 'via'),
via: _('via', 'via', 'via')
};

export default orgSpecificTranslations(dictionary, {
Expand Down
12 changes: 12 additions & 0 deletions src/translations/pages/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const AssistantInternal = {
_(`Fra ${place}`, `From ${place}`, `Frå ${place}`),
unknownPlace: _('ukjent', 'unknown', 'ukjend'),
},
quayPublicCodePrefix: _('', '', ''),
details: _('Detaljer', 'Details', 'Detaljar'),
hasSituationsTip: _(
'Denne reisen har driftsmeldinger. Se detaljer for mer info',
Expand Down Expand Up @@ -353,6 +354,7 @@ const AssistantInternal = {
`${duration} reisetid`,
),
},
quayPublicCodePrefix: _('', '', ''),
mapSection: {
travelTime: (time: string) =>
_(
Expand Down Expand Up @@ -527,4 +529,14 @@ export const Assistant = orgSpecificTranslations(AssistantInternal, {
},
},
},
vkt: {
details: {
quayPublicCodePrefix: _(' - Spor ', ' - Track ', ' - Spor '),
},
trip: {
tripPattern: {
quayPublicCodePrefix: _(' - Spor ', ' - Track ', ' - Spor '),
}
}
}
});
12 changes: 11 additions & 1 deletion src/translations/pages/departures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { translation as _ } from '@atb/translations/commons';
import { orgSpecificTranslations } from '@atb/translations/utils';

export const Departures = {
const DeparturesInternal = {
title: _('Finn avganger', 'Find departures', 'Finn avgangar'),
titleAddress: (place: string) =>
_(`Stopp nært ${place}`, `Stops near ${place}`, `Stopp nær ${place}`),
Expand Down Expand Up @@ -117,6 +118,7 @@ export const Departures = {
'Back to travel suggestion',
'Tilbake til reiseforslag',
),
quayPublicCodePrefix: _('', '', ''),
lastPassedStop: (stopPlaceName: string, time: string) =>
_(
`Passerte ${stopPlaceName} kl. ${time}`,
Expand Down Expand Up @@ -156,3 +158,11 @@ export const Departures = {
},
},
};

export const Departures = orgSpecificTranslations(DeparturesInternal, {
vkt: {
details: {
quayPublicCodePrefix: _(' - Spor ', ' - Track ', ' - Spor '),
},
},
});

0 comments on commit 797d061

Please sign in to comment.