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}>