Skip to content

feat(site): Add Admin Dropdown menu #885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Admin Dropdown
  • Loading branch information
presleyp committed Apr 6, 2022
commit 14b9e86828fa2e207911ad5e759675e58e7b6b7d
51 changes: 0 additions & 51 deletions site/src/components/Navbar/Admin/index.tsx

This file was deleted.

164 changes: 164 additions & 0 deletions site/src/components/Navbar/AdminDropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import React, { useState } from "react"
import { useNavigate } from "react-router-dom"
import { BorderedMenu } from "../../BorderedMenu"
import { BorderedMenuRow } from "../../BorderedMenu/BorderedMenuRow"
import { CloseDropdown, OpenDropdown } from "../Arrows"
import ListItem from "@material-ui/core/ListItem"
import ListItemText from "@material-ui/core/ListItemText"
import { makeStyles } from "@material-ui/styles"
import AdminIcon from "@material-ui/icons/SettingsOutlined"
import { fade, Theme } from "@material-ui/core"
import { BuildingIcon } from "../../Icons/BuildingIcon"
import { UsersOutlinedIcon } from "../../Icons/UsersOutlinedIcon"
import { navHeight } from "../../../theme/constants"

const Language = {
usersLabel: "Users",
usersDescription: "Manage users, roles, and permissions.",
orgsLabel: "Organizations",
orgsDescription: "Manage organizations.",
settingsLabel: "Settings",
settingsDescription: "Configure authentication and more."
}

const entries = [
{
label: Language.usersLabel,
description: Language.usersDescription,
path: "/users",
Icon: UsersOutlinedIcon,
},
{
label: Language.orgsLabel,
description: Language.orgsDescription,
path: "/orgs",
Icon: BuildingIcon,
},
{
label: Language.settingsLabel,
description: Language.settingsDescription,
path: "/settings",
Icon: AdminIcon
}
]

export const AdminDropdown: React.FC = () => {
const styles = useStyles()
const navigate = useNavigate()
const [anchorEl, setAnchorEl] = useState<HTMLElement>()
const onClose = () => setAnchorEl(undefined)
const onOpenAdminMenu = (ev: React.MouseEvent<HTMLDivElement>) => setAnchorEl(ev.currentTarget)

return (
<>
<div className={styles.link}>
<ListItem selected={Boolean(anchorEl)} button onClick={onOpenAdminMenu}>
<ListItemText className="no-brace" color="primary" primary="Admin" />
{anchorEl ? (
<CloseDropdown />
) : (
<OpenDropdown />
)}
</ListItem>
</div>

<BorderedMenu
anchorEl={anchorEl}
getContentAnchorEl={null}
open={!!anchorEl}
anchorOrigin={{
vertical: "bottom",
horizontal: "center",
}}
transformOrigin={{
vertical: "top",
horizontal: "center",
}}
marginThreshold={0}
variant="admin-dropdown"
onClose={onClose}
>
{entries.map((entry) =>
entry.label && entry.Icon ? (
<BorderedMenuRow
description={entry.description}
Icon={entry.Icon}
key={entry.label}
path={entry.path}
title={entry.label}
variant="narrow"
onClick={() => {
onClose()
navigate(entry.path)
}}
/>
) : null,
)}
</BorderedMenu>
</>
)
}

const useStyles = makeStyles((theme: Theme) => ({
link: {
"&:focus": {
outline: "none",

"& .MuiListItem-button": {
background: fade(theme.palette.primary.light, 0.1),
},
},

"& .MuiListItemText-root": {
display: "flex",
flexDirection: "column",
alignItems: "center",
},
"& .feature-stage-chip": {
position: "absolute",
bottom: theme.spacing(1),

"& .MuiChip-labelSmall": {
fontSize: "10px",
},
},
whiteSpace: "nowrap",
"& .MuiListItem-button": {
height: navHeight,
color: "#A7A7A7",
padding: `0 ${theme.spacing(3)}px`,

"&.Mui-selected": {
background: "transparent",
"& .MuiListItemText-root": {
color: theme.palette.primary.contrastText,

"&:not(.no-brace) .MuiTypography-root": {
position: "relative",

"&::before": {
content: `"{"`,
left: -14,
position: "absolute",
},
"&::after": {
content: `"}"`,
position: "absolute",
right: -14,
},
},
},
},

"&.Mui-focusVisible, &:hover": {
background: "#333",
},

"& .MuiListItemText-primary": {
fontFamily: theme.typography.fontFamily,
fontSize: 16,
fontWeight: 500,
},
},
},
}))
4 changes: 4 additions & 0 deletions site/src/components/Navbar/NavbarView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from "react"
import { Link } from "react-router-dom"
import { UserResponse } from "../../api/types"
import { Logo } from "../Icons"
import { AdminDropdown } from "./AdminDropdown"
import { UserDropdown } from "./UserDropdown"

export interface NavbarViewProps {
Expand All @@ -23,6 +24,9 @@ export const NavbarView: React.FC<NavbarViewProps> = ({ user, onSignOut }) => {
</Link>
</div>
<div className={styles.fullWidth} />
{user && user.email === "admin@coder.com" &&
<AdminDropdown />
}
<div className={styles.fixed}>{user && <UserDropdown user={user} onSignOut={onSignOut} />}</div>
</div>
)
Expand Down