Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions src/lib/sketch/v3/InfrastructureTypeSubform.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,24 @@
import MeasureSubform from "./MeasureSubform.svelte";

export let intervention: V3Intervention;
const intervention_type_options: InfrastructureSubtype[] =
intervention.intervention_type !== ""
? infrastructureFormInformation[intervention.intervention_type].types
$: intervention_type_options = getInterventionTypeOptions(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is important so that the options in the component change whenever a new intervention type is selected

intervention.intervention_type,
);

function getInterventionTypeOptions(
interventionType:
| "amenity"
| "bus_stop_treatment"
| "crossing"
| "junction_treatment"
| "link_segment"
| "place-making"
| "",
): InfrastructureSubtype[] {
return interventionType !== ""
? infrastructureFormInformation[interventionType].types
: [];
}

function getSubtypeObject(
subtype: string,
Expand Down Expand Up @@ -44,11 +58,18 @@
return [original, capitalisedSubsstrings.join(" ")];
}

const subtypes: [string, string][] = intervention_type_options.map(
(type_options) => {
return formatForRadio(type_options.name);
},
);
$: subtypes = getSubtypes(intervention_type_options);

function getSubtypes(
interventionTypeOptions: InfrastructureSubtype[],
): [string, string][] {
if (!interventionTypeOptions) {
return [];
}
return interventionTypeOptions.map((type_option) => {
return formatForRadio(type_option.name);
});
}

$: subtypeObject = getSubtypeObject(
intervention.properties.intervention_subtype,
Expand Down Expand Up @@ -148,25 +169,29 @@
}
</script>

<Radio
label={"Intervention Subtype"}
choices={subtypes}
bind:value={intervention.properties.intervention_subtype}
/>
<Radio
label={"Context"}
choices={contexts}
bind:value={intervention.properties.context}
/>
{#if subtypeObject && subtypeObject.possible_measurements}
{#if subtypes.length > 0}
<Radio
label={"Intervention Subtype"}
choices={subtypes}
bind:value={intervention.properties.intervention_subtype}
/>
{/if}
{#if contexts.length > 0}
<Radio
label={"Context"}
choices={contexts}
bind:value={intervention.properties.context}
/>
{/if}
{#if subtypeObject && subtypeObject.possible_measurements && subtypeObject.possible_measurements.length > 0}
<h2>Measures</h2>
{#each subtypeObject.possible_measurements as _measureObject, index}
<MeasureSubform
bind:interventionMeasure={intervention.properties.measurements[index]}
/>
{/each}
{/if}
{#if contextObject && contextObject.possible_features}
{#if contextObject && contextObject.possible_features && contextObject.possible_features.length > 0}
<h2>Features</h2>
{#each contextObject.possible_features as featureObject, index}
<FeatureSubform
Expand Down
Loading
Loading