-
Notifications
You must be signed in to change notification settings - Fork 881
feat(site): add deployment menu to navbar #13401
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
7 commits
Select commit
Hold shift + click to select a range
7c5a750
feat(site): add deployment menu to navbar
aslilac aa11ae9
Merge branch 'main' into deployment-menu
aslilac c29e76c
Merge branch 'main' into deployment-menu
aslilac b081a12
💇♀️
aslilac 9104fce
🧹
aslilac c3d8207
fix tests
aslilac b28025a
same thing but different
aslilac 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
151 changes: 151 additions & 0 deletions
151
site/src/modules/dashboard/Navbar/DeploymentDropdown.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,151 @@ | ||
import { css, type Interpolation, type Theme, useTheme } from "@emotion/react"; | ||
import Button from "@mui/material/Button"; | ||
import MenuItem from "@mui/material/MenuItem"; | ||
import type { FC } from "react"; | ||
import { NavLink } from "react-router-dom"; | ||
import { DropdownArrow } from "components/DropdownArrow/DropdownArrow"; | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
usePopover, | ||
} from "components/Popover/Popover"; | ||
import { USERS_LINK } from "modules/navigation"; | ||
|
||
interface DeploymentDropdownProps { | ||
canViewAuditLog: boolean; | ||
canViewDeployment: boolean; | ||
canViewAllUsers: boolean; | ||
canViewHealth: boolean; | ||
} | ||
|
||
export const DeploymentDropdown: FC<DeploymentDropdownProps> = ({ | ||
canViewAuditLog, | ||
canViewDeployment, | ||
canViewAllUsers, | ||
canViewHealth, | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
if ( | ||
!canViewAuditLog && | ||
!canViewDeployment && | ||
!canViewAllUsers && | ||
!canViewHealth | ||
) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Popover> | ||
<PopoverTrigger> | ||
<Button | ||
size="small" | ||
endIcon={ | ||
<DropdownArrow | ||
color={theme.experimental.l2.fill.solid} | ||
close={false} | ||
margin={false} | ||
/> | ||
} | ||
> | ||
Deployment | ||
</Button> | ||
</PopoverTrigger> | ||
|
||
<PopoverContent | ||
horizontal="right" | ||
css={{ | ||
".MuiPaper-root": { | ||
minWidth: "auto", | ||
width: 180, | ||
boxShadow: theme.shadows[6], | ||
}, | ||
}} | ||
> | ||
<DeploymentDropdownContent | ||
canViewAuditLog={canViewAuditLog} | ||
canViewDeployment={canViewDeployment} | ||
canViewAllUsers={canViewAllUsers} | ||
canViewHealth={canViewHealth} | ||
/> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
}; | ||
|
||
const DeploymentDropdownContent: FC<DeploymentDropdownProps> = ({ | ||
canViewAuditLog, | ||
canViewDeployment, | ||
canViewAllUsers, | ||
canViewHealth, | ||
}) => { | ||
const popover = usePopover(); | ||
|
||
const onPopoverClose = () => popover.setIsOpen(false); | ||
|
||
return ( | ||
<nav> | ||
{canViewDeployment && ( | ||
<MenuItem | ||
component={NavLink} | ||
to="/deployment/general" | ||
css={styles.menuItem} | ||
onClick={onPopoverClose} | ||
> | ||
Settings | ||
</MenuItem> | ||
)} | ||
{canViewAllUsers && ( | ||
<MenuItem | ||
component={NavLink} | ||
to={USERS_LINK} | ||
css={styles.menuItem} | ||
onClick={onPopoverClose} | ||
> | ||
Users | ||
</MenuItem> | ||
)} | ||
{canViewAuditLog && ( | ||
<MenuItem | ||
component={NavLink} | ||
to="/audit" | ||
css={styles.menuItem} | ||
onClick={onPopoverClose} | ||
> | ||
Auditing | ||
</MenuItem> | ||
)} | ||
{canViewHealth && ( | ||
<MenuItem | ||
component={NavLink} | ||
to="/health" | ||
css={styles.menuItem} | ||
onClick={onPopoverClose} | ||
> | ||
Healthcheck | ||
</MenuItem> | ||
)} | ||
</nav> | ||
); | ||
}; | ||
|
||
const styles = { | ||
menuItem: (theme) => css` | ||
text-decoration: none; | ||
color: inherit; | ||
gap: 20px; | ||
padding: 8px 20px; | ||
font-size: 14px; | ||
|
||
&:hover { | ||
background-color: ${theme.palette.action.hover}; | ||
transition: background-color 0.3s ease; | ||
} | ||
`, | ||
menuItemIcon: (theme) => ({ | ||
color: theme.palette.text.secondary, | ||
width: 20, | ||
height: 20, | ||
}), | ||
} satisfies Record<string, Interpolation<Theme>>; |
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
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
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can pass the root permissions to the component instead of creating derived values for each option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh, I don't mind this. the root permissions names are a lot less clear imo, so having the
Navbar
"controller" abstract them with better names is nice.