-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Morecast: Empty Cell validation (#3957)
Separate `error` into `error` and `invalid` states, where error is a superset of invalid but includes an empty check. Forecast cells (except for grass curing and wind direction) include both error and invalid state checks. `SaveForecastButton` will set `isRequiredInputSet` redux flag to false if any `rowsToSave` have empty fields that are required. `Forecast` cell subscribes to the state and checks it's own value for emptiness and renders itself accordingly. Note: - put `WindDirectionForecastCell` in it's own component otherwise it renders the cell very wide. If anyone can spot why we could remove it. It should be able to rendered the same way as `ValidatedGrassCureForecastCell`. - unable to get `react-testing-library` to recognize the error border color in cells when they are in error or invalid states
- Loading branch information
Showing
24 changed files
with
605 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { theme } from '@/app/theme' | ||
import InvalidCellToolTip from '@/features/moreCast2/components/InvalidCellToolTip' | ||
import { TextField } from '@mui/material' | ||
import { GridRenderCellParams } from '@mui/x-data-grid-pro' | ||
import React from 'react' | ||
|
||
interface ValidatedCellProps { | ||
disabled: boolean | ||
label: string | ||
error: boolean | ||
invalid: string | ||
value: Pick<GridRenderCellParams, 'formattedValue'> | ||
} | ||
|
||
const ValidatedGrassCureForecastCell = ({ disabled, label, value, invalid, error }: ValidatedCellProps) => { | ||
const testTag = error ? 'validated-forecast-cell-error' : 'validated-forecast-cell' | ||
return ( | ||
<InvalidCellToolTip invalid={invalid}> | ||
<TextField | ||
data-testid={testTag} | ||
disabled={disabled} | ||
size="small" | ||
label={label} | ||
InputLabelProps={{ | ||
shrink: true | ||
}} | ||
sx={{ | ||
'& .MuiOutlinedInput-root': { | ||
backgroundColor: `${theme.palette.common.white}`, | ||
'& fieldset': { | ||
borderColor: error ? theme.palette.error.main : '#737373', | ||
borderWidth: '2px' | ||
}, | ||
'&:hover fieldset': { | ||
borderColor: error ? theme.palette.error.main : '#737373' | ||
}, | ||
'&.Mui-focused fieldset': { | ||
borderColor: error ? theme.palette.error.main : '#737373', | ||
borderWidth: '2px' | ||
} | ||
}, | ||
'& .Mui-disabled': { | ||
'& fieldset': { | ||
borderWidth: '1px' | ||
} | ||
} | ||
}} | ||
value={value} | ||
></TextField> | ||
</InvalidCellToolTip> | ||
) | ||
} | ||
|
||
export default React.memo(ValidatedGrassCureForecastCell) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
web/src/features/moreCast2/components/ValidatedGrassCureForecastCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react' | ||
import { GridRenderCellParams } from '@mui/x-data-grid-pro' | ||
import ValidatedCell from '@/features/moreCast2/components/ValidatedCell' | ||
import { Box } from '@mui/material' | ||
|
||
interface ValidatedGrassCureForecastCellProps { | ||
disabled: boolean | ||
label: string | ||
value: Pick<GridRenderCellParams, 'formattedValue'> | ||
validator?: (value: string) => string | ||
} | ||
|
||
const ValidatedGrassCureForecastCell = ({ disabled, label, value, validator }: ValidatedGrassCureForecastCellProps) => { | ||
const error = validator ? validator(value as string) : '' | ||
return ( | ||
<Box data-testid="validated-gc-forecast-cell"> | ||
<ValidatedCell disabled={disabled} label={label} error={error !== ''} invalid={error} value={value} /> | ||
</Box> | ||
) | ||
} | ||
|
||
export default React.memo(ValidatedGrassCureForecastCell) |
28 changes: 28 additions & 0 deletions
28
web/src/features/moreCast2/components/ValidatedWindDirectionForecastCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Grid } from '@mui/material' | ||
import { GridRenderCellParams } from '@mui/x-data-grid-pro' | ||
import ValidatedCell from '@/features/moreCast2/components/ValidatedCell' | ||
|
||
interface ForecastCellProps { | ||
disabled: boolean | ||
label: string | ||
value: Pick<GridRenderCellParams, 'formattedValue'> | ||
validator?: (value: string) => string | ||
} | ||
|
||
const ValidatedWindDirectionForecastCell = ({ disabled, label, value, validator }: ForecastCellProps) => { | ||
const error = validator ? validator(value as string) : '' | ||
|
||
return ( | ||
<Grid | ||
container | ||
sx={{ justifyContent: 'center', alignItems: 'center' }} | ||
data-testid="validated-winddir-forecast-cell" | ||
> | ||
<Grid item xs={8}> | ||
<ValidatedCell disabled={disabled} label={label} value={value} error={error !== ''} invalid={error} /> | ||
</Grid> | ||
</Grid> | ||
) | ||
} | ||
|
||
export default ValidatedWindDirectionForecastCell |
Oops, something went wrong.