- Notifications
You must be signed in to change notification settings - Fork929
feat: Add user menu#887
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from5 commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
36026f1
feat: Add user menu
BrunoQuaresma901da69
fix: Arrow icons
BrunoQuaresma73ed5cd
fix: styles
BrunoQuaresma5ed8232
test: Add tests and storybook
BrunoQuaresma5dae508
chore: merge main
BrunoQuaresma9748e39
chore: Merge branch 'main' of github.com:coder/coder into bq/usermenu
BrunoQuaresma0455e54
refactor: use Language object
BrunoQuaresmad17a808
refactor: Use Language in tests
BrunoQuaresmaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletionssite/src/AppRouter.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
13 changes: 13 additions & 0 deletionssite/src/components/Icons/DocsIcon.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,13 @@ | ||
import SvgIcon, { SvgIconProps } from "@material-ui/core/SvgIcon" | ||
import React from "react" | ||
export const DocsIcon = (props: SvgIconProps): JSX.Element => ( | ||
<SvgIcon {...props} viewBox="0 0 24 24"> | ||
<path | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M6.53846 3.75C4.67698 3.75 2.86058 4.50721 2.86058 4.50721L2.5 4.66947V16.4423H9.00841C9.20898 16.7871 9.57407 17.0192 10 17.0192C10.4259 17.0192 10.791 16.7871 10.9916 16.4423H17.5V4.66947L17.1394 4.50721C17.1394 4.50721 15.323 3.75 13.4615 3.75C11.7781 3.75 10.2997 4.31566 10 4.4351C9.70027 4.31566 8.22191 3.75 6.53846 3.75ZM6.53846 4.90385C7.654 4.90385 8.84615 5.26442 9.42308 5.46274V14.7656C8.7808 14.5538 7.72611 14.2608 6.53846 14.2608C5.32602 14.2608 4.33894 14.5403 3.65385 14.7656V5.46274C4.09781 5.30273 5.26968 4.90385 6.53846 4.90385ZM13.4615 4.90385C14.7303 4.90385 15.9022 5.30273 16.3462 5.46274V14.7656C15.6611 14.5403 14.674 14.2608 13.4615 14.2608C12.2739 14.2608 11.2192 14.5538 10.5769 14.7656V5.46274C11.1538 5.26442 12.346 4.90385 13.4615 4.90385Z" | ||
fill="currentColor" | ||
/> | ||
</SvgIcon> | ||
) |
26 changes: 26 additions & 0 deletionssite/src/components/Navbar/UserDropdown.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,26 @@ | ||
import Box from "@material-ui/core/Box" | ||
import { Story } from "@storybook/react" | ||
import React from "react" | ||
import { UserDropdown, UserDropdownProps } from "./UserDropdown" | ||
export default { | ||
title: "Page/UserDropdown", | ||
component: UserDropdown, | ||
argTypes: { | ||
onSignOut: { action: "Sign Out" }, | ||
}, | ||
} | ||
const Template: Story<UserDropdownProps> = (args: UserDropdownProps) => ( | ||
<Box style={{ backgroundColor: "#000", width: 88 }}> | ||
<UserDropdown {...args} /> | ||
</Box> | ||
) | ||
export const Example = Template.bind({}) | ||
Example.args = { | ||
user: { id: "1", username: "CathyCoder", email: "cathy@coder.com", created_at: "dawn" }, | ||
onSignOut: () => { | ||
return Promise.resolve() | ||
}, | ||
} |
55 changes: 55 additions & 0 deletionssite/src/components/Navbar/UserDropdown.test.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,55 @@ | ||
import{screen}from"@testing-library/react" | ||
importReactfrom"react" | ||
import{render}from"../../test_helpers" | ||
import{MockUser}from"../../test_helpers/entities" | ||
import{UserDropdown,UserDropdownProps}from"./UserDropdown" | ||
constrenderAndClick=async(props:Partial<UserDropdownProps>={})=>{ | ||
render(<UserDropdownuser={props.user??MockUser}onSignOut={props.onSignOut??jest.fn()}/>) | ||
consttrigger=awaitscreen.findByTestId("user-dropdown-trigger") | ||
trigger.click() | ||
} | ||
describe("UserDropdown",()=>{ | ||
describe("when the trigger is clicked",()=>{ | ||
it("opens the menu",async()=>{ | ||
awaitrenderAndClick() | ||
expect(screen.getByText(/account/i)).toBeDefined() | ||
expect(screen.getByText(/documentation/i)).toBeDefined() | ||
expect(screen.getByText(/signout/i)).toBeDefined() | ||
}) | ||
}) | ||
describe("when the menu is open",()=>{ | ||
describe("and sign out is clicked",()=>{ | ||
it("calls the onSignOut function",async()=>{ | ||
constonSignOut=jest.fn() | ||
awaitrenderAndClick({ onSignOut}) | ||
screen.getByText(/signout/i).click() | ||
expect(onSignOut).toBeCalledTimes(1) | ||
}) | ||
}) | ||
}) | ||
it("has the correct link for the documentation item",async()=>{ | ||
awaitrenderAndClick() | ||
constlink=screen.getByText(/documentation/i).closest("a") | ||
if(!link){ | ||
thrownewError("Anchor tag not found for the documentation menu item") | ||
} | ||
expect(link.getAttribute("href")).toBe("https://coder.com/docs") | ||
}) | ||
it("has the correct link for the account item",async()=>{ | ||
awaitrenderAndClick() | ||
constlink=screen.getByText(/account/i).closest("a") | ||
if(!link){ | ||
thrownewError("Anchor tag not found for the account menu item") | ||
} | ||
expect(link.getAttribute("href")).toBe("/preferences") | ||
}) | ||
}) |
33 changes: 31 additions & 2 deletionssite/src/components/Navbar/UserDropdown.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
15 changes: 15 additions & 0 deletionssite/src/pages/preferences/index.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,15 @@ | ||
import Box from "@material-ui/core/Box" | ||
import Paper from "@material-ui/core/Paper" | ||
import React from "react" | ||
import { Header } from "../../components/Header" | ||
import { Footer } from "../../components/Page" | ||
export const PreferencesPage: React.FC = () => { | ||
return ( | ||
<Box display="flex" flexDirection="column"> | ||
<Header title="Preferences" /> | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
<Paper style={{ maxWidth: "1380px", margin: "1em auto", width: "100%" }}>Preferences here!</Paper> | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
<Footer /> | ||
</Box> | ||
) | ||
} |
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.