Repository navigation
fix(web): manual project order can be changed again #33227
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
HarunRRayhan
wants to merge
16
commits into
pingdotgg:main
Choose a base branch
from
HarunRRayhan:fix/web-manual-project-order
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.
+315
−3
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
87016bc
fix(web): manual project order can be changed again
HarunRRayhan e1d4710
fix(web): project ordering has its own switch and numbered rows
HarunRRayhan a92211f
fix(web): boring sidebar shows project order and a drag locks it
HarunRRayhan e99110b
fix(web): customize project order from Labs, pin from the list
HarunRRayhan ea112db
fix(web): project list keeps its arrow last, after pin
HarunRRayhan 7c6ea4c
fix(web): dragging onto a grouped project keeps its checkouts together
HarunRRayhan 31deb1d
fix(web): project reorder announcements read project names
HarunRRayhan d4d9859
fix(web): keep the project order list to ordering
HarunRRayhan 3da2625
test(web): cover reordering below the pinned divider
HarunRRayhan 9fbbd6c
Merge remote-tracking branch 'origin/main' into fix/web-manual-projec…
HarunRRayhan 63b09ee
fix(web): announce when a drop across the pinned line is ignored
HarunRRayhan e113a04
fix(web): allow keyboard project reordering in settings
maria-rcks bf7173d
Merge remote-tracking branch 'origin/main' into fix/web-manual-projec…
juliusmarminge e4ff19e
fix(web): edit manual project order from the existing Project order s…
juliusmarminge 9945e81
Merge remote-tracking branch 'origin/main' into fix/web-manual-projec…
juliusmarminge 644d413
fix(web): project order intro is not a live region
juliusmarminge 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
76 changes: 76 additions & 0 deletions
76
apps/web/src/components/settings/ProjectOrderList.browser.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,76 @@ | ||
| import { describe, expect, it, vi } from "vite-plus/test"; | ||
| import { page, userEvent } from "vite-plus/test/browser"; | ||
|
|
||
| import { render } from "../../../test/render"; | ||
| import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping"; | ||
| import { useUiStateStore } from "../../uiStateStore"; | ||
| import { AppRouteModal } from "../AppRouteModal"; | ||
| import { ProjectOrderList } from "./ProjectOrderList"; | ||
|
|
||
| const state = vi.hoisted(() => ({ | ||
| groups: [] as SidebarProjectSnapshot[], | ||
| })); | ||
|
|
||
| vi.mock(import("../../hooks/useSidebarProjectGroups"), () => ({ | ||
| useSidebarProjectGroups: () => state.groups, | ||
| })); | ||
| vi.mock(import("../../state/entities"), async (original) => ({ | ||
| ...(await original()), | ||
| useProjects: () => [], | ||
| })); | ||
| vi.mock(import("./SettingsScopeContext"), async (original) => ({ | ||
| ...(await original()), | ||
| useSettingsScope: () => ({ selectScope: vi.fn() }) as never, | ||
| })); | ||
| vi.mock(import("../ProjectFavicon"), () => ({ ProjectFavicon: () => <span /> })); | ||
|
|
||
| function group(name: string, memberKeys: readonly string[], pinned = false) { | ||
| return { | ||
| projectKey: name, | ||
| displayName: name, | ||
| workspaceRoot: `/code/${name}`, | ||
| pinned, | ||
| archived: false, | ||
| memberProjects: memberKeys.map((physicalProjectKey) => ({ physicalProjectKey })), | ||
| } as unknown as SidebarProjectSnapshot; | ||
| } | ||
|
|
||
| function setup(groups: SidebarProjectSnapshot[]) { | ||
| state.groups = groups; | ||
| useUiStateStore.setState({ projectOrder: [] }); | ||
| } | ||
|
|
||
| async function moveDown(name: string) { | ||
| const handle = page.getByRole("button", { name: new RegExp(`^Reorder ${name},`) }); | ||
| await expect.element(handle).toBeVisible(); | ||
| handle.element().focus(); | ||
| await userEvent.keyboard(" "); | ||
| await expect.element(handle).toHaveAttribute("aria-pressed", "true"); | ||
| await userEvent.keyboard("{ArrowDown}"); | ||
| await userEvent.keyboard(" "); | ||
| await expect.element(handle).not.toHaveAttribute("aria-pressed", "true"); | ||
| } | ||
|
|
||
| describe("ProjectOrderList", () => { | ||
| it("saves a dragged project's checkouts together", async () => { | ||
| setup([group("alpha", ["a-local", "a-remote"]), group("beta", ["b"]), group("gamma", ["g"])]); | ||
| await using _screen = await render( | ||
| <AppRouteModal label="Settings"> | ||
| <ProjectOrderList /> | ||
| </AppRouteModal>, | ||
| ); | ||
|
|
||
| await moveDown("alpha"); | ||
|
|
||
| expect(useUiStateStore.getState().projectOrder).toEqual(["b", "a-local", "a-remote", "g"]); | ||
| }); | ||
|
|
||
| it("leaves the order alone when a drop crosses the pinned line", async () => { | ||
| setup([group("pinned", ["p"], true), group("beta", ["b"])]); | ||
| await using _screen = await render(<ProjectOrderList />); | ||
|
|
||
| await moveDown("pinned"); | ||
|
|
||
| expect(useUiStateStore.getState().projectOrder).toEqual([]); | ||
| }); | ||
| }); |
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,199 @@ | ||
| import { | ||
| type Announcements, | ||
| DndContext, | ||
| type DragEndEvent, | ||
| KeyboardSensor, | ||
| PointerSensor, | ||
| type UniqueIdentifier, | ||
| closestCenter, | ||
| useSensor, | ||
| useSensors, | ||
| } from "@dnd-kit/core"; | ||
| import { restrictToParentElement, restrictToVerticalAxis } from "@dnd-kit/modifiers"; | ||
| import { | ||
| SortableContext, | ||
| sortableKeyboardCoordinates, | ||
| useSortable, | ||
| verticalListSortingStrategy, | ||
| } from "@dnd-kit/sortable"; | ||
| import { CSS } from "@dnd-kit/utilities"; | ||
| import { | ||
| pickableProjectGroups, | ||
| selectProjectGroupingSettings, | ||
| } from "@t3tools/client-runtime/state/project-grouping"; | ||
| import { ChevronRightIcon, GripVerticalIcon, PinIcon } from "lucide-react"; | ||
| import { Fragment } from "react"; | ||
|
|
||
| import { useClientSettings } from "../../hooks/useSettings"; | ||
| import { useSidebarProjectGroups } from "../../hooks/useSidebarProjectGroups"; | ||
| import { cn } from "../../lib/utils"; | ||
| import { | ||
| getSidebarProjectSettingsKey, | ||
| type SidebarProjectSnapshot, | ||
| } from "../../sidebarProjectGrouping"; | ||
| import { useProjects } from "../../state/entities"; | ||
| import { useUiStateStore } from "../../uiStateStore"; | ||
| import { ProjectFavicon } from "../ProjectFavicon"; | ||
| import { ITEM_ROW_CLASSNAME } from "./itemRows"; | ||
| import { SettingsGroup } from "./SettingsGroup"; | ||
| import { useSettingsScope } from "./SettingsScopeContext"; | ||
|
|
||
| const memberKeys = (group: SidebarProjectSnapshot) => | ||
| group.memberProjects.map((member) => member.physicalProjectKey); | ||
|
|
||
| export function ProjectOrderList() { | ||
| const groups = useSidebarProjectGroups(); | ||
| const projects = useProjects(); | ||
| const groupingSettings = useClientSettings(selectProjectGroupingSettings); | ||
| const reorderProjects = useUiStateStore((store) => store.reorderProjects); | ||
| const { selectScope } = useSettingsScope(); | ||
| const sensors = useSensors( | ||
| useSensor(PointerSensor, { activationConstraint: { distance: 4 } }), | ||
| useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }), | ||
| ); | ||
| const shown = pickableProjectGroups(groups); | ||
|
|
||
| // dnd-kit announces raw ids by default, and these ids are internal project keys. | ||
| const findGroup = (id: UniqueIdentifier | undefined) => | ||
| shown.find((group) => group.projectKey === id); | ||
| const nameOf = (id: UniqueIdentifier) => findGroup(id)?.displayName ?? String(id); | ||
| const announcements: Announcements = { | ||
| onDragStart: ({ active }) => `Picked up ${nameOf(active.id)}.`, | ||
| onDragOver: ({ active, over }) => | ||
| over ? `${nameOf(active.id)} is over ${nameOf(over.id)}.` : undefined, | ||
| onDragEnd: ({ active, over }) => { | ||
| if (!over) return `${nameOf(active.id)} was dropped.`; | ||
| return findGroup(active.id)?.pinned === findGroup(over.id)?.pinned | ||
| ? `${nameOf(active.id)} was dropped on ${nameOf(over.id)}.` | ||
| : `${nameOf(active.id)} did not move. Pinned projects stay above unpinned projects.`; | ||
| }, | ||
| onDragCancel: ({ active }) => `Moving ${nameOf(active.id)} was cancelled.`, | ||
| }; | ||
|
|
||
| const handleDragEnd = ({ active, over }: DragEndEvent) => { | ||
| const dragged = findGroup(active.id); | ||
| const target = findGroup(over?.id); | ||
| // Pinned projects always sort first, so a drop across that line could not stick. | ||
| if (!dragged || !target || dragged === target || dragged.pinned !== target.pinned) return; | ||
| reorderProjects(groups.flatMap(memberKeys), memberKeys(dragged), memberKeys(target)); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="space-y-3"> | ||
| <p className="px-3 text-sm text-muted-foreground sm:px-4"> | ||
| Choose a project to manage its name, icon, checkouts and actions. Drag projects to fix their | ||
| order in the sidebar. | ||
| </p> | ||
| <SettingsGroup> | ||
| <DndContext | ||
| sensors={sensors} | ||
| collisionDetection={closestCenter} | ||
| modifiers={[restrictToVerticalAxis, restrictToParentElement]} | ||
| accessibility={{ announcements }} | ||
| onDragEnd={handleDragEnd} | ||
| > | ||
| <SortableContext | ||
| items={shown.map((group) => group.projectKey)} | ||
| strategy={verticalListSortingStrategy} | ||
| > | ||
| <ol aria-label="Projects, in sidebar order"> | ||
| {shown.map((group, index) => ( | ||
| <Fragment key={group.projectKey}> | ||
| {shown[index - 1]?.pinned && !group.pinned ? ( | ||
| <li aria-hidden className="mx-3 border-t border-border sm:mx-4" /> | ||
| ) : null} | ||
| <SortableProjectRow | ||
| group={group} | ||
| position={index + 1} | ||
| onOpen={() => | ||
| selectScope({ | ||
| project: getSidebarProjectSettingsKey(group, groupingSettings, projects), | ||
| }) | ||
| } | ||
| /> | ||
| </Fragment> | ||
| ))} | ||
| </ol> | ||
| </SortableContext> | ||
| </DndContext> | ||
| </SettingsGroup> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function SortableProjectRow({ | ||
| group, | ||
| position, | ||
| onOpen, | ||
| }: { | ||
| readonly group: SidebarProjectSnapshot; | ||
| readonly position: number; | ||
| readonly onOpen: () => void; | ||
| }) { | ||
| const { | ||
| attributes, | ||
| listeners, | ||
| setNodeRef, | ||
| setActivatorNodeRef, | ||
| transform, | ||
| transition, | ||
| isDragging, | ||
| } = useSortable({ id: group.projectKey }); | ||
|
|
||
| return ( | ||
| <li | ||
| ref={setNodeRef} | ||
| style={{ transform: CSS.Translate.toString(transform), transition }} | ||
| className={cn( | ||
| ITEM_ROW_CLASSNAME, | ||
| "flex items-center gap-2", | ||
| isDragging && "relative z-10 rounded-md bg-background shadow-md", | ||
| )} | ||
| > | ||
| <button | ||
| type="button" | ||
| ref={setActivatorNodeRef} | ||
| {...attributes} | ||
| {...listeners} | ||
| aria-label={`Reorder ${group.displayName}, position ${position}`} | ||
| className="flex size-6 shrink-0 cursor-grab touch-none items-center justify-center rounded text-muted-foreground/70 outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring active:cursor-grabbing" | ||
| > | ||
| <GripVerticalIcon className="size-3.5" /> | ||
| </button> | ||
| <span | ||
| aria-hidden | ||
| className="w-5 shrink-0 text-right text-xs text-muted-foreground tabular-nums" | ||
| > | ||
| {position} | ||
| </span> | ||
| <button | ||
| type="button" | ||
| className="flex min-w-0 flex-1 cursor-pointer items-center gap-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring" | ||
| onClick={onOpen} | ||
| > | ||
| <ProjectFavicon project={group} className="size-4 shrink-0" /> | ||
| <span className="min-w-0 flex-1"> | ||
| <span className="block truncate text-sm font-medium">{group.displayName}</span> | ||
| <span className="block truncate text-xs text-muted-foreground"> | ||
| {group.workspaceRoot} | ||
| </span> | ||
| </span> | ||
| </button> | ||
| {group.pinned ? ( | ||
| <span className="flex shrink-0 items-center gap-1 text-xs font-medium text-muted-foreground"> | ||
| <PinIcon aria-hidden className="size-3" /> | ||
| Pinned | ||
| </span> | ||
| ) : null} | ||
| <button | ||
| type="button" | ||
| tabIndex={-1} | ||
| aria-hidden | ||
| className="flex shrink-0 cursor-pointer items-center text-muted-foreground" | ||
| onClick={onOpen} | ||
| > | ||
| <ChevronRightIcon className="size-4" /> | ||
| </button> | ||
| </li> | ||
| ); | ||
| } | ||
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
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.