Skip to content

Commit 4a96a07

Browse files
committed
make the form work with other infra types
1 parent 570e68d commit 4a96a07

4 files changed

Lines changed: 3525 additions & 3448 deletions

File tree

src/lib/sketch/v3/InfrastructureTypeSubform.svelte

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,24 @@
1212
import MeasureSubform from "./MeasureSubform.svelte";
1313
1414
export let intervention: V3Intervention;
15-
const intervention_type_options: InfrastructureSubtype[] =
16-
intervention.intervention_type !== ""
17-
? infrastructureFormInformation[intervention.intervention_type].types
15+
$: intervention_type_options = getInterventionTypeOptions(
16+
intervention.intervention_type,
17+
);
18+
19+
function getInterventionTypeOptions(
20+
interventionType:
21+
| "amenity"
22+
| "bus_stop_treatment"
23+
| "crossing"
24+
| "junction_treatment"
25+
| "link_segment"
26+
| "place-making"
27+
| "",
28+
): InfrastructureSubtype[] {
29+
return interventionType !== ""
30+
? infrastructureFormInformation[interventionType].types
1831
: [];
32+
}
1933
2034
function getSubtypeObject(
2135
subtype: string,
@@ -44,11 +58,18 @@
4458
return [original, capitalisedSubsstrings.join(" ")];
4559
}
4660
47-
const subtypes: [string, string][] = intervention_type_options.map(
48-
(type_options) => {
49-
return formatForRadio(type_options.name);
50-
},
51-
);
61+
$: subtypes = getSubtypes(intervention_type_options);
62+
63+
function getSubtypes(
64+
interventionTypeOptions: InfrastructureSubtype[],
65+
): [string, string][] {
66+
if (!interventionTypeOptions) {
67+
return [];
68+
}
69+
return interventionTypeOptions.map((type_option) => {
70+
return formatForRadio(type_option.name);
71+
});
72+
}
5273
5374
$: subtypeObject = getSubtypeObject(
5475
intervention.properties.intervention_subtype,
@@ -148,16 +169,20 @@
148169
}
149170
</script>
150171

151-
<Radio
152-
label={"Intervention Subtype"}
153-
choices={subtypes}
154-
bind:value={intervention.properties.intervention_subtype}
155-
/>
156-
<Radio
157-
label={"Context"}
158-
choices={contexts}
159-
bind:value={intervention.properties.context}
160-
/>
172+
{#if subtypes.length > 0}
173+
<Radio
174+
label={"Intervention Subtype"}
175+
choices={subtypes}
176+
bind:value={intervention.properties.intervention_subtype}
177+
/>
178+
{/if}
179+
{#if contexts.length > 0}
180+
<Radio
181+
label={"Context"}
182+
choices={contexts}
183+
bind:value={intervention.properties.context}
184+
/>
185+
{/if}
161186
{#if subtypeObject && subtypeObject.possible_measurements}
162187
<h2>Measures</h2>
163188
{#each subtypeObject.possible_measurements as _measureObject, index}

0 commit comments

Comments
 (0)