Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASA Radio Buttons #3861

Merged
merged 3 commits into from
Aug 19, 2024
Merged
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
61 changes: 61 additions & 0 deletions web/src/features/fba/components/ActualForecastControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { FormControl, FormControlLabel, FormLabel, Radio, RadioGroup } from '@mui/material'
import React from 'react'
import { RunType } from 'features/fba/pages/FireBehaviourAdvisoryPage'
import { isNull } from 'lodash'
import { theme } from 'app/theme'

export interface ActualForecastControlProps {
runType: RunType
setRunType: React.Dispatch<React.SetStateAction<RunType>>
}
const ActualForecastControl = ({ runType, setRunType }: ActualForecastControlProps) => {
const changeHandler = (_: React.ChangeEvent<{}>, value: any | null) => {
if (!isNull(value)) {
setRunType(value)
}
}
return (
<FormControl
variant="outlined"
sx={{
border: '1px solid rgba(0, 0, 0, 0.23)',
borderRadius: '4px',
padding: '8px 12px 4px',
position: 'relative',
margin: theme.spacing(1)
}}
>
<FormLabel
sx={{
fontSize: '0.75rem',
color: 'rgba(0, 0, 0, 0.6)',
position: 'absolute',
top: '-10px',
left: '12px',
backgroundColor: 'white',
padding: '0 4px'
}}
>
Time Frame
</FormLabel>
<RadioGroup row defaultValue={runType} onChange={changeHandler}>
<FormControlLabel
value={RunType.ACTUAL}
control={
<Radio inputProps={{ 'data-testid': 'actual-radio' } as React.InputHTMLAttributes<HTMLInputElement>} />
}
label="Actual"
/>
<FormControlLabel
value={RunType.FORECAST}
control={
<Radio inputProps={{ 'data-testid': 'forecast-radio' } as React.InputHTMLAttributes<HTMLInputElement>} />
}
label="Forecast"
/>
</RadioGroup>
</FormControl>
)
}

export default React.memo(ActualForecastControl)
32 changes: 0 additions & 32 deletions web/src/features/fba/components/AdvisoryMetadata.tsx

This file was deleted.

22 changes: 22 additions & 0 deletions web/src/features/fba/components/actualForecastControl.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import ActualForecastControl from './ActualForecastControl'
import { RunType } from 'features/fba/pages/FireBehaviourAdvisoryPage'

describe('ActualForecastControl', () => {
const mockSetRunType = jest.fn()

it('should render the radio button selector with the correct default', () => {
const { getByTestId } = render(<ActualForecastControl runType={RunType.FORECAST} setRunType={mockSetRunType} />)
const forecastButton = getByTestId('forecast-radio')
expect(forecastButton).toBeChecked()
})

it('should call setRunType with the correct value when a radio button is selected', () => {
const { getByTestId } = render(<ActualForecastControl runType={RunType.FORECAST} setRunType={mockSetRunType} />)
fireEvent.click(getByTestId('actual-radio'))
expect(mockSetRunType).toHaveBeenCalledWith(RunType.ACTUAL)
fireEvent.click(getByTestId('forecast-radio'))
expect(mockSetRunType).toHaveBeenCalledWith(RunType.FORECAST)
})
})
19 changes: 6 additions & 13 deletions web/src/features/fba/pages/FireBehaviourAdvisoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ASA_DOC_TITLE, FIRE_BEHAVIOUR_ADVISORY_NAME, PST_UTC_OFFSET } from 'uti
import WPSDatePicker from 'components/WPSDatePicker'
import { AppDispatch } from 'app/store'
import AdvisoryThresholdSlider from 'features/fba/components/map/AdvisoryThresholdSlider'
import AdvisoryMetadata from 'features/fba/components/AdvisoryMetadata'
import ActualForecastControl from 'features/fba/components/ActualForecastControl'
import { fetchSFMSRunDates } from 'features/fba/slices/runDatesSlice'
import { isNull, isUndefined } from 'lodash'
import { fetchHighHFIFuels } from 'features/fba/slices/hfiFuelTypesSlice'
Expand All @@ -44,11 +44,6 @@ export const FireCentreFormControl = styled(FormControl)({
minWidth: 280
})

export const ForecastActualDropdownFormControl = styled(FormControl)({
margin: theme.spacing(1),
minWidth: 280
})

const FireBehaviourAdvisoryPage: React.FunctionComponent = () => {
const dispatch: AppDispatch = useDispatch()
const { fireCenters } = useSelector(selectFireCenters)
Expand Down Expand Up @@ -176,6 +171,11 @@ const FireBehaviourAdvisoryPage: React.FunctionComponent = () => {
<WPSDatePicker date={dateOfInterest} updateDate={updateDate} />
</StyledFormControl>
</Grid>
<ErrorBoundary>
<Grid item>
<ActualForecastControl runType={runType} setRunType={setRunType} />
</Grid>
</ErrorBoundary>
<Grid item>
<FireCentreFormControl>
<FireCenterDropdown
Expand All @@ -187,13 +187,6 @@ const FireBehaviourAdvisoryPage: React.FunctionComponent = () => {
/>
</FireCentreFormControl>
</Grid>
<ErrorBoundary>
<Grid item>
<ForecastActualDropdownFormControl>
<AdvisoryMetadata runType={runType.toString()} setRunType={setRunType} />
</ForecastActualDropdownFormControl>
</Grid>
</ErrorBoundary>
<Grid item>
<StyledFormControl>
<FormControlLabel
Expand Down
Loading