-
Notifications
You must be signed in to change notification settings - Fork 649
Adds components to main top navbar #4678
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
Open
byrnec30
wants to merge
9
commits into
IBM:epic/ui-rewrite
Choose a base branch
from
byrnec30:cb-NavBarFeature
base: epic/ui-rewrite
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e86af0a
wip: checkpoint current branch changes
clarebyrne f363456
removes amber background image colour
clarebyrne 9d103ee
edits search bar shortcut for different OS
clarebyrne 94c3ac5
changes search input to expandable format
clarebyrne d2e8a75
adds test
clarebyrne 72b5cff
code cleanup
clarebyrne da6cbb5
linting fix
clarebyrne 9e82985
updates mock stub
clarebyrne e551ce5
adds unit tests
clarebyrne 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
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,12 @@ | ||
| export function GitHubIcon({ className }: { className?: string }) { | ||
| return ( | ||
| <svg | ||
| className={className} | ||
| viewBox="0 0 24 24" | ||
| fill="currentColor" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path d="M12 .5C5.65.5.5 5.8.5 12.33c0 5.23 3.3 9.67 7.88 11.24.58.11.79-.26.79-.57 0-.28-.01-1.21-.02-2.19-3.21.72-3.89-1.4-3.89-1.4-.52-1.36-1.28-1.72-1.28-1.72-1.05-.74.08-.72.08-.72 1.16.09 1.77 1.23 1.77 1.23 1.03 1.82 2.7 1.29 3.36.98.1-.77.4-1.29.73-1.59-2.56-.3-5.25-1.32-5.25-5.9 0-1.3.45-2.36 1.2-3.19-.12-.31-.52-1.57.11-3.28 0 0 .98-.32 3.2 1.22a10.8 10.8 0 0 1 5.82 0c2.22-1.54 3.2-1.22 3.2-1.22.63 1.71.23 2.97.11 3.28.75.83 1.2 1.89 1.2 3.19 0 4.59-2.69 5.59-5.26 5.89.41.37.78 1.08.78 2.19 0 1.58-.01 2.85-.01 3.24 0 .31.21.69.8.57 4.57-1.57 7.87-6.01 7.87-11.24C23.5 5.8 18.35.5 12 .5Z" /> | ||
| </svg> | ||
| ); | ||
| } |
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
110 changes: 110 additions & 0 deletions
110
client/src/components/layout/HeaderProfileMenu.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,110 @@ | ||
| import { describe, expect, it, vi, beforeEach } from "vitest"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { ThemeProvider } from "@/hooks/useTheme"; | ||
| import { I18nProvider } from "@/i18n"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { HeaderProfileMenu } from "./HeaderProfileMenu"; | ||
|
|
||
| const mockLogout = vi.fn(); | ||
| const mockNavigate = vi.fn(); | ||
|
|
||
| vi.mock("@/auth/useAuth", () => ({ | ||
| useAuth: () => ({ | ||
| user: { | ||
| email: "bobo@cf.com", | ||
| full_name: "Bobo Example", | ||
| is_admin: false, | ||
| is_active: true, | ||
| auth_provider: "local", | ||
| email_verified: true, | ||
| password_change_required: false, | ||
| }, | ||
| logout: mockLogout, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("@/router", async () => { | ||
| const actual = await vi.importActual<typeof import("@/router")>("@/router"); | ||
| return { | ||
| ...actual, | ||
| useRouter: () => ({ | ||
| path: "/app/", | ||
| params: {}, | ||
| navigate: mockNavigate, | ||
| }), | ||
| }; | ||
| }); | ||
|
|
||
| describe("HeaderProfileMenu", () => { | ||
| beforeEach(() => { | ||
| mockLogout.mockReset(); | ||
| mockNavigate.mockReset(); | ||
| localStorage.clear(); | ||
| }); | ||
|
|
||
| function renderMenu() { | ||
| return render( | ||
| <I18nProvider> | ||
| <ThemeProvider> | ||
| <HeaderProfileMenu /> | ||
| </ThemeProvider> | ||
| </I18nProvider>, | ||
| ); | ||
| } | ||
|
|
||
| it("renders the profile trigger", () => { | ||
| renderMenu(); | ||
| expect(screen.getByRole("button", { name: "Bobo Example" })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("navigates to settings from the dropdown", async () => { | ||
| const user = userEvent.setup(); | ||
| renderMenu(); | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "Bobo Example" })); | ||
| await user.click(screen.getByText("Settings")); | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledWith("/app/settings"); | ||
| }); | ||
|
|
||
| it("logs out from the dropdown", async () => { | ||
| const user = userEvent.setup(); | ||
| renderMenu(); | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "Bobo Example" })); | ||
| await user.click(screen.getByText("Sign Out")); | ||
|
|
||
| expect(mockLogout).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("updates the saved theme preference", async () => { | ||
| const user = userEvent.setup(); | ||
| renderMenu(); | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "Bobo Example" })); | ||
| await user.click(screen.getByRole("button", { name: "Dark mode" })); | ||
|
|
||
| expect(localStorage.getItem("theme-preference")).toBe("dark"); | ||
| }); | ||
|
|
||
| it("supports switching back to light mode", async () => { | ||
| const user = userEvent.setup(); | ||
| localStorage.setItem("theme-preference", "dark"); | ||
| renderMenu(); | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "Bobo Example" })); | ||
| await user.click(screen.getByRole("button", { name: "Light mode" })); | ||
|
|
||
| expect(localStorage.getItem("theme-preference")).toBe("light"); | ||
| }); | ||
|
|
||
| it("supports switching to system theme", async () => { | ||
| const user = userEvent.setup(); | ||
| renderMenu(); | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "Bobo Example" })); | ||
| await user.click(screen.getByRole("button", { name: "System theme" })); | ||
|
|
||
| expect(localStorage.getItem("theme-preference")).toBe("system"); | ||
| }); | ||
| }); |
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,91 @@ | ||
| import { ChevronDown, LogOut, Monitor, Moon, Settings2, Sun } from "lucide-react"; | ||
| import { useIntl } from "react-intl"; | ||
| import { useAuth } from "../../auth/useAuth"; | ||
| import { useTheme } from "../../hooks/useTheme"; | ||
| import { useRouter } from "../../router"; | ||
| import { Button } from "../ui/button"; | ||
| import { | ||
| DropdownMenu, | ||
| DropdownMenuContent, | ||
| DropdownMenuItem, | ||
| DropdownMenuLabel, | ||
| DropdownMenuSeparator, | ||
| DropdownMenuTrigger, | ||
| } from "../ui/dropdown-menu"; | ||
|
|
||
| export function HeaderProfileMenu() { | ||
| const intl = useIntl(); | ||
| const { user, logout } = useAuth(); | ||
| const { navigate } = useRouter(); | ||
| const { theme, setTheme } = useTheme(); | ||
|
|
||
| if (!user) return null; | ||
|
|
||
| const displayName = user.full_name || user.email; | ||
|
|
||
| return ( | ||
| <DropdownMenu> | ||
| <DropdownMenuTrigger asChild> | ||
| {/* TODO: User photo/avatar data does not appear to be available in the current frontend. Using fallback button for now. */} | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: source for photo or avatar? |
||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| className="h-8 gap-1.5 rounded-lg px-1.5 hover:bg-muted" | ||
| aria-label={displayName} | ||
| > | ||
| <span className="block size-6 overflow-hidden rounded-md bg-muted" aria-hidden="true" /> | ||
| <ChevronDown className="size-4 text-muted-foreground" aria-hidden="true" /> | ||
| </Button> | ||
| </DropdownMenuTrigger> | ||
| <DropdownMenuContent align="end" className="w-72 rounded-xl p-2"> | ||
| <DropdownMenuLabel className="px-3 py-2 text-sm font-normal text-muted-foreground"> | ||
| {user.email} | ||
| </DropdownMenuLabel> | ||
| <DropdownMenuSeparator /> | ||
| <div className="flex items-center justify-between gap-3 px-3 py-2"> | ||
| <span className="text-sm">{intl.formatMessage({ id: "common.theme" })}</span> | ||
| <div className="flex items-center gap-1 rounded-full bg-muted p-1"> | ||
| <button | ||
| type="button" | ||
| onClick={() => setTheme("light")} | ||
| className={`rounded-full p-1.5 transition-colors ${theme === "light" ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`} | ||
| aria-label={intl.formatMessage({ id: "common.theme.light" })} | ||
| title={intl.formatMessage({ id: "common.theme.light" })} | ||
| > | ||
| <Sun className="size-4" /> | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => setTheme("dark")} | ||
| className={`rounded-full p-1.5 transition-colors ${theme === "dark" ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`} | ||
| aria-label={intl.formatMessage({ id: "common.theme.dark" })} | ||
| title={intl.formatMessage({ id: "common.theme.dark" })} | ||
| > | ||
| <Moon className="size-4" /> | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => setTheme("system")} | ||
| className={`rounded-full p-1.5 transition-colors ${theme === "system" ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`} | ||
| aria-label={intl.formatMessage({ id: "common.theme.system" })} | ||
| title={intl.formatMessage({ id: "common.theme.system" })} | ||
| > | ||
| <Monitor className="size-4" /> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| <DropdownMenuItem | ||
| onClick={() => navigate("/app/settings")} | ||
| className="gap-2 rounded-lg px-3 py-2" | ||
| > | ||
| <Settings2 className="size-4" aria-hidden="true" /> | ||
| {intl.formatMessage({ id: "navigation.settings" })} | ||
| </DropdownMenuItem> | ||
| <DropdownMenuItem onClick={logout} className="gap-2 rounded-lg px-3 py-2"> | ||
| <LogOut className="size-4" aria-hidden="true" /> | ||
| {intl.formatMessage({ id: "auth.logout" })} | ||
| </DropdownMenuItem> | ||
| </DropdownMenuContent> | ||
| </DropdownMenu> | ||
| ); | ||
| } | ||
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.
this version may not match the actual app release version, is there a better source of truth for the version displayed here?