|
12 | 12 | import MeasureSubform from "./MeasureSubform.svelte"; |
13 | 13 |
|
14 | 14 | 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 |
18 | 31 | : []; |
| 32 | + } |
19 | 33 |
|
20 | 34 | function getSubtypeObject( |
21 | 35 | subtype: string, |
|
44 | 58 | return [original, capitalisedSubsstrings.join(" ")]; |
45 | 59 | } |
46 | 60 |
|
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 | + } |
52 | 73 |
|
53 | 74 | $: subtypeObject = getSubtypeObject( |
54 | 75 | intervention.properties.intervention_subtype, |
|
148 | 169 | } |
149 | 170 | </script> |
150 | 171 |
|
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} |
161 | 186 | {#if subtypeObject && subtypeObject.possible_measurements} |
162 | 187 | <h2>Measures</h2> |
163 | 188 | {#each subtypeObject.possible_measurements as _measureObject, index} |
|
0 commit comments