adding display for when the foundaddresses is an empty array

This commit is contained in:
csawatzky 2025-06-30 11:34:43 -06:00
parent c8105ef624
commit ba7852bbc7
2 changed files with 77 additions and 59 deletions

View file

@ -37,6 +37,14 @@ export default function DeviceScannedComponents(props: Props){
useEffect(()=>{
if (scannedComponents.i2c) setScannedI2C(scannedComponents.i2c)
//makes the array empty for testing
// if (scannedComponents.i2c) {
// let clone = cloneDeep(scannedComponents.i2c)
// if (clone.settings){
// clone.settings.foundAddresses = []
// }
// setScannedI2C(clone)
// }
},[scannedComponents])
useEffect(() => {
@ -101,57 +109,56 @@ export default function DeviceScannedComponents(props: Props){
}}
/>
</DialogContent>
<DialogActions>
<Grid2 container direction="row" justifyContent="space-between">
<Grid2>
<Button
variant="contained"
color="primary"
onClick={() => {
close();
}}>
Cancel
</Button>
</Grid2>
<Grid2>
{currentStep !== 0 && (
<Button
sx={{marginX: 1}}
variant="contained"
color="primary"
onClick={() => {
setCurrentStep(currentStep - 1);
}}>
Back
</Button>
)}
{currentStep !== steps.length - 1 && (
<React.Fragment>
<Button
sx={{marginX: 1}}
variant="contained"
color="primary"
onClick={() => {
setCurrentStep(currentStep + 1);
}}>
Next
</Button>
</React.Fragment>
)}
<Button
sx={{marginX: 1}}
variant="contained"
color="primary"
onClick={() => {
//setConfirmationDialogOpen(true)
setOpenDialog(false)
addComponents();
}}>
Confirm
</Button>
</Grid2>
</Grid2>
</DialogActions>
<DialogActions>
<Grid2 container direction="row" justifyContent="space-between">
<Grid2>
<Button
variant="contained"
color="primary"
onClick={() => {
close();
}}>
Cancel
</Button>
</Grid2>
<Grid2>
{currentStep !== 0 && (
<Button
sx={{marginX: 1}}
variant="contained"
color="primary"
onClick={() => {
setCurrentStep(currentStep - 1);
}}>
Back
</Button>
)}
{currentStep !== steps.length - 1 && (
<React.Fragment>
<Button
sx={{marginX: 1}}
variant="contained"
color="primary"
onClick={() => {
setCurrentStep(currentStep + 1);
}}>
Next
</Button>
</React.Fragment>
)}
<Button
sx={{marginX: 1}}
variant="contained"
color="primary"
onClick={() => {
setOpenDialog(false)
addComponents();
}}>
Confirm
</Button>
</Grid2>
</Grid2>
</DialogActions>
</ResponsiveDialog>
);
};
@ -182,14 +189,24 @@ export default function DeviceScannedComponents(props: Props){
<React.Fragment>
<Box>
<Typography sx={{fontWeight: 650}}>
I2C Components Found
I2C Sensors
</Typography>
</Box>
{scannedI2C?.settings?.foundAddresses.map((addr, index) => {
{scannedI2C.settings?.foundAddresses && scannedI2C.settings.foundAddresses.length > 0 ? scannedI2C?.settings?.foundAddresses.map((addr, index) => {
return (
<ScannedI2C key={index} decimalAddress={addr} deviceProduct={device.settings.product} componentSelectionCallback={componentSelection} availablePositions={availablePositions.get(quack.AddressType.ADDRESS_TYPE_I2C) ?? []}/>
<ScannedI2C key={index} sensorNum={index+1} decimalAddress={addr} deviceProduct={device.settings.product} componentSelectionCallback={componentSelection} availablePositions={availablePositions.get(quack.AddressType.ADDRESS_TYPE_I2C) ?? []}/>
)
})}
}) :
<Box sx={{
margin: 1,
display: "flex",
justifyContent: "center"
}}>
<Typography>
No Sensors Found
</Typography>
</Box>
}
</React.Fragment>
}
<Box display="flex" flexDirection="row-reverse" marginTop={2}>

View file

@ -1,4 +1,4 @@
import { Box, Button, Checkbox, FormControlLabel, Grid2, MenuItem, Radio, RadioGroup, TextField, Tooltip } from "@mui/material";
import { Box, Button, Checkbox, FormControlLabel, Grid2, MenuItem, Radio, RadioGroup, TextField, Tooltip, Typography } from "@mui/material";
import { Component } from "models";
import { getAddressTypes, getFriendlyName, getSubtypes, Subtype } from "pbHelpers/ComponentType";
import { ComponentAvailabilityMap, DevicePositions } from "pbHelpers/DeviceAvailability";
@ -12,10 +12,11 @@ interface Props {
deviceProduct: pond.DeviceProduct
componentSelectionCallback: (component: Component, checked: boolean) => void
availablePositions: DevicePositions
sensorNum?: number
}
export default function ScannedI2C(props: Props){
const {decimalAddress, deviceProduct, componentSelectionCallback, availablePositions} = props
const {decimalAddress, deviceProduct, componentSelectionCallback, availablePositions, sensorNum} = props
const [types, setTypes] = useState<quack.ComponentType[]>([])
const [subtypeOptions, setSubtypeOptions] = useState<Array<Subtype>>([])
const [selectedType, setSelectedType] = useState<quack.ComponentType>(quack.ComponentType.COMPONENT_TYPE_INVALID)
@ -90,8 +91,8 @@ export default function ScannedI2C(props: Props){
return (
<Box>
Sensor 1
<Box sx={{marginY: 1}}>
{sensorNum && <Typography>Sensor {sensorNum}</Typography>}
<Grid2 container direction="row" alignItems="center" justifyContent="space-between">
<Grid2 size={3}>
<RadioGroup