|
| 1 | +import { |
| 2 | + Box, |
| 3 | + Tooltip, |
| 4 | + IconButton, |
| 5 | + Menu, |
| 6 | + Typography, |
| 7 | + Divider, |
| 8 | + List, |
| 9 | + ListItem, |
| 10 | + ListItemButton, |
| 11 | + ListItemIcon, |
| 12 | + ListItemText, |
| 13 | + Button, |
| 14 | + Drawer, |
| 15 | + Toolbar, |
| 16 | + MenuItem, |
| 17 | +} from "@mui/material"; |
| 18 | +import { useState } from "react"; |
| 19 | +import MoreIcon from "@mui/icons-material/MoreVert"; |
| 20 | +import { Download } from "../features/Download"; |
| 21 | +import { Upload } from "../features/Upload"; |
| 22 | +import InboxIcon from "@mui/icons-material/MoveToInbox"; |
| 23 | +import MailIcon from "@mui/icons-material/Mail"; |
| 24 | +import { ToolsProps } from "./props/ToolsProps"; |
| 25 | +import { IsDFA } from "../utils/IsDFA"; |
| 26 | + |
| 27 | +export const Tools = (props: ToolsProps) => { |
| 28 | + console.log("re rendering Tools: props"); |
| 29 | + |
| 30 | + const [anchorElUser, setAnchorElUser] = useState<null | HTMLElement>(null); |
| 31 | + |
| 32 | + const handleOpenUserMenu = (event: React.MouseEvent<HTMLElement>) => { |
| 33 | + setAnchorElUser(event.currentTarget); |
| 34 | + }; |
| 35 | + |
| 36 | + const handleCloseToolsMenu = () => { |
| 37 | + setAnchorElUser(null); |
| 38 | + }; |
| 39 | + |
| 40 | + // const [isDrawerOpen, setIsDrawerOpen] = useState(false); |
| 41 | + |
| 42 | + // const toggleDrawer = |
| 43 | + // (open: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => { |
| 44 | + // if ( |
| 45 | + // event.type === "keydown" && |
| 46 | + // ((event as React.KeyboardEvent).key === "Tab" || |
| 47 | + // (event as React.KeyboardEvent).key === "Shift") |
| 48 | + // ) { |
| 49 | + // return; |
| 50 | + // } |
| 51 | + |
| 52 | + // setIsDrawerOpen(open); |
| 53 | + // }; |
| 54 | + |
| 55 | + // const list = () => ( |
| 56 | + // <Box |
| 57 | + // sx={{ width: 250 }} |
| 58 | + // role="presentation" |
| 59 | + // onClick={toggleDrawer(false)} |
| 60 | + // onKeyDown={toggleDrawer(false)} |
| 61 | + // > |
| 62 | + // <List> |
| 63 | + // {["Inbox", "Starred", "Send email", "Drafts"].map((text, index) => ( |
| 64 | + // <ListItem key={text} disablePadding> |
| 65 | + // <ListItemButton> |
| 66 | + // <ListItemIcon> |
| 67 | + // {index % 2 === 0 ? <InboxIcon /> : <MailIcon />} |
| 68 | + // </ListItemIcon> |
| 69 | + // <ListItemText primary={text} /> |
| 70 | + // </ListItemButton> |
| 71 | + // </ListItem> |
| 72 | + // ))} |
| 73 | + // </List> |
| 74 | + // <Divider /> |
| 75 | + // <List> |
| 76 | + // {["All mail", "Trash", "Spam"].map((text, index) => ( |
| 77 | + // <ListItem key={text} disablePadding> |
| 78 | + // <ListItemButton> |
| 79 | + // <ListItemIcon> |
| 80 | + // {index % 2 === 0 ? <InboxIcon /> : <MailIcon />} |
| 81 | + // </ListItemIcon> |
| 82 | + // <ListItemText primary={text} /> |
| 83 | + // </ListItemButton> |
| 84 | + // </ListItem> |
| 85 | + // ))} |
| 86 | + // </List> |
| 87 | + // </Box> |
| 88 | + // ); |
| 89 | + |
| 90 | + return ( |
| 91 | + // <> |
| 92 | + // <Button onClick={toggleDrawer(true)}>Tools</Button> |
| 93 | + // <Drawer |
| 94 | + // anchor="left" |
| 95 | + // open={isDrawerOpen} |
| 96 | + // onClose={toggleDrawer(false)} |
| 97 | + // sx={{ |
| 98 | + // width: 250, |
| 99 | + // flexShrink: 0, |
| 100 | + // [`& .MuiDrawer-paper`]: { |
| 101 | + // width: 250, |
| 102 | + // boxSizing: "border-box", |
| 103 | + // }, |
| 104 | + // }} |
| 105 | + // > |
| 106 | + // {list()} |
| 107 | + // </Drawer> |
| 108 | + // </> |
| 109 | + |
| 110 | + <Box> |
| 111 | + <Button |
| 112 | + size="small" |
| 113 | + aria-label="tools" |
| 114 | + aria-controls="menu-appbar-tools" |
| 115 | + aria-haspopup="true" |
| 116 | + onClick={handleOpenUserMenu} |
| 117 | + sx={{ marginLeft: 3 }} |
| 118 | + > |
| 119 | + Tools |
| 120 | + </Button> |
| 121 | + <Menu |
| 122 | + id="menu-appbar-tools" |
| 123 | + anchorEl={anchorElUser} |
| 124 | + anchorOrigin={{ |
| 125 | + vertical: "bottom", |
| 126 | + horizontal: "left", |
| 127 | + }} |
| 128 | + keepMounted |
| 129 | + transformOrigin={{ |
| 130 | + vertical: "top", |
| 131 | + horizontal: "left", |
| 132 | + }} |
| 133 | + open={Boolean(anchorElUser)} |
| 134 | + onClose={handleCloseToolsMenu} |
| 135 | + > |
| 136 | + <Download handleCloseToolsMenu={handleCloseToolsMenu} /> |
| 137 | + <Upload handleCloseToolsMenu={handleCloseToolsMenu} /> |
| 138 | + <MenuItem |
| 139 | + onClick={() => { |
| 140 | + handleCloseToolsMenu(); |
| 141 | + IsDFA(props.rows); |
| 142 | + }} |
| 143 | + > |
| 144 | + <Button variant="text" component="label"> |
| 145 | + Is DFA |
| 146 | + </Button> |
| 147 | + </MenuItem> |
| 148 | + </Menu> |
| 149 | + </Box> |
| 150 | + ); |
| 151 | +}; |
0 commit comments