-
Notifications
You must be signed in to change notification settings - Fork 937
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
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d6dacf9
Start porting components for Admin menu
presleyp f040a07
Merge branch 'main' into admin/presleyp/591
presleyp a9e4dd4
More porting, wip
presleyp 8944e10
Add icons
presleyp 88bac07
Extract arrow components, navHeight
presleyp 14b9e86
Add Admin Dropdown
presleyp b50b34d
Format
presleyp 8b4834f
Delete types
presleyp 25c5056
Merge branch 'main' into admin/presleyp/591
presleyp 98ec516
Fix styles
presleyp 4f7871e
Merge branch 'main' into admin/presleyp/591
presleyp 1d4c94f
Lint
presleyp f134141
Add stub pages
presleyp db542ca
Use navHeight constant
presleyp a5ca439
Move files
presleyp 6bb47e0
Add and organize stories
presleyp bc84caf
Storybook and organize text stories
presleyp 675b195
Add test
presleyp a121c7e
Lint
presleyp babde57
Merge branch 'main' into admin/presleyp/591
presleyp 466a43d
Lint
presleyp f6342da
Fix double navigation
presleyp c78fa88
Lint
presleyp 9a06d69
Wrap new routes in AuthAndNav
presleyp f1dd2c8
Undo unrelated storybook changes
presleyp acc92f8
Refactor according to conventions
presleyp 1dfb981
Merge branch 'main' into admin/presleyp/591
presleyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
site/src/components/AdminDropdown/AdminDropdown.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Box from "@material-ui/core/Box" | ||
import { Story } from "@storybook/react" | ||
import React from "react" | ||
import { AdminDropdown } from "./AdminDropdown" | ||
|
||
export default { | ||
title: "components/AdminDropdown", | ||
component: AdminDropdown, | ||
} | ||
|
||
const Template: Story = () => ( | ||
<Box style={{ backgroundColor: "#000", width: 100 }}> | ||
<AdminDropdown /> | ||
</Box> | ||
) | ||
|
||
export const Example = Template.bind({}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { screen } from "@testing-library/react" | ||
import React from "react" | ||
import { history, render } from "../../test_helpers" | ||
import { AdminDropdown, Language } from "./AdminDropdown" | ||
|
||
const renderAndClick = async () => { | ||
render(<AdminDropdown />) | ||
const trigger = await screen.findByText(Language.menuTitle) | ||
trigger.click() | ||
} | ||
|
||
describe("AdminDropdown", () => { | ||
describe("when the trigger is clicked", () => { | ||
it("opens the menu", async () => { | ||
await renderAndClick() | ||
expect(screen.getByText(Language.usersLabel)).toBeDefined() | ||
expect(screen.getByText(Language.orgsLabel)).toBeDefined() | ||
expect(screen.getByText(Language.settingsLabel)).toBeDefined() | ||
}) | ||
}) | ||
|
||
it("links to the users page", async () => { | ||
await renderAndClick() | ||
|
||
const usersLink = screen.getByText(Language.usersLabel).closest("a") | ||
usersLink?.click() | ||
|
||
expect(history.location.pathname).toEqual("/users") | ||
}) | ||
|
||
it("links to the orgs page", async () => { | ||
await renderAndClick() | ||
|
||
const usersLink = screen.getByText(Language.orgsLabel).closest("a") | ||
usersLink?.click() | ||
|
||
expect(history.location.pathname).toEqual("/orgs") | ||
}) | ||
|
||
it("links to the settings page", async () => { | ||
await renderAndClick() | ||
|
||
const usersLink = screen.getByText(Language.settingsLabel).closest("a") | ||
usersLink?.click() | ||
|
||
expect(history.location.pathname).toEqual("/settings") | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import ListItem from "@material-ui/core/ListItem" | ||
import ListItemText from "@material-ui/core/ListItemText" | ||
import { fade, makeStyles, Theme } from "@material-ui/core/styles" | ||
import AdminIcon from "@material-ui/icons/SettingsOutlined" | ||
import React, { useState } from "react" | ||
import { navHeight } from "../../theme/constants" | ||
import { BorderedMenu } from "../BorderedMenu/BorderedMenu" | ||
import { BorderedMenuRow } from "../BorderedMenuRow/BorderedMenuRow" | ||
import { CloseDropdown, OpenDropdown } from "../DropdownArrows/DropdownArrows" | ||
import { BuildingIcon } from "../Icons/BuildingIcon" | ||
import { UsersOutlinedIcon } from "../Icons/UsersOutlinedIcon" | ||
|
||
export const Language = { | ||
menuTitle: "Admin", | ||
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 [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={Language.menuTitle} /> | ||
{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) => ( | ||
<BorderedMenuRow | ||
description={entry.description} | ||
Icon={entry.Icon} | ||
key={entry.label} | ||
path={entry.path} | ||
title={entry.label} | ||
variant="narrow" | ||
onClick={() => { | ||
onClose() | ||
}} | ||
/> | ||
))} | ||
</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, | ||
}, | ||
}, | ||
}, | ||
})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Story } from "@storybook/react" | ||
import React from "react" | ||
import { BorderedMenuRow } from "../BorderedMenuRow/BorderedMenuRow" | ||
import { BuildingIcon } from "../Icons/BuildingIcon" | ||
import { UsersOutlinedIcon } from "../Icons/UsersOutlinedIcon" | ||
import { BorderedMenu, BorderedMenuProps } from "./BorderedMenu" | ||
|
||
export default { | ||
title: "components/BorderedMenu", | ||
component: BorderedMenu, | ||
} | ||
|
||
const Template: Story<BorderedMenuProps> = (args: BorderedMenuProps) => ( | ||
<BorderedMenu {...args}> | ||
<BorderedMenuRow title="Item 1" description="Here's a description" Icon={BuildingIcon} /> | ||
<BorderedMenuRow active title="Item 2" description="This BorderedMenuRow is active" Icon={UsersOutlinedIcon} /> | ||
</BorderedMenu> | ||
) | ||
|
||
export const AdminVariant = Template.bind({}) | ||
AdminVariant.args = { | ||
variant: "admin-dropdown", | ||
open: true, | ||
} | ||
|
||
export const UserVariant = Template.bind({}) | ||
UserVariant.args = { | ||
variant: "user-dropdown", | ||
open: true, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.