From 393a2f77dca37831764b21b5b8d0913271512557 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Mon, 10 Nov 2025 15:21:43 -0600 Subject: [PATCH] the component sets are being properly constructed and passed up to the mode dialog that will control adding the interactions to them --- src/bin/BinVisualizerV2.tsx | 39 ++- src/bin/conditioning/conditioningSelector.tsx | 82 ++++++ src/bin/conditioning/modeChangeDialog.tsx | 275 ++++++++++++++++++ src/bin/conditioning/pickComponentSet.tsx | 125 ++++++++ 4 files changed, 512 insertions(+), 9 deletions(-) create mode 100644 src/bin/conditioning/conditioningSelector.tsx create mode 100644 src/bin/conditioning/modeChangeDialog.tsx create mode 100644 src/bin/conditioning/pickComponentSet.tsx diff --git a/src/bin/BinVisualizerV2.tsx b/src/bin/BinVisualizerV2.tsx index be71eb8..767eaed 100644 --- a/src/bin/BinVisualizerV2.tsx +++ b/src/bin/BinVisualizerV2.tsx @@ -74,6 +74,7 @@ import SearchSelect, { Option } from "common/SearchSelect"; import Edit from "@mui/icons-material/Edit"; import { makeStyles, styled } from "@mui/styles"; import ButtonGroup from "common/ButtonGroup"; +import ModeChangeDialog from "./conditioning/modeChangeDialog"; const useStyles = makeStyles((theme: Theme) => { return ({ @@ -256,7 +257,7 @@ export default function BinVisualizer(props: Props) { const [cfmLowOpen, setCFMLowOpen] = useState(false); const [cfmHighOpen, setCFMHighOpen] = useState(false); const [{ user }] = useGlobalState(); - const [newPreset, setNewPreset] = useState(pond.BinMode.BIN_MODE_NONE); + // const [newPreset, setNewPreset] = useState(pond.BinMode.BIN_MODE_NONE); const [newBinMode, setNewBinMode] = useState(pond.BinMode.BIN_MODE_NONE); const [selectedCable, setSelectedCable] = useState(); const [openNodeDialog, setOpenNodeDialog] = useState(false); @@ -293,6 +294,8 @@ export default function BinVisualizer(props: Props) { const [activePlenumIndex, setActivePlenumIndex] = useState(0) const [combinedPlenums, setCombinedPlenums] = useState([]) + const [openModeChange, setOpenModeChange] = useState(false) + // const StyledToggle = styled(ToggleButton)(({ theme }: { theme: Theme }) => ({ // root: { // backgroundColor: "transparent", @@ -373,7 +376,7 @@ export default function BinVisualizer(props: Props) { useEffect(() => { setIsCustomInventory(bin.storage() !== pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN); setStorageType(bin.storage()); - setNewPreset(pond.BinMode.BIN_MODE_NONE); + // setNewPreset(pond.BinMode.BIN_MODE_NONE); if (bin.settings.inventory) { setMoistureInput(bin.settings.inventory.initialMoisture.toString()); setCustomTypeName(bin.settings.inventory.customTypeName); @@ -2020,16 +2023,18 @@ export default function BinVisualizer(props: Props) { }; const setModeStorage = () => { - setNewPreset(pond.BinMode.BIN_MODE_STORAGE); + // setNewPreset(pond.BinMode.BIN_MODE_STORAGE); setNewBinMode(pond.BinMode.BIN_MODE_STORAGE); + setOpenModeChange(true) }; const setModeCooldown = () => { if (bin.settings.mode === pond.BinMode.BIN_MODE_COOLDOWN) { return; } - setNewPreset(pond.BinMode.BIN_MODE_COOLDOWN); + // setNewPreset(pond.BinMode.BIN_MODE_COOLDOWN); setNewBinMode(pond.BinMode.BIN_MODE_COOLDOWN); + setOpenModeChange(true) }; const setModeDrying = () => { @@ -2037,16 +2042,17 @@ export default function BinVisualizer(props: Props) { bin.settings.inventory && bin.settings.inventory?.initialMoisture < bin.settings.inventory?.targetMoisture ) { - setNewPreset(pond.BinMode.BIN_MODE_HYDRATING); + // setNewPreset(pond.BinMode.BIN_MODE_HYDRATING); setNewBinMode(pond.BinMode.BIN_MODE_HYDRATING); } else { - setNewPreset(pond.BinMode.BIN_MODE_DRYING); + // setNewPreset(pond.BinMode.BIN_MODE_DRYING); setNewBinMode(pond.BinMode.BIN_MODE_DRYING); } + setOpenModeChange(true) }; const closeMoistureDialog = () => { - setNewPreset(0); + // setNewPreset(0); setNewBinMode(bin.settings.mode); setShowInputMoisture(false); }; @@ -2107,7 +2113,7 @@ export default function BinVisualizer(props: Props) { + {/* Confirm - button to enter storage and end conditioning */} + + + + ) + case pond.BinMode.BIN_MODE_COOLDOWN: + case pond.BinMode.BIN_MODE_DRYING: + case pond.BinMode.BIN_MODE_HYDRATING: + return ( + + Choose Device for {modeDescription()} Method + + + {modeDescription()} control is handled by interactions between multiple components on the + same device. Please choose which device and components will handle this bin's{" "} + {modeDescription()}. + + {deviceSelector()} + { + //update the component sets that will be used for the interactions + console.log(sets) + }}/> + + + + + + + ) + } + } + + return ( + {close(false)}}> + {content()} + + ) +} \ No newline at end of file diff --git a/src/bin/conditioning/pickComponentSet.tsx b/src/bin/conditioning/pickComponentSet.tsx new file mode 100644 index 0000000..e2c9acf --- /dev/null +++ b/src/bin/conditioning/pickComponentSet.tsx @@ -0,0 +1,125 @@ +import { CheckBox, ExpandMore } from "@mui/icons-material"; +import { Accordion, AccordionDetails, AccordionSummary, Box, Checkbox, FormControlLabel, Typography } from "@mui/material"; +import { cloneDeep } from "lodash"; +import { Ambient } from "models/Ambient"; +import { Controller } from "models/Controller"; +import { Plenum } from "models/Plenum"; +import React, { useEffect, useState } from "react"; + +export interface ComponentSet { + sensor: Plenum | Ambient, + controllers: Controller[] +} + +interface Props { + sensor: Plenum | Ambient + heaters?: Controller[] + fans?: Controller[] + updateSet: (sensorKey: string, componentSet?: ComponentSet) => void +} + +export default function PickComponentSet(props: Props) { + const {sensor, heaters, fans, updateSet} = props + const [sensorSelected, setSensorSelected] = useState(false) + const [currentSet, setCurrentSet] = useState() + + const controllerIndex = (key: string) => { + if(!currentSet) return -1 + let index = -1 + currentSet.controllers.forEach((cont, i) => { + if(cont.key() === key){ + index = i + } + }) + return index + } + + return ( + + { + setSensorSelected(checked) + let newSet: ComponentSet | undefined + if(checked){ + newSet = { + sensor: sensor, + controllers: [] + } + } + setCurrentSet(newSet) + updateSet(sensor.key(), newSet) + }} + /> + } + label={sensor.name()} + /> + {sensorSelected && currentSet && + + }>Controllers Selected: {currentSet.controllers.length} + + {heaters && heaters.length > 0 && + + Heaters + {heaters.map(heater => ( + { + let set = cloneDeep(currentSet) + if(checked){//if checked need to add it to the controllers + set.controllers.push(heater) + }else{//will need to make sure it is not in the controllers + let index = controllerIndex(heater.key()) + if (index !== -1){ + set.controllers.splice(index, 1) + } + } + setCurrentSet(set) + updateSet(sensor.key(), set) + }} + /> + } + label={heater.name()} + /> + ))} + + } + {fans && fans.length > 0 && + + Fans + {fans.map(fan => ( + { + let set = cloneDeep(currentSet) + if(checked){//if checked need to add it to the controllers + set.controllers.push(fan) + }else{//will need to make sure it is not in the controllers + let index = controllerIndex(fan.key()) + if (index !== -1){ + set.controllers.splice(index, 1) + } + } + setCurrentSet(set) + updateSet(sensor.key(), set) + }} + /> + } + label={fan.name()} + /> + ))} + + } + + + } + + ) +} \ No newline at end of file