import { Grid2 as Grid, IconButton, ListItemIcon, ListItemText, Menu, MenuItem, Tooltip, Theme, Box } from "@mui/material"; //import ObjectTeamsIcon from "@material-ui/icons/SupervisedUserCircle"; import FieldsIcon from "products/AgIcons/FieldsIcon"; import React, { useState } from "react"; import DeviceIcon from "products/Bindapt/BindaptIcon"; import { Device, Scope } from "models"; import ObjectTeams from "teams/ObjectTeams"; import { pond } from "protobuf-ts/pond"; import { Link, SupervisedUserCircle as ObjectTeamsIcon } from "@mui/icons-material"; //import { useHistory } from "react-router"; import { useNavigate } from "react-router-dom"; import { useThemeType } from "hooks"; import { makeStyles } from "@mui/styles"; interface Props { actions: JSX.Element; objectButton?: JSX.Element; mapFunction?: () => void; linkDeviceFunction?: () => void; notesButton?: JSX.Element; teamScope?: Scope; permissions?: pond.Permission[]; devices?: Device[]; } const useStyles = makeStyles((theme: Theme) => ({ avatar: { color: useThemeType() === "light" ? theme.palette.common.black : theme.palette.common.white, backgroundColor: "transparent", width: theme.spacing(5), height: theme.spacing(5), border: "1px solid", borderColor: theme.palette.divider } })); export default function ObjectControls(props: Props) { const { mapFunction, linkDeviceFunction, teamScope, permissions, actions, devices, notesButton, objectButton } = props; const [openTeams, setOpenTeams] = useState(false); //const history = useHistory(); const navigate = useNavigate(); const [anchorEl, setAnchorEl] = React.useState(null); const classes = useStyles(); // const goToDevice = (dev: Device) => { // history.push("/devices/" + dev.id()); // }; const goToDevice = (dev: Device) => { let path = "/devices/" + dev.id(); navigate(path); }; const dialogs = () => { return ( {teamScope && permissions && ( {}} closeDialogCallback={() => { setOpenTeams(false); }} /> )} ); }; const deviceNavButton = () => { if (devices) { if (devices.length > 1) { return ( ) => setAnchorEl(event.currentTarget) } size="small" style={{ marginTop: "0.3625rem", marginBottom: "0.3625rem", marginRight: "0.5rem" }} className={classes.avatar} component="span"> ); } else { return devices.map(dev => ( goToDevice(dev)} size="small" style={{ marginTop: "0.3625rem", marginBottom: "0.3625rem", marginRight: "0.5rem" }} className={classes.avatar} component="span"> )); } } }; const deviceMenu = () => { return ( setAnchorEl(null)} keepMounted //classes={{ paper: classes.menuPaper }} disableAutoFocusItem> {devices && devices.map(dev => ( goToDevice(dev)}> ))} ); }; return ( {dialogs()} {/* buttons on the left side start here */} {objectButton} {notesButton} {deviceNavButton()} {deviceMenu()} {mapFunction && ( )} {teamScope && permissions && ( { setOpenTeams(true); }} size="small" style={{ marginTop: "0.3625rem", marginBottom: "0.3625rem", marginRight: "0.5rem" }} className={classes.avatar} component="span"> )} {/* bottons on the right side start here */} {linkDeviceFunction && ( )} {actions} ); }