Skip to content

Commit 08126e6

Browse files
committed
StopSearch: Flow down observationDate
Instead of using the old `useObservationDateQueryParam`, which in turn uses `useUrlQuery` to read and parse the value, the original value is passed down directly from the source of truth. Thus, ridding the Stop Search page completely from the old untyped `useUrlQuery` implementation.
1 parent 6b8ad10 commit 08126e6

File tree

12 files changed

+73
-16
lines changed

12 files changed

+73
-16
lines changed

ui/src/components/stop-registry/search/by-line/LineRoutesListing.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
import { DateTime } from 'luxon';
12
import { FC, useDeferredValue } from 'react';
23
import { SortingInfo } from '../types';
34
import { RouteStopsTable } from './RouteStopsTable';
45
import { FindStopByLineInfo } from './useFindLinesByStopSearch';
56

67
type LineRoutesListingProps = {
78
readonly line: FindStopByLineInfo;
9+
readonly observationDate: DateTime;
810
readonly sortingInfo: SortingInfo;
911
};
1012

1113
export const LineRoutesListing: FC<LineRoutesListingProps> = ({
1214
line,
15+
observationDate,
1316
sortingInfo,
1417
}) => {
1518
// Rendering all the routes into tables is a slow process.
@@ -23,6 +26,7 @@ export const LineRoutesListing: FC<LineRoutesListingProps> = ({
2326
className="mt-6"
2427
key={route.route_id}
2528
lineTransitionInProgress={lineTransitionInProgress}
29+
observationDate={observationDate}
2630
route={route}
2731
sortingInfo={sortingInfo}
2832
/>

ui/src/components/stop-registry/search/by-line/RouteStopsTable.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DateTime } from 'luxon';
12
import { FC } from 'react';
23
import { useTranslation } from 'react-i18next';
34
import { Visible } from '../../../../layoutComponents';
@@ -21,13 +22,15 @@ type RouteStopsTableProps = {
2122
// Enable asynchronous rendering of the result tables on the background.
2223
// Aka, do not lock up the ui.
2324
readonly lineTransitionInProgress: boolean;
25+
readonly observationDate: DateTime;
2426
readonly route: FindStopByLineRouteInfo;
2527
readonly sortingInfo: SortingInfo;
2628
};
2729

2830
export const RouteStopsTable: FC<RouteStopsTableProps> = ({
2931
className,
3032
lineTransitionInProgress,
33+
observationDate,
3134
route,
3235
sortingInfo,
3336
}) => {
@@ -53,7 +56,10 @@ export const RouteStopsTable: FC<RouteStopsTableProps> = ({
5356
loading={lineTransitionInProgress || (loading && stops.length === 0)}
5457
>
5558
<Visible visible={!lineTransitionInProgress && stops.length > 0}>
56-
<StopSearchResultStopsTable stops={stops} />
59+
<StopSearchResultStopsTable
60+
observationDate={observationDate}
61+
stops={stops}
62+
/>
5763
</Visible>
5864
</LoadingWrapper>
5965
</div>

ui/src/components/stop-registry/search/by-line/StopsByLineNongroupedStopsResults.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DateTime } from 'luxon';
12
import { Dispatch, FC, SetStateAction } from 'react';
23
import { useTranslation } from 'react-i18next';
34
import { Visible } from '../../../../layoutComponents';
@@ -19,6 +20,7 @@ const testIds = {
1920

2021
type StopsByLineNongroupedStopsResultsProps = {
2122
readonly lines: ReadonlyArray<FindStopByLineInfo>;
23+
readonly observationDate: DateTime;
2224
readonly pagingInfo: PagingInfo;
2325
readonly setPagingInfo: (pagingInfo: PagingInfo) => void;
2426
readonly setSortingInfo: Dispatch<SetStateAction<SortingInfo>>;
@@ -27,7 +29,14 @@ type StopsByLineNongroupedStopsResultsProps = {
2729

2830
export const StopsByLineNongroupedStopsResults: FC<
2931
StopsByLineNongroupedStopsResultsProps
30-
> = ({ lines, pagingInfo, setPagingInfo, setSortingInfo, sortingInfo }) => {
32+
> = ({
33+
lines,
34+
observationDate,
35+
pagingInfo,
36+
setPagingInfo,
37+
setSortingInfo,
38+
sortingInfo,
39+
}) => {
3140
const { t } = useTranslation();
3241

3342
const {
@@ -67,7 +76,12 @@ export const StopsByLineNongroupedStopsResults: FC<
6776
<LoadingStopsErrorRow error={error} refetch={stopsRefetch} />
6877
)}
6978

70-
{!error && <StopSearchResultStopsTable stops={stops} />}
79+
{!error && (
80+
<StopSearchResultStopsTable
81+
observationDate={observationDate}
82+
stops={stops}
83+
/>
84+
)}
7185

7286
<Visible visible={!!resultCount}>
7387
<div className="grid grid-cols-4">

ui/src/components/stop-registry/search/by-line/StopsByLineSearchGroupedStopsResults.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DateTime } from 'luxon';
12
import {
23
Dispatch,
34
FC,
@@ -16,14 +17,21 @@ import { FindStopByLineInfo } from './useFindLinesByStopSearch';
1617

1718
type StopsByLineSearchGroupedStopsResultsProps = {
1819
readonly lines: ReadonlyArray<FindStopByLineInfo>;
20+
readonly observationDate: DateTime;
1921
readonly setPagingInfo: (pagingInfo: PagingInfo) => void;
2022
readonly setSortingInfo: Dispatch<SetStateAction<SortingInfo>>;
2123
readonly sortingInfo: SortingInfo;
2224
};
2325

2426
export const StopsByLineSearchGroupedStopsResults: FC<
2527
StopsByLineSearchGroupedStopsResultsProps
26-
> = ({ lines, setPagingInfo, setSortingInfo, sortingInfo }) => {
28+
> = ({
29+
lines,
30+
observationDate,
31+
setPagingInfo,
32+
setSortingInfo,
33+
sortingInfo,
34+
}) => {
2735
const [activeLineIds, setActiveLineIds] =
2836
useState<ReadonlyArray<UUID> | null>(
2937
lines.at(0)?.line_id ? [lines.at(0)?.line_id as string] : null,
@@ -83,7 +91,11 @@ export const StopsByLineSearchGroupedStopsResults: FC<
8391
{linesToShow.map((line) => (
8492
<>
8593
<ActiveLineHeader line={line} className="mt-6" />
86-
<LineRoutesListing line={line} sortingInfo={sortingInfo} />
94+
<LineRoutesListing
95+
observationDate={observationDate}
96+
line={line}
97+
sortingInfo={sortingInfo}
98+
/>
8799
</>
88100
))}
89101
</>

ui/src/components/stop-registry/search/by-line/StopsByLineSearchResults.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ export const StopsByLineSearchResults: FC<StopSearchResultsProps> = ({
3535
{groupByLine ? (
3636
<StopsByLineSearchGroupedStopsResults
3737
lines={lines}
38+
observationDate={filters.observationDate}
3839
setPagingInfo={setPagingInfo}
3940
setSortingInfo={setSortingInfo}
4041
sortingInfo={sortingInfo}
4142
/>
4243
) : (
4344
<StopsByLineNongroupedStopsResults
4445
lines={lines}
46+
observationDate={filters.observationDate}
4547
pagingInfo={pagingInfo}
4648
setPagingInfo={setPagingInfo}
4749
setSortingInfo={setSortingInfo}

ui/src/components/stop-registry/search/by-stop/StopSearchByStopResults.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export const StopSearchByStopResults: FC<StopSearchResultsProps> = ({
4545
{error ? (
4646
<LoadingStopsErrorRow error={error} refetch={refetch} />
4747
) : (
48-
<StopSearchResultStopsTable stops={stops} />
48+
<StopSearchResultStopsTable
49+
observationDate={filters.observationDate}
50+
stops={stops}
51+
/>
4952
)}
5053

5154
<Visible visible={!!resultCount}>

ui/src/components/stop-registry/search/components/StopPlaceSharedComponents/GroupedStopsResults.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DateTime } from 'luxon';
12
import {
23
ComponentType,
34
Dispatch,
@@ -24,6 +25,7 @@ type NoStopsComponentProps = {
2425
};
2526

2627
type SearchGroupedStopsResultsProps = {
28+
readonly observationDate: DateTime;
2729
readonly setPagingInfo: (pagingInfo: PagingInfo) => void;
2830
readonly setSortingInfo: Dispatch<SetStateAction<SortingInfo>>;
2931
readonly sortingInfo: SortingInfo;
@@ -35,6 +37,7 @@ type SearchGroupedStopsResultsProps = {
3537
};
3638

3739
export const SearchGroupedStopsResults: FC<SearchGroupedStopsResultsProps> = ({
40+
observationDate,
3841
setPagingInfo,
3942
setSortingInfo,
4043
sortingInfo,
@@ -106,9 +109,10 @@ export const SearchGroupedStopsResults: FC<SearchGroupedStopsResultsProps> = ({
106109

107110
{selectedStopPlaces.map((stopPlace) => (
108111
<StopsTable
112+
className="mb-6 last:mb-0"
109113
key={stopPlace.id}
114+
observationDate={observationDate}
110115
stopPlace={stopPlace}
111-
className="mb-6 last:mb-0"
112116
HeaderComponent={HeaderComponent}
113117
NoStopsComponent={NoStopsComponent}
114118
/>

ui/src/components/stop-registry/search/components/StopPlaceSharedComponents/NongroupedStopsResults.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DateTime } from 'luxon';
12
import { ComponentType, Dispatch, FC, SetStateAction } from 'react';
23
import { useTranslation } from 'react-i18next';
34
import { Visible } from '../../../../../layoutComponents';
@@ -16,6 +17,7 @@ const testIds = {
1617
};
1718

1819
type NongroupedStopsResults = {
20+
readonly observationDate: DateTime;
1921
readonly pagingInfo: PagingInfo;
2022
readonly setPagingInfo: (pagingInfo: PagingInfo) => void;
2123
readonly setSortingInfo: Dispatch<SetStateAction<SortingInfo>>;
@@ -25,6 +27,7 @@ type NongroupedStopsResults = {
2527
};
2628

2729
export const NongroupedStopsResults: FC<NongroupedStopsResults> = ({
30+
observationDate,
2831
pagingInfo,
2932
setPagingInfo,
3033
setSortingInfo,
@@ -55,7 +58,10 @@ export const NongroupedStopsResults: FC<NongroupedStopsResults> = ({
5558
{error ? (
5659
<LoadingStopsErrorRow error={error} refetch={refetch} />
5760
) : (
58-
<StopSearchResultStopsTable stops={stops} />
61+
<StopSearchResultStopsTable
62+
observationDate={observationDate}
63+
stops={stops}
64+
/>
5965
)}
6066

6167
<Visible visible={!!resultCount}>

ui/src/components/stop-registry/search/components/StopPlaceSharedComponents/StopsTable.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DateTime } from 'luxon';
12
import { ComponentType, FC } from 'react';
23
import { useTranslation } from 'react-i18next';
34
import { Visible } from '../../../../../layoutComponents';
@@ -13,6 +14,7 @@ const testIds = {
1314

1415
type StopsTableProps = {
1516
readonly className?: string;
17+
readonly observationDate: DateTime;
1618
readonly stopPlace: FindStopPlaceInfo;
1719
readonly HeaderComponent: ComponentType<{
1820
stopPlace: FindStopPlaceInfo;
@@ -25,6 +27,7 @@ type StopsTableProps = {
2527

2628
export const StopsTable: FC<StopsTableProps> = ({
2729
className,
30+
observationDate,
2831
stopPlace,
2932
HeaderComponent,
3033
NoStopsComponent,
@@ -51,7 +54,10 @@ export const StopsTable: FC<StopsTableProps> = ({
5154
loading={loading && stops.length === 0}
5255
>
5356
<Visible visible={stops.length > 0}>
54-
<StopSearchResultStopsTable stops={stops} />
57+
<StopSearchResultStopsTable
58+
observationDate={observationDate}
59+
stops={stops}
60+
/>
5561
</Visible>
5662
</LoadingWrapper>
5763

ui/src/components/stop-registry/search/components/StopSearchResultStopsTable.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { DateTime } from 'luxon';
22
import { FC } from 'react';
33
import { twMerge } from 'tailwind-merge';
4-
import { useObservationDateQueryParam } from '../../../../hooks';
54
import { getGeometryPoint } from '../../../../utils';
65
import {
76
LocatorActionButton,
@@ -45,16 +44,13 @@ const StopSearchResultRow: FC<StopSearchResultRowProps> = ({
4544

4645
type StopSearchResultStopsTableProps = {
4746
readonly className?: string;
47+
readonly observationDate: DateTime;
4848
readonly stops: ReadonlyArray<StopSearchRow>;
4949
};
5050

5151
export const StopSearchResultStopsTable: FC<
5252
StopSearchResultStopsTableProps
53-
> = ({ className, stops }) => {
54-
const { observationDate } = useObservationDateQueryParam({
55-
initialize: false,
56-
});
57-
53+
> = ({ className, observationDate, stops }) => {
5854
return (
5955
<table
6056
className={twMerge('h-1 w-full border-x border-x-light-grey', className)}
@@ -64,7 +60,7 @@ export const StopSearchResultStopsTable: FC<
6460
{stops.map((stop: StopSearchRow) => (
6561
<StopSearchResultRow
6662
key={stop.id}
67-
observationDate={observationDate ?? null}
63+
observationDate={observationDate}
6864
stop={stop}
6965
/>
7066
))}

0 commit comments

Comments
 (0)