Skip to content

Commit

Permalink
refactor(frontend): hazards sidebar
Browse files Browse the repository at this point in the history
- Refactor individual hazard sections as `HazardToggleSection`.
- Use app config to generate individual hazard sections.
  • Loading branch information
eatyourgreens committed Jun 12, 2024
1 parent 67fd3e1 commit 71358f3
Showing 1 changed file with 32 additions and 52 deletions.
84 changes: 32 additions & 52 deletions frontend/src/sidebar/hazards/HazardsControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ import { RCPControl } from 'sidebar/ui/params/RCPControl';
import { useRecoilValue } from 'recoil';
import { showDamagesState } from 'state/damage-mapping/damage-map';
import { Alert, Box } from '@mui/material';
import { HAZARDS_UI_ORDER, HAZARDS_METADATA } from 'config/hazards/metadata';

function HazardToggleSection({ hazard, disabled }) {
const otherProps =
hazard === 'cyclone'
? {
showMarkLabelsFor: [10, 50, 100, 500, 1000, 5000, 10000],
valueLabelDisplay: 'auto',
}
: {};
return (
<ToggleSection id={hazard} label={HAZARDS_METADATA[hazard].label} disabled={disabled}>
<InputSection>
<ReturnPeriodControl
group={hazard}
param="returnPeriod"
disabled={disabled}
{...otherProps}
/>
</InputSection>
<InputSection>
<InputRow>
<EpochControl group={hazard} disabled={disabled} />
<RCPControl group={hazard} disabled={disabled} />
</InputRow>
</InputSection>
</ToggleSection>
);
}

export const HazardsControl = () => {
const showDirectDamages = useRecoilValue(showDamagesState);
Expand All @@ -24,58 +53,9 @@ export const HazardsControl = () => {
</Box>
) : null}
<ToggleSectionGroup toggleState={hazardSelectionState}>
<ToggleSection id="fluvial" label="River Flooding" disabled={disabled}>
<InputSection>
<ReturnPeriodControl group="fluvial" param="returnPeriod" disabled={disabled} />
</InputSection>
<InputSection>
<InputRow>
<EpochControl group="fluvial" disabled={disabled} />
<RCPControl group="fluvial" disabled={disabled} />
</InputRow>
</InputSection>
</ToggleSection>

<ToggleSection id="surface" label="Surface Flooding" disabled={disabled}>
<InputSection>
<ReturnPeriodControl group="surface" param="returnPeriod" disabled={disabled} />
</InputSection>
<InputSection>
<InputRow>
<EpochControl group="surface" disabled={disabled} />
<RCPControl group="surface" disabled={disabled} />
</InputRow>
</InputSection>
</ToggleSection>

<ToggleSection id="coastal" label="Coastal Flooding" disabled={disabled}>
<InputSection>
<ReturnPeriodControl group="coastal" param="returnPeriod" disabled={disabled} />
</InputSection>
<InputSection>
<InputRow>
<EpochControl group="coastal" disabled={disabled} />
<RCPControl group="coastal" disabled={disabled} />
</InputRow>
</InputSection>
</ToggleSection>

<ToggleSection id="cyclone" label="Cyclones" disabled={disabled}>
<InputSection>
<ReturnPeriodControl
group="cyclone"
valueLabelDisplay="auto"
showMarkLabelsFor={[10, 50, 100, 500, 1000, 5000, 10000]}
disabled={disabled}
/>
</InputSection>
<InputSection>
<InputRow>
<EpochControl group="cyclone" disabled={disabled} />
<RCPControl group="cyclone" disabled={disabled} />
</InputRow>
</InputSection>
</ToggleSection>
{HAZARDS_UI_ORDER.map((hazard) => (
<HazardToggleSection key={hazard} hazard={hazard} disabled={disabled} />
))}
</ToggleSectionGroup>
</>
);
Expand Down

0 comments on commit 71358f3

Please sign in to comment.