Skip to content

Commit 0e41656

Browse files
committed
Use the new PrivateCode based StopAreaDetails links
1 parent 88f107b commit 0e41656

File tree

7 files changed

+74
-11
lines changed

7 files changed

+74
-11
lines changed

ui/src/components/forms/stop/components/StopAreaInfoSection.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useWatch } from 'react-hook-form';
44
import { useTranslation } from 'react-i18next';
55
import { Link } from 'react-router';
66
import { twMerge } from 'tailwind-merge';
7+
import { useObservationDateQueryParam } from '../../../../hooks';
78
import { Path, routeDetails } from '../../../../router/routeDetails';
89
import { ExpandButton } from '../../../../uiComponents';
910
import { LabeledDetail } from '../../../stop-registry/stops/stop-details/layout';
@@ -39,6 +40,10 @@ export const StopAreaInfoSection: FC<StopAreaInfoSectionProps> = ({
3940
const { t } = useTranslation();
4041
const [expanded, setExpanded] = useState(false);
4142

43+
const { observationDate } = useObservationDateQueryParam({
44+
initialize: false,
45+
});
46+
4247
const stopArea = useWatch<StopFormState, 'stopArea'>({ name: 'stopArea' });
4348

4449
if (!stopArea) {
@@ -49,7 +54,10 @@ export const StopAreaInfoSection: FC<StopAreaInfoSectionProps> = ({
4954
<div className={twMerge('flex flex-col', className)}>
5055
<Link
5156
className="flex self-end"
52-
to={routeDetails[Path.stopAreaDetails].getLink(stopArea.netextId)}
57+
to={routeDetails[Path.stopAreaDetails].getLink(
58+
stopArea.privateCode,
59+
observationDate,
60+
)}
5361
target="_blank"
5462
title={t('accessibility:stopAreas.showStopAreaDetails', {
5563
areaLabel: stopArea.nameFin ?? stopArea.nameSwe,

ui/src/components/map/stop-areas/StopAreaPopup.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useTranslation } from 'react-i18next';
22
import { MdAddCircle, MdDelete } from 'react-icons/md';
33
import { Popup } from 'react-map-gl/maplibre';
4+
import { useObservationDateQueryParam } from '../../../hooks';
45
import { Column, Row } from '../../../layoutComponents';
56
import { Path, routeDetails } from '../../../router/routeDetails';
67
import { parseDate } from '../../../time';
@@ -41,6 +42,10 @@ export const StopAreaPopup = ({
4142
}: StopAreaPopupProps) => {
4243
const { t } = useTranslation();
4344

45+
const { observationDate } = useObservationDateQueryParam({
46+
initialize: false,
47+
});
48+
4449
const point = getGeometryPoint(area.geometry);
4550
const areaLabel = area.privateCode?.value;
4651
const areaName = area.name ?? '';
@@ -64,7 +69,10 @@ export const StopAreaPopup = ({
6469
<Row className="items-center">
6570
<h3>
6671
<a
67-
href={routeDetails[Path.stopAreaDetails].getLink(area.id)}
72+
href={routeDetails[Path.stopAreaDetails].getLink(
73+
areaLabel,
74+
observationDate,
75+
)}
6876
target="_blank"
6977
rel="noreferrer"
7078
data-testid={testIds.label}

ui/src/components/stop-registry/search/for-stop-areas/ActionMenu/OpenAreaDetailsPage.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
import { forwardRef } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { useNavigate } from 'react-router';
4+
import { useObservationDateQueryParam } from '../../../../../hooks';
45
import { Path, routeDetails } from '../../../../../router/routeDetails';
56
import { SimpleDropdownMenuItem } from '../../../../../uiComponents';
67

78
type OpenDetailsProps = {
89
readonly className?: string;
9-
readonly netexId: string | null | undefined;
10+
readonly privateCode: string | null | undefined;
1011
readonly testId: string;
1112
};
1213

1314
export const OpenDetails = forwardRef<HTMLButtonElement, OpenDetailsProps>(
14-
({ className, netexId, testId }, ref) => {
15+
({ className, privateCode, testId }, ref) => {
1516
const { t } = useTranslation();
1617
const navigate = useNavigate();
1718

19+
const { observationDate } = useObservationDateQueryParam({
20+
initialize: false,
21+
});
22+
1823
return (
1924
<SimpleDropdownMenuItem
2025
className={className}
2126
text={t('stopRegistrySearch.stopAreaRowActions.openDetails')}
2227
onClick={() =>
23-
navigate(routeDetails[Path.stopAreaDetails].getLink(netexId))
28+
navigate(
29+
routeDetails[Path.stopAreaDetails].getLink(
30+
privateCode,
31+
observationDate,
32+
),
33+
)
2434
}
2535
testId={testId}
2636
ref={ref}
27-
disabled={!netexId}
37+
disabled={!privateCode}
2838
/>
2939
);
3040
},

ui/src/components/stop-registry/search/for-stop-areas/StopAreaHeader.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { FC } from 'react';
44
import { useTranslation } from 'react-i18next';
55
import { Link } from 'react-router';
66
import { twMerge } from 'tailwind-merge';
7+
import { useObservationDateQueryParam } from '../../../../hooks';
78
import { Path, routeDetails } from '../../../../router/routeDetails';
89
import { Point } from '../../../../types';
910
import { LocatorButton } from '../../../../uiComponents';
@@ -43,6 +44,10 @@ export const StopAreaHeader: FC<StopAreaHeaderProps> = ({
4344
}) => {
4445
const { t } = useTranslation();
4546

47+
const { observationDate } = useObservationDateQueryParam({
48+
initialize: false,
49+
});
50+
4651
const showOnMap = useShowStopAreaOnMap();
4752
const point = centroidToPoint(stopArea.centroid);
4853

@@ -59,7 +64,10 @@ export const StopAreaHeader: FC<StopAreaHeaderProps> = ({
5964
)}
6065
>
6166
<Link
62-
to={routeDetails[Path.stopAreaDetails].getLink(stopArea.netex_id)}
67+
to={routeDetails[Path.stopAreaDetails].getLink(
68+
stopArea.private_code,
69+
observationDate,
70+
)}
6371
data-testid={testIds.stopAreaLink}
6472
title={t('accessibility:stopAreas.showStopAreaDetails', {
6573
areaLabel: stopArea.name_value,
@@ -85,7 +93,7 @@ export const StopAreaHeader: FC<StopAreaHeaderProps> = ({
8593
<OpenDetails
8694
key="openDetails"
8795
className={className}
88-
netexId={stopArea.netex_id}
96+
privateCode={stopArea.private_code}
8997
testId={testIds.showStopAreaDetails}
9098
/>
9199
<ShowAreaOnMap

ui/src/components/stop-registry/search/for-stop-areas/StopAreaSearchNoStops.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FC } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { MdOpenInNew } from 'react-icons/md';
44
import { Link } from 'react-router';
5+
import { useObservationDateQueryParam } from '../../../../hooks';
56
import { Path, routeDetails } from '../../../../router/routeDetails';
67
import { FindStopAreaInfo } from './useFindStopAreas';
78

@@ -19,6 +20,10 @@ export const StopAreaSearchNoStops: FC<StopAreaSearchNoStopsProps> = ({
1920
}) => {
2021
const { t } = useTranslation();
2122

23+
const { observationDate } = useObservationDateQueryParam({
24+
initialize: false,
25+
});
26+
2227
return (
2328
<div
2429
className="ml-2 mt-4 flex w-full flex-row items-center gap-1"
@@ -27,7 +32,10 @@ export const StopAreaSearchNoStops: FC<StopAreaSearchNoStopsProps> = ({
2732
<i className="icon-info text-2xl text-brand" />
2833
<p>{t('stopArea.noStops')}</p>
2934
<Link
30-
to={routeDetails[Path.stopAreaDetails].getLink(stopArea.netex_id)}
35+
to={routeDetails[Path.stopAreaDetails].getLink(
36+
stopArea.private_code,
37+
observationDate,
38+
)}
3139
data-testid={testIds.stopAreaLink}
3240
title={t('accessibility:stopAreas.showStopAreaDetails', {
3341
areaLabel: stopArea.name_value,

ui/src/components/stop-registry/stops/stop-details/basic-details/BasicDetailsStopAreaFields.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FC } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { Link } from 'react-router';
4+
import { useObservationDateQueryParam } from '../../../../../hooks';
45
import { Path, routeDetails } from '../../../../../router/routeDetails';
56
import { StopWithDetails } from '../../../../../types';
67
import { AlternativeNames } from '../../../components/AlternativeNames/AlternativeNames';
@@ -34,12 +35,19 @@ export const StopAreaDetailsSection: FC<StopAreaDetailsSectionProps> = ({
3435
}) => {
3536
const { t } = useTranslation();
3637

38+
const { observationDate } = useObservationDateQueryParam({
39+
initialize: false,
40+
});
41+
3742
return (
3843
<div className="-mx-5 -mt-5 bg-background px-5 pt-2.5">
3944
{/* Has negative margin to stretch grey bg to previous div */}
4045
<DetailRow>
4146
<Link
42-
to={routeDetails[Path.stopAreaDetails].getLink(stop.stop_place?.id)}
47+
to={routeDetails[Path.stopAreaDetails].getLink(
48+
stop.stop_place?.privateCode?.value,
49+
observationDate,
50+
)}
4351
data-testid={testIds.areaLink}
4452
title={t('accessibility:stopAreas.showStopAreaDetails', {
4553
areaLabel: stop.stop_place?.name,

ui/src/router/routeDetails.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DateTime } from 'luxon';
12
import qs from 'qs';
23
import { QueryParameterName } from '../hooks/urlQuery/useUrlQuery';
34
import { TranslationKey } from '../i18n';
@@ -126,7 +127,19 @@ export const routeDetails: Record<Path, RouteDetail> = {
126127
includeInNav: false,
127128
},
128129
[Path.stopAreaDetails]: {
129-
getLink: (id: string) => Path.stopAreaDetails.replace(':id', id),
130+
getLink: (id: string, observationDate: DateTime | string = '') => {
131+
const observationDateStr =
132+
observationDate instanceof DateTime
133+
? observationDate.toISODate()
134+
: observationDate;
135+
if (observationDateStr) {
136+
return `${Path.stopAreaDetails.replace(':id', id)}?${qs.stringify({
137+
[QueryParameterName.ObservationDate]: observationDateStr,
138+
})}`;
139+
}
140+
141+
return Path.stopAreaDetails.replace(':id', id);
142+
},
130143
includeInNav: false,
131144
},
132145
[Path.terminalDetails]: {

0 commit comments

Comments
 (0)