Skip to content

Commit 15d3370

Browse files
committed
Add SSP creation for child quays and mirror quay deletion #35370
1 parent 3c0a97c commit 15d3370

3 files changed

Lines changed: 106 additions & 2 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { useCallback, useState } from 'react';
2+
import {
3+
useEditKeyValuesOfQuayMutation,
4+
useGetStopPointsByQuayIdLazyQuery,
5+
useRemoveStopMutation,
6+
} from '../../../../../generated/graphql';
7+
import { StopWithDetails } from '../../../../../types';
8+
import {
9+
removeMirroredBy,
10+
stripKeyValueTypenames,
11+
} from '../../../../../utils/stop-registry/mirrorRelation';
12+
import { useDeleteQuay } from '../../queries/useDeleteQuay';
13+
14+
type RemoveMirrorRelationParams = {
15+
readonly parentStop: StopWithDetails;
16+
readonly childQuayId: string;
17+
readonly childStopPlaceId: string;
18+
};
19+
20+
export function useRemoveMirrorRelation() {
21+
const [loading, setLoading] = useState(false);
22+
23+
const [editKeyValuesOfQuay] = useEditKeyValuesOfQuayMutation({
24+
refetchQueries: ['GetStopDetails'],
25+
awaitRefetchQueries: true,
26+
});
27+
28+
const [getStopPointsByQuayId] = useGetStopPointsByQuayIdLazyQuery();
29+
const [removeStopMutation] = useRemoveStopMutation();
30+
const deleteQuay = useDeleteQuay();
31+
32+
const removeMirrorRelation = useCallback(
33+
async ({
34+
parentStop,
35+
childQuayId,
36+
childStopPlaceId,
37+
}: RemoveMirrorRelationParams) => {
38+
const parentQuayId = parentStop.quay?.id;
39+
const parentStopPlaceId = parentStop.stop_place?.id;
40+
if (!parentQuayId || !parentStopPlaceId) {
41+
return false;
42+
}
43+
44+
setLoading(true);
45+
try {
46+
// 1. Remove the child's SSP (scheduled stop point)
47+
const sspResult = await getStopPointsByQuayId({
48+
variables: { quayIds: [childQuayId] },
49+
});
50+
const childStopPoints =
51+
sspResult.data?.service_pattern_scheduled_stop_point ?? [];
52+
await Promise.all(
53+
childStopPoints.map((ssp) =>
54+
removeStopMutation({
55+
variables: { stop_id: ssp.scheduled_stop_point_id },
56+
}),
57+
),
58+
);
59+
60+
// 2. Delete the child quay from Tiamat
61+
await deleteQuay(childStopPlaceId, childQuayId);
62+
63+
// 3. Remove child from parent's mirroredBy list
64+
const updatedParentKeyValues = removeMirroredBy(
65+
parentStop.quay?.keyValues ?? undefined,
66+
childQuayId,
67+
);
68+
69+
await editKeyValuesOfQuay({
70+
variables: {
71+
stopId: parentStopPlaceId,
72+
quayId: parentQuayId,
73+
keyValues: stripKeyValueTypenames(updatedParentKeyValues),
74+
versionComment: 'Yhteiskäyttöpysäkin poisto',
75+
},
76+
});
77+
78+
return true;
79+
} finally {
80+
setLoading(false);
81+
}
82+
},
83+
[
84+
editKeyValuesOfQuay,
85+
getStopPointsByQuayId,
86+
removeStopMutation,
87+
deleteQuay,
88+
],
89+
);
90+
91+
return { removeMirrorRelation, loading };
92+
}

ui/src/locales/en-US/common.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,13 @@
568568
"metro": "Metro station",
569569
"rail": "Train station",
570570
"water": "Ferry stop"
571-
}
571+
},
572+
"removeButton": "Remove from hybrid",
573+
"removeConfirmTitle": "Remove transport mode",
574+
"removeConfirmDescription": "Are you sure you want to remove this transport mode from hybrid use?",
575+
"removeConfirm": "Remove",
576+
"removeCancel": "Cancel",
577+
"removeSuccess": "Stop removed from hybrid use"
572578
},
573579
"version": {
574580
"copyBoilerPlate": "All properties from the existing stop will be copied over. You can edit the properties of the new copy after its creation.",

ui/src/locales/fi-FI/common.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,13 @@
568568
"metro": "Metroasema",
569569
"rail": "Juna-asema",
570570
"water": "Lauttapysäkki"
571-
}
571+
},
572+
"removeButton": "Poista yhteiskäytöstä",
573+
"removeConfirmTitle": "Poista liikennemuoto",
574+
"removeConfirmDescription": "Haluatko varmasti poistaa tämän liikennemuodon yhteiskäytöstä?",
575+
"removeConfirm": "Poista",
576+
"removeCancel": "Peruuta",
577+
"removeSuccess": "Pysäkki poistettu yhteiskäytöstä"
572578
},
573579
"version": {
574580
"copyBoilerPlate": "Pysäkin kaikki ominaisuudet kopioidaan mukana. Voit muokata uuden version ominaisuuksia kopioinnin jälkeen.",

0 commit comments

Comments
 (0)