Skip to content

Commit 8b64cdd

Browse files
committed
MirroredStop: Allow editing Trunk Line & Speed Tram status
1 parent e14707b commit 8b64cdd

4 files changed

Lines changed: 66 additions & 4 deletions

File tree

ui/src/components/stop-registry/stops/stop-details/hybrid-stop/MirroredQuayDetailsCard.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export const MirroredQuayDetailsCard: FC<MirroredQuayDetailsCardProps> = ({
9191

9292
const defaultValues: Partial<MirroredQuayFormState> = {
9393
stopState: stopState ?? undefined,
94+
trunkLineStop: details.quay.stopType.trunkLineStop,
95+
speedTramStop: details.quay.stopType.speedTramStop,
9496
reasonForChange: '',
9597
};
9698

@@ -138,6 +140,7 @@ export const MirroredQuayDetailsCard: FC<MirroredQuayDetailsCardProps> = ({
138140
onRemove={() => setShowRemoveDialog(true)}
139141
stop={pseudoStop}
140142
testIdPrefix="MirroredQuayDetails"
143+
transportMode={transportMode}
141144
/>
142145
) : (
143146
<>

ui/src/components/stop-registry/stops/stop-details/hybrid-stop/mirrored-quay-form/MirroredQuayBasicDetailsForm.tsx

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { zodResolver } from '@hookform/resolvers/zod';
22
import { ForwardRefRenderFunction, forwardRef } from 'react';
33
import { FormProvider, useForm } from 'react-hook-form';
44
import { useTranslation } from 'react-i18next';
5+
import { StopRegistryTransportModeType } from '../../../../../../generated/graphql';
56
import { mapStopPlaceStateToUiName } from '../../../../../../i18n/uiNameMappings';
6-
import { Column } from '../../../../../../layoutComponents';
77
import { StopWithDetails } from '../../../../../../types';
88
import { StopPlaceState } from '../../../../../../types/stop-registry';
99
import {
1010
EnumDropdown,
1111
FormActionButtons,
1212
FormColumn,
1313
FormRow,
14+
InputElement,
1415
InputField,
1516
ReasonForChangeForm,
1617
} from '../../../../../forms/common';
@@ -20,6 +21,8 @@ import { MirroredQuayFormState, mirroredQuayFormSchema } from './schema';
2021

2122
const testIds = {
2223
stopPlaceState: 'MirroredQuayForm::stopPlaceState',
24+
trunkLineStop: 'StopBasicDetailsForm::trunkLineStop',
25+
speedTramStop: 'StopBasicDetailsForm::speedTramStop',
2326
};
2427

2528
type MirroredQuayBasicDetailsFormProps = {
@@ -29,13 +32,22 @@ type MirroredQuayBasicDetailsFormProps = {
2932
readonly onRemove: () => void;
3033
readonly stop: StopWithDetails;
3134
readonly testIdPrefix: string;
35+
readonly transportMode: StopRegistryTransportModeType | null | undefined;
3236
};
3337

3438
const MirroredQuayBasicDetailsFormComponent: ForwardRefRenderFunction<
3539
HTMLFormElement,
3640
MirroredQuayBasicDetailsFormProps
3741
> = (
38-
{ defaultValues, onSubmit, onCancel, onRemove, stop, testIdPrefix },
42+
{
43+
defaultValues,
44+
onSubmit,
45+
onCancel,
46+
onRemove,
47+
stop,
48+
testIdPrefix,
49+
transportMode,
50+
},
3951
ref,
4052
) => {
4153
const { t } = useTranslation();
@@ -47,14 +59,17 @@ const MirroredQuayBasicDetailsFormComponent: ForwardRefRenderFunction<
4759
useDirtyFormBlockNavigation(methods.formState, 'MirroredQuayForm');
4860
const { handleSubmit } = methods;
4961

62+
const isBusStop = transportMode === StopRegistryTransportModeType.Bus;
63+
const isTramStop = transportMode === StopRegistryTransportModeType.Tram;
64+
5065
return (
5166
// eslint-disable-next-line react/jsx-props-no-spreading
5267
<FormProvider {...methods}>
5368
<form onSubmit={handleSubmit(onSubmit)} ref={ref}>
5469
<FormColumn>
5570
<StopAreaDetailsSection stop={stop} />
5671
<FormRow mdColumns={4}>
57-
<Column>
72+
<FormColumn>
5873
<InputField<MirroredQuayFormState>
5974
translationPrefix="stopDetails.basicDetails"
6075
fieldPath="stopState"
@@ -72,7 +87,41 @@ const MirroredQuayBasicDetailsFormComponent: ForwardRefRenderFunction<
7287
/>
7388
)}
7489
/>
75-
</Column>
90+
</FormColumn>
91+
92+
<FormColumn className="justify-end">
93+
<label
94+
htmlFor="trunkLineStop"
95+
className="inline-flex font-normal"
96+
>
97+
<InputElement<MirroredQuayFormState>
98+
type="checkbox"
99+
id="trunkLineStop"
100+
fieldPath="trunkLineStop"
101+
className="mr-3.5 h-6 w-6"
102+
testId={testIds.trunkLineStop}
103+
disabled={!isBusStop}
104+
/>
105+
{t(($) => $.stopPlaceTypes.trunkLineStop)}
106+
</label>
107+
</FormColumn>
108+
109+
<FormColumn className="justify-end">
110+
<label
111+
htmlFor="speedTramStop"
112+
className="inline-flex font-normal"
113+
>
114+
<InputElement<MirroredQuayFormState>
115+
type="checkbox"
116+
id="speedTramStop"
117+
fieldPath="speedTramStop"
118+
className="mr-3.5 h-6 w-6"
119+
testId={testIds.speedTramStop}
120+
disabled={!isTramStop}
121+
/>
122+
{t(($) => $.stopPlaceTypes.speedTramStop)}
123+
</label>
124+
</FormColumn>
76125
</FormRow>
77126
<ReasonForChangeForm />
78127
</FormColumn>

ui/src/components/stop-registry/stops/stop-details/hybrid-stop/mirrored-quay-form/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { reasonForChangeFormSchema } from '../../../../../forms/common';
55
export const mirroredQuayFormSchema = z
66
.object({
77
stopState: z.nativeEnum(StopPlaceState),
8+
trunkLineStop: z.boolean(),
9+
speedTramStop: z.boolean(),
810
})
911
.merge(reasonForChangeFormSchema);
1012

ui/src/components/stop-registry/stops/stop-details/hybrid-stop/useEditMirroredQuayDetails.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ export function useEditMirroredQuayDetails() {
3838
key: KnownValueKey.StopState,
3939
values: state.stopState ? [state.stopState] : [],
4040
},
41+
{
42+
key: KnownValueKey.TrunkLineStop,
43+
values: state.stopState ? [state.trunkLineStop.toString()] : [],
44+
},
45+
{
46+
key: KnownValueKey.SpeedTramStop,
47+
values: state.stopState ? [state.speedTramStop.toString()] : [],
48+
},
4149
]),
4250
versionComment: state.reasonForChange,
4351
},

0 commit comments

Comments
 (0)