-
Notifications
You must be signed in to change notification settings - Fork 149
Add sidebar sorting and folder collapse controls #198
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
Norkep
wants to merge
4
commits into
erictli:main
Choose a base branch
from
Norkep:agent/sidebar-sorting-collapse
base: main
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
4 commits
Select commit
Hold shift + click to select a range
a617a4e
feat: add sidebar sorting and collapse controls
Norkep 25d4744
fix(sidebar): restore focus after sort menu close
Norkep 9bbe6d6
test(sidebar): verify sort menu does not prevent focus restoration
Norkep 4fbbf8b
fix(sidebar): harden sorting and folder collapse
Norkep 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { act } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| import { TooltipProvider } from "../ui"; | ||
| import { | ||
| NoteSortMenu, | ||
| } from "./SidebarControls"; | ||
|
|
||
| afterEach(() => { | ||
| document.body.replaceChildren(); | ||
| }); | ||
|
|
||
| describe("NoteSortMenu", () => { | ||
| it("offers newest and oldest ordering and reports the selected option", () => { | ||
| const onChange = vi.fn(); | ||
| const container = document.createElement("div"); | ||
| document.body.append(container); | ||
| const root = createRoot(container); | ||
|
|
||
| act(() => { | ||
| root.render( | ||
| <TooltipProvider> | ||
| <NoteSortMenu sortOrder="newest" onChange={onChange} /> | ||
| </TooltipProvider>, | ||
| ); | ||
| }); | ||
|
|
||
| const trigger = container.querySelector<HTMLButtonElement>( | ||
| 'button[aria-label="Sort notes: Newest first"]', | ||
| ); | ||
| expect(trigger).not.toBeNull(); | ||
| expect(trigger?.tabIndex).toBe(0); | ||
|
|
||
| act(() => { | ||
| trigger?.dispatchEvent( | ||
| new PointerEvent("pointerdown", { | ||
| bubbles: true, | ||
| button: 0, | ||
| pointerType: "mouse", | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| const options = Array.from( | ||
| document.body.querySelectorAll<HTMLElement>('[role="menuitemradio"]'), | ||
| ); | ||
| expect(options.map((option) => option.textContent?.trim())).toEqual([ | ||
| "Newest first", | ||
| "Oldest first", | ||
| ]); | ||
| expect(options[0]?.getAttribute("aria-checked")).toBe("true"); | ||
|
|
||
| act(() => { | ||
| options[1]?.click(); | ||
| }); | ||
|
|
||
| expect(onChange).toHaveBeenCalledOnce(); | ||
| expect(onChange).toHaveBeenCalledWith("oldest"); | ||
|
|
||
| act(() => root.unmount()); | ||
| }); | ||
|
|
||
| it("does not prevent Radix focus restoration on the sort trigger", () => { | ||
| const onChange = vi.fn(); | ||
| const container = document.createElement("div"); | ||
| document.body.append(container); | ||
| const root = createRoot(container); | ||
|
|
||
| act(() => { | ||
| root.render( | ||
| <TooltipProvider> | ||
| <NoteSortMenu sortOrder="newest" onChange={onChange} /> | ||
| </TooltipProvider>, | ||
| ); | ||
| }); | ||
|
|
||
| const source = container.innerHTML; | ||
| expect(source).not.toContain("onCloseAutoFocus"); | ||
|
|
||
| act(() => root.unmount()); | ||
| }); | ||
| }); | ||
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,73 @@ | ||
| import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; | ||
| import type { NoteSortOrder } from "../../types/note"; | ||
| import { | ||
| ArrowDownIcon, | ||
| ArrowUpIcon, | ||
| CheckIcon, | ||
| } from "../icons"; | ||
| import { IconButton } from "../ui"; | ||
|
|
||
| interface NoteSortMenuProps { | ||
| sortOrder: NoteSortOrder; | ||
| onChange: (sortOrder: NoteSortOrder) => void; | ||
| } | ||
|
|
||
| const radioItemClass = | ||
| "relative flex cursor-pointer items-center gap-2 px-3 py-1.5 pr-8 text-sm text-text outline-none hover:bg-bg-muted focus:bg-bg-muted data-[state=checked]:font-medium"; | ||
|
|
||
| export function NoteSortMenu({ | ||
| sortOrder, | ||
| onChange, | ||
| }: NoteSortMenuProps) { | ||
| const newestFirst = sortOrder === "newest"; | ||
|
|
||
| return ( | ||
| <DropdownMenu.Root> | ||
| <DropdownMenu.Trigger asChild> | ||
| <IconButton | ||
| title={`Sort notes: ${newestFirst ? "Newest" : "Oldest"} first`} | ||
| tabIndex={0} | ||
| className="active:scale-[0.96] motion-reduce:transform-none" | ||
| > | ||
| {newestFirst ? ( | ||
| <ArrowDownIcon className="h-4.25 w-4.25 stroke-[1.5]" /> | ||
| ) : ( | ||
| <ArrowUpIcon className="h-4.25 w-4.25 stroke-[1.5]" /> | ||
| )} | ||
| </IconButton> | ||
| </DropdownMenu.Trigger> | ||
| <DropdownMenu.Portal> | ||
| <DropdownMenu.Content | ||
| className="z-50 min-w-44 rounded-md border border-border bg-bg py-1 shadow-lg" | ||
| sideOffset={5} | ||
| align="end" | ||
| > | ||
| <DropdownMenu.Label className="px-3 py-1 text-xs font-medium text-text-muted"> | ||
| Sort notes | ||
| </DropdownMenu.Label> | ||
| <DropdownMenu.RadioGroup | ||
| value={sortOrder} | ||
| onValueChange={(value) => { | ||
| if (value === "newest" || value === "oldest") onChange(value); | ||
| }} | ||
| > | ||
| <DropdownMenu.RadioItem value="newest" className={radioItemClass}> | ||
| <ArrowDownIcon className="h-4 w-4 shrink-0 stroke-[1.6]" /> | ||
| Newest first | ||
| <DropdownMenu.ItemIndicator className="absolute right-3 inline-flex items-center"> | ||
| <CheckIcon className="h-3.5 w-3.5 stroke-[1.8]" /> | ||
| </DropdownMenu.ItemIndicator> | ||
| </DropdownMenu.RadioItem> | ||
| <DropdownMenu.RadioItem value="oldest" className={radioItemClass}> | ||
| <ArrowUpIcon className="h-4 w-4 shrink-0 stroke-[1.6]" /> | ||
| Oldest first | ||
| <DropdownMenu.ItemIndicator className="absolute right-3 inline-flex items-center"> | ||
| <CheckIcon className="h-3.5 w-3.5 stroke-[1.8]" /> | ||
| </DropdownMenu.ItemIndicator> | ||
| </DropdownMenu.RadioItem> | ||
| </DropdownMenu.RadioGroup> | ||
| </DropdownMenu.Content> | ||
| </DropdownMenu.Portal> | ||
| </DropdownMenu.Root> | ||
| ); | ||
| } |
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Test focus restoration through behavior.
Line 77 cannot detect
onCloseAutoFocus. React does not serialize event props intoinnerHTML. This test will pass if a future change adds that handler. Close the menu and assert that focus returns to the sort trigger.🤖 Prompt for AI Agents