diff --git a/src/bin/binSummary/BinSummary.tsx b/src/bin/binSummary/BinSummary.tsx index 61e6980..7519e53 100644 --- a/src/bin/binSummary/BinSummary.tsx +++ b/src/bin/binSummary/BinSummary.tsx @@ -1,4 +1,4 @@ -import { Box, Card, Grid2, LinearProgress, Typography } from "@mui/material"; +import { Box, Card, DialogContent, DialogTitle, Grid2, IconButton, LinearProgress, Switch, Typography } from "@mui/material"; import { useMobile } from "hooks"; import { Bin, Component, Device } from "models"; import Bin3dVisualizer from "./components/bin3dVisualizer"; @@ -12,6 +12,10 @@ import { pond } from "protobuf-ts/pond"; import BinDetails from "./components/binDetails"; import { Plenum } from "models/Plenum"; import BinSensorsDisplay from "../binSensorsDisplay"; +import ResponsiveDialog from "common/ResponsiveDialog"; +import { useState } from "react"; +import SearchSelect from "common/SearchSelect"; +import ChangeGrainDialog from "grain/ChangeGrainDialog"; interface Props { bin: Bin @@ -34,6 +38,7 @@ export default function BinSummary(props: Props){ const {bin, devices, fans, heaters, permissions, componentDevices, componentMap, binPrefs, updateBinCallback, cables = [], plenums = [], setPreferences} = props //const [currentDevice, setCurrentDevice] = useState(undefined) const isMobile = useMobile() + const [openGrainDialog, setOpenGrainDialog] = useState(false) // useEffect(() => { // if(devices.length > 0){ @@ -71,79 +76,90 @@ export default function BinSummary(props: Props){ ) } + const inventorySummary = () => { + return ( + + + + {/* Grain Type */} + + + Grain Type + + setOpenGrainDialog(true)} + sx={{ + cursor: "pointer", + mt: 0.5, + px: 1, + py: 0.5, + borderRadius: 1, + border: "1px solid", + borderColor: grey[700], + "&:hover": { + borderColor: grey[500], + backgroundColor: "rgba(255,255,255,0.05)", + }, + }} + > + + {bin.grainName()} + + + + {/* Bin Fill */} + + + Bin Fill + + + + {bin.binFillCap()} + + + + + + {/* Last Updated */} + + + Last Updated + + + + + + {moment(bin.status.timestamp).fromNow()} + + + {activity(bin.status.timestamp)} + + + + + ); + }; + return ( - - - - - Grain Type - - - - {/* */} - {bin.grainName()} - - - - - Bin Fill - - - - {bin.binFillCap()} - - - - - - - Last Updated - - {/* this would be to show the last time the device checked in */} - {/* {currentDevice ? - - - - - {moment(currentDevice.status.lastActive).fromNow()} - - - {activity(currentDevice.status.lastActive)} - - : - - - No Connected Devices Found - - - } */} - {/* this shows the last time the bins status updated */} - - - - - {moment(bin.status.timestamp).fromNow()} - - - {activity(bin.status.timestamp)} - - - - + setOpenGrainDialog(false)} permissions={permissions} updateBin={updateBinCallback}/> + {inventorySummary()} diff --git a/src/bin/binTableView.tsx b/src/bin/binTableView.tsx index d7eb26d..0c9958d 100644 --- a/src/bin/binTableView.tsx +++ b/src/bin/binTableView.tsx @@ -394,41 +394,6 @@ export default function BinTableView(props: Props) { {levelDisplay(level)} ))} - - TESTING - SCROLLING - ROWS - - - TESTING - SCROLLING - ROWS - - - TESTING - SCROLLING - ROWS - - - TESTING - SCROLLING - ROWS - - - TESTING - SCROLLING - ROWS - - - TESTING - SCROLLING - ROWS - - - TESTING - SCROLLING - ROWS - diff --git a/src/grain/ChangeGrainDialog.tsx b/src/grain/ChangeGrainDialog.tsx new file mode 100644 index 0000000..2910b25 --- /dev/null +++ b/src/grain/ChangeGrainDialog.tsx @@ -0,0 +1,175 @@ +import { Box, Button, DialogActions, DialogContent, DialogTitle, Grid2, Switch, TextField } from "@mui/material"; +import ResponsiveDialog from "common/ResponsiveDialog"; +import SearchSelect, { Option } from "common/SearchSelect"; +import { Bin } from "models"; +import { pond } from "protobuf-ts/pond"; +import GrainDescriber, { GrainOptions, ToGrainOption } from "grain/GrainDescriber"; +import { useEffect, useMemo, useState } from "react"; +import React from "react"; +import CustomGrainSelector from "./CustomGrainSelector"; +import { cloneDeep } from "lodash"; +import { useBinAPI, useSnackbar } from "providers"; + +interface Props { + bin: Bin + open: boolean + closeDialog: () => void + permissions: pond.Permission[] + /** + * this function can be passed in if you want to just return a new bin with the changes and handle the actual update in the parent, + * it will stop the component from doing the update itself + * @param bin the bin with the new changes + * @returns + */ + updateBin?: (bin: Bin) => void + /** + * this function can be passed in as a callback function if the component handles the update + * @param updated whether the bin api was used to update the bin + * @returns + */ + updateCallback?: (bin: Bin) => void +} + +export default function ChangeGrainDialog(props: Props){ + const { bin, open, permissions, closeDialog, updateBin, updateCallback } = props + const canEdit = useMemo(()=>{ + return permissions ? permissions.includes(pond.Permission.PERMISSION_WRITE) : false; + },[permissions]) + + const [isCustom, setIsCustom] = useState(false) + const grainOptions = GrainOptions(); + const [grainOption, setGrainOption] = useState