Skip to content

Commit ea50455

Browse files
committed
Stop Search: transport mode updates
1 parent 207f665 commit ea50455

7 files changed

Lines changed: 137 additions & 69 deletions

File tree

ui/src/components/stop-registry/components/StopTableRow/components/LabelAndTimingPlaceTd.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,28 @@ export const LabelAndTimingPlaceTd: FC<LabelAndTimingPlaceTdProps> = ({
2323
stop,
2424
}) => {
2525
const { t } = useTranslation();
26-
const transportModeIcon = getTransportModeIcon(stop.transportMode);
2726

2827
return (
2928
<td className={className}>
3029
<Row className="items-center leading-none font-bold">
31-
<i
32-
className={twJoin(transportModeIcon, 'mr-1 text-xl')}
33-
title={
34-
stop.transportMode
35-
? mapStopRegistryTransportModeTypeToUiName(t, stop.transportMode)
36-
: undefined
37-
}
38-
/>
30+
{stop.transportModes.map((mode) => (
31+
<i
32+
key={mode}
33+
className={twJoin(
34+
getTransportModeIcon(
35+
mode,
36+
stop.activeTransportModes.includes(mode),
37+
stop.trunkLineStop,
38+
stop.speedTramStop,
39+
),
40+
'text-xl not-last-of-type:-mr-1',
41+
)}
42+
title={mapStopRegistryTransportModeTypeToUiName(t, mode)}
43+
/>
44+
))}
45+
3946
<Link
47+
className="ml-1"
4048
to={routeDetails[Path.stopDetails].getLink(stop.publicCode, {
4149
observationDate,
4250
priority: stop.priority,

ui/src/components/stop-registry/components/StopTableRow/queries/DataFragments.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const GQL_STOP_TABLE_ROW_QUAY_DETAILS = gql`
2121
centroid
2222
description_value
2323
24+
transport_modes
25+
active_transport_modes
26+
speed_tram_stop
27+
trunk_line_stop
28+
2429
stop_place {
2530
id
2631
name_value
@@ -33,10 +38,6 @@ const GQL_STOP_TABLE_ROW_QUAY_DETAILS = gql`
3338
name_value
3439
}
3540
}
36-
}
37-
38-
stop_place_newest_version {
39-
id
4041
4142
TiamatStopPlace {
4243
... on stop_registry_StopPlace {

ui/src/components/stop-registry/components/StopTableRow/types/StopSearchRow.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export type StopSearchRow = {
2626
readonly priority: Priority;
2727

2828
readonly transportMode?: StopRegistryTransportModeType | null;
29+
readonly transportModes: ReadonlyArray<StopRegistryTransportModeType>;
30+
readonly activeTransportModes: ReadonlyArray<StopRegistryTransportModeType>;
31+
readonly speedTramStop: boolean;
32+
readonly trunkLineStop: boolean;
33+
2934
readonly replacesRailSign?: boolean;
3035
readonly electricity?: string | null;
3136
readonly shelter?: string | null;

ui/src/components/stop-registry/components/StopTableRow/utils/mapQueryResultToStopSearchRow.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
getStopPlacesFromQueryResult,
1919
isValidGeoJSONPoint,
2020
log,
21+
parseStopRegistryTransportModeJsonArray,
2122
requireValue,
2223
} from '../../../../../utils';
2324
import { parseStopRegistryTransportMode } from '../../../../../utils/stop-registry/transportMode';
@@ -141,7 +142,7 @@ function mapEquipmentDetails(
141142
| 'shelter'
142143
| 'accessibility'
143144
> {
144-
const tiamatStopPlaces = quay.stop_place_newest_version?.TiamatStopPlace;
145+
const tiamatStopPlaces = quay.stop_place?.TiamatStopPlace;
145146

146147
const [stopPlace] = getStopPlacesFromQueryResult<StopPlace>(tiamatStopPlaces);
147148

@@ -170,6 +171,14 @@ function mapQueryResultToStopSearchRowImpl(
170171
transportMode: parseStopRegistryTransportMode(
171172
quay.stop_place?.transport_mode,
172173
),
174+
transportModes: parseStopRegistryTransportModeJsonArray(
175+
quay.transport_modes,
176+
),
177+
activeTransportModes: parseStopRegistryTransportModeJsonArray(
178+
quay.active_transport_modes,
179+
),
180+
speedTramStop: !!quay.speed_tram_stop,
181+
trunkLineStop: !!quay.trunk_line_stop,
173182

174183
location: validateLocation(quay.centroid),
175184

@@ -235,7 +244,21 @@ function mapSingleTiamatStopAreaQuayToStopSearchRow<
235244
location: validateLocation(quay.geometry),
236245
description: quay.description?.value ?? null,
237246

238-
transportMode: stopArea.transportMode ?? null,
247+
...(stopArea.transportMode
248+
? {
249+
transportMode: stopArea.transportMode,
250+
transportModes: [stopArea.transportMode],
251+
activeTransportModes: [stopArea.transportMode],
252+
speedTramStop: false,
253+
trunkLineStop: false,
254+
}
255+
: {
256+
transportMode: null,
257+
transportModes: [],
258+
activeTransportModes: [],
259+
speedTramStop: false,
260+
trunkLineStop: false,
261+
}),
239262

240263
validityStart: requireValue(
241264
findKeyValueParsed(quay, KnownValueKey.ValidityStart, parseDate),

ui/src/components/stop-registry/search/by-stop/filtersToQueryVariables.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,9 @@ function buildTransportationModeFilter({
9898
}
9999

100100
return {
101-
stop_place: {
102-
transport_mode: {
103-
_in: transportationMode.map(toTiamatDBEnumCase),
104-
},
105-
},
101+
_or: transportationMode.map(toTiamatDBEnumCase).map((mode) => ({
102+
transport_modes: { _contains: mode },
103+
})),
106104
};
107105
}
108106

@@ -310,9 +308,7 @@ export function filtersAndResultSelectionToQueryVariables(
310308
if (excluded.length) {
311309
return buildSearchStopsGqlQueryVariables(
312310
filters,
313-
{
314-
_not: { netex_id: { _in: excluded } },
315-
},
311+
{ _not: { netex_id: { _in: excluded } } },
316312
...extraConditions,
317313
);
318314
}

ui/src/generated/graphql.tsx

Lines changed: 36 additions & 36 deletions
Large diffs are not rendered by default.

ui/src/utils/stop-registry/transportMode.ts

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55

66
const vehicleModeValues = Object.values(ReusableComponentsVehicleModeEnum);
77

8-
export const parseVehicleMode = (
8+
export function parseVehicleMode(
99
transportMode?: string | null,
10-
): ReusableComponentsVehicleModeEnum | null => {
10+
): ReusableComponentsVehicleModeEnum | null {
1111
if (!transportMode) {
1212
return null;
1313
}
@@ -20,27 +20,62 @@ export const parseVehicleMode = (
2020
}
2121

2222
return null;
23-
};
23+
}
2424

2525
const stopRegistryTransportModeValues = Object.values(
2626
StopRegistryTransportModeType,
2727
);
2828

29-
export const parseStopRegistryTransportMode = (
30-
transportMode?: string | StopRegistryTransportModeType | null,
31-
): StopRegistryTransportModeType | null => {
29+
export function parseStopRegistryTransportMode(
30+
transportMode: unknown,
31+
strict: true,
32+
): StopRegistryTransportModeType;
33+
export function parseStopRegistryTransportMode(
34+
transportMode: unknown,
35+
strict?: boolean,
36+
): StopRegistryTransportModeType | null;
37+
export function parseStopRegistryTransportMode(
38+
transportMode: unknown,
39+
strict?: boolean,
40+
): StopRegistryTransportModeType | null {
3241
if (!transportMode) {
3342
return null;
3443
}
3544

36-
const normalizedTransportMode = transportMode.toLowerCase();
45+
if (typeof transportMode !== 'string') {
46+
throw new TypeError(
47+
`Expected transportMode to be a string! But was: typeof(${typeof transportMode})`,
48+
);
49+
}
50+
51+
const normalized = transportMode.toLowerCase();
3752
if (
3853
stopRegistryTransportModeValues.includes(
39-
normalizedTransportMode as StopRegistryTransportModeType,
54+
normalized as StopRegistryTransportModeType,
4055
)
4156
) {
42-
return normalizedTransportMode as StopRegistryTransportModeType;
57+
return normalized as StopRegistryTransportModeType;
58+
}
59+
60+
if (strict) {
61+
throw new TypeError(
62+
`Expected transportMode to be a valid StopRegistryTransportModeType. transportMode(${transportMode}); normalized(${normalized}); StopRegistryTransportModeType(${stopRegistryTransportModeValues})`,
63+
);
4364
}
4465

4566
return null;
46-
};
67+
}
68+
69+
export function parseStopRegistryTransportModeJsonArray(
70+
transportModes: unknown,
71+
): Array<StopRegistryTransportModeType> {
72+
if (!Array.isArray(transportModes)) {
73+
throw new TypeError(
74+
`Expected transportModes to be an array! But was: typeof(${typeof transportModes})`,
75+
);
76+
}
77+
78+
return transportModes
79+
.map((it) => parseStopRegistryTransportMode(it, true))
80+
.sort();
81+
}

0 commit comments

Comments
 (0)