Skip to content

Put one collection under another and rename a collection from the sidebar - #4281

Merged
mstomar125 merged 6 commits into
mainfrom
issue-4280-collections
Nov 16, 2026
Merged

mstomar125 merged 6 commits into
mainfrom
issue-4280-collections

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Refs #4280 (the issue closes when this merges).

What a person sees now

  • Nest: drag a collection row onto another, or use the row's ⋯ menu → Move to collection… (a dialog that lists only the collections it can go into). The target opens, the moved collection is listed under it, and focus lands on it there.
  • A collection in several collections is listed under each of them. Dragging a nested row onto an unrelated collection adds that collection as a second parent and the row now appears under both. (A parent that is an ancestor of another of its parents is still left out, as before: a collection filed under both a workspace-wide container and its real parent is not listed twice, with one inside the other.)
  • When the result would otherwise be invisible (a collection put into the ancestor of a parent it already has, or taken out of one it was not listed under) a notice says so: "“HR” is now also in “DeutNet”. It stays listed under “Company Policies”, which is inside “DeutNet”."
  • Un-nest: the same menu has Remove from , one entry per parent. A collection stays in its other parents.
  • Rename: double-click the name, or menu → Rename. Enter saves and focus returns to the name; Escape or leaving the field abandons it. A name another collection already has (ignoring letter case) is refused with a message and the field stays open with what was typed and keeps focus. A rename against a stale version says the collection changed, refreshes the list, and the retry goes out with the current version.
  • Refused moves say why in words: into itself, into a collection it is already in, and into one of its own descendants (naming both collections). Backend refusals (for example no rights on the target) come back as "Couldn't move “X” into “Y”: <the backend's reason>" in a dismissible message under the list. Dismissing it does not close an open rename field.
  • The list nests to any depth (it stopped at three levels before), shown to a fixed depth of 24 so a tangled graph cannot grow without bound; a parent edge that would close a cycle in the data is ignored.
  • Accessible tree: the list is a labelled tree of treeitems with aria-level, aria-expanded (only on a collection that has collections in it) and aria-selected. Arrow keys: Up/Down move between rows, Right opens a collapsed collection and then enters it, Left closes an open one and then goes to its parent, Home/End go to the first and last row.

Premises of the issue, checked against main

  • Core supports nesting: true. A root collection may nest in another; add_to_collection refuses a cycle at the store (collection_cycle).
  • "The sidebar shows only top-level collections": not exactly. It already built a tree from parentCollectionIds and showed three levels, under ONE parent only (the most specific). There was no way to create or change nesting from it. The store's header said collections are flat, which was wrong (corrected).
  • "Add existing may not list collections as candidates": unchanged and out of scope (that picker is for content nodes in a collection's view).
  • Backend commands already existed (add_node_to_collection, remove_node_from_collection, rename_collection, with the version check and a refusal of a duplicate name); the frontend used none of them for collections. No Rust change was needed.
  • Cycle guard: core already refuses it; the frontend checks first (same rules) so the message names both collections, and also maps the backend's collection_cycle text to the same message when its list is stale.

Design

  • stores/collection-moves.ts: the nesting rules and messages as pure functions (ancestors, descendants, the refusal for a move, the candidate list and its early-exit check, the failure messages, stale-version detection).
  • collectionsData.moveCollectionInto / removeCollectionFrom / renameCollection: validate, call the existing service, reload, return { ok } | { ok: false, message }; a database switched mid-call is reported, not written into the new store. A failed rename reloads so the retry uses the current version.
  • buildCollectionsTree lists a collection under every most-specific parent (displayParentIds); the old single-parent choice is gone. Expansion state stays per collection (opening a collection that appears twice opens it in both places).
  • The stale-version case the rename command really reports is an update error with the daemon's Aborted status and "Version conflict" in the message; an earlier branch looking for a VERSION_CONFLICT code could never fire (the rename command only emits COLLECTION_EXISTS or UPDATE_ERROR) and is gone.
  • collection-row-menu.svelte (design-system dropdown menu) and collection-move-dialog.svelte (design-system dialog): the keyboard route to everything dragging does. Whatever the menu opens manages focus itself, so the menu's own focus return to its trigger is cancelled after a choice (it would take focus off the rename field, or land on a row that has moved). The menu stays mounted but hidden while renaming, for the same reason.
  • Drag and drop and arrow-key navigation are Svelte actions, so no lint suppression. A row removed mid-drag clears the drag state.
  • A row's menu entries (its parents, whether it can move) are evaluated only when its menu opens: Svelte reads a component's props lazily. A first attempt to memoize them for the whole list did more work and was reverted; the move check now stops at the first place the collection can go.
  • The sidebar's three copy-pasted levels are one recursive snippet.
  • Bugs found by the tests while building, now fixed: opening Rename from the menu lost focus to the menu's own focus return (the field cancelled itself); the dialog's choice was undone whenever the candidate list recomputed.

Tests

  • 38 sidebar tests, 20 store-action tests, 20 pure-rule tests, and four new tree tests in the existing collections suite (unrelated parents listed under each, a cycle in the data, the depth cap, a parent that is an ancestor of another).
  • Mutation checks, applied to the real source one at a time: 42 on the first version (38 re-killed on the final code, 3 re-applied to code that moved, 1 superseded) and 33 on the review fixes (multi-parent display, cycle and depth guards, stale-version detection, rename reload, notices, focus, tree roles, arrow keys, dismiss behaviour, drag state, lazy menu work). All killed. Six survived the first pass of the second set and each exposed a real test gap (a notice that could not tell a filtered list from an unfiltered one, focus return that Happy-DOM could not exercise until the test blurred the field itself, Up and Right missing from the key walk); the tests were strengthened until each was killed.
  • Tests that pinned the old single-parent display were rewritten on purpose (one now asserts a collection under unrelated parents is listed under each).
  • bun run test:changed passes on exactly what is pushed (Happy-DOM and Chromium tiers); frontend lint, design-token check and svelte-check are clean. It caught one repo rule earlier (focus styles may change colour only); fixed.

Not visually verified

The desktop app was not launched. Not covered by anything but event-level tests and the design checks: the real drag in the webview (the drag image, the cursor, scrolling while dragging in a long list); how the menu, dialog, notice and message rows look (spacing, wrapping, colours in light and dark); and how a real screen reader announces the tree and the focus moves (the roles and levels are asserted, the announcements are not). Focus restoration after the menu closes is asserted in Happy-DOM, where the menu's focus-return timing may differ from a real browser's.

Docs

Nothing in this PR touches the docs repo. Lines that need a change in nodespace-docs: the Collections description in the sidebar/navigation component docs (collections can be moved, un-nested and renamed from the sidebar; any depth of nesting is shown) — to be checked against what the docs say about the Collections section.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

REQUEST CHANGES (head 3a8d0e4). Overall solid and well tested; the three medium findings are small.

Checked: I ran the three new test files (55 tests pass). bun scripts/check-sync-boundary.ts is clean and the diff contains no Sync, tenant or membership wording. Also clean: no {@html}, no any, no raw console, no ticket numbers, no raw colours, and the focus styles change colour only. The collection store file (collections.svelte.ts) is the only one with Pro/sync hits, and those are just async and Sync method names.

Findings

  1. Medium (behaviour and PR body): moving into a second parent shows nothing.

    • buildCollectionsTree (collections.svelte.ts ~738) displays a collection under ONE parent (pickDisplayParent).
    • Scenario: HR sits in Company Policies. Drag HR onto Design (or use Move to collection…). add_node_to_collection adds a second parent and the row stays where it was. moveCollection (navigation-sidebar.svelte) expands Design, but HR is not listed under it.
    • The user sees a move that did nothing. The PR body line "The moved collection shows under its new parent, which opens" is true only for a collection that had no parent.
    • Dragging a nested row therefore never relocates it. The move is really "add parent", and there is no one-step "move from X to Y".
    • Ask: either say so in the dialog description and the body, and show a success note ("Added to Design; it is also still in Company Policies"), or make a drag from a nested row remove the display parent. At minimum, correct the body.
  2. Medium (dead branch): rename VERSION_CONFLICT is never produced.

    • app-lib/src/commands/collections.rs:415-418 maps only AlreadyExists to COLLECTION_EXISTS; everything else is UPDATE_ERROR. renameFailureMessage (collection-moves.ts:155) tests code === 'VERSION_CONFLICT', and the store test fakes that code.
    • Scenario: the name is changed elsewhere, so the stored collection.version is stale. The user gets "Couldn't rename “X”: " rather than the friendly message.
    • renameCollection also does not loadCollections() after a failure, so a retry reuses the same stale version and fails again until some other refresh arrives.
    • Ask: reload on failure. Either map the daemon's conflict status in the command, or match on the message too, and add a test using the real code the command emits.
  3. Medium (a11y): the focus and semantics gaps are real.

    • The tree has no role="tree", treeitem, aria-expanded or aria-level. This is unchanged from before, but the PR adds a recursive list of arbitrary depth, so depth is not conveyed to a screen reader (the expand button's label is only "Expand"/"Collapse"). Ask: at least aria-level and aria-expanded, or file a follow-up.
    • After Enter saves a rename, the input unmounts and focus drops to body. The same happens after "Remove from" when the row's menu moves. Return focus to the row's name button.
    • The keyboard route exists and is discoverable: the ⋯ trigger has aria-label="Actions for X" and is revealed on focus-within.
    • Touch: HTML5 drag does not work on touch, so the menu is the only route there. It is reachable but not announced as such; fine for a desktop app.
  4. Low (rename and blur).

    • Blur abandons the rename, and I would flag this as a product choice. It loses typed text on a stray click, and it contradicts the error path: after a duplicate-name refusal the field "stays open", but clicking the message's Dismiss ×, or anywhere, cancels it.
    • If blur happens during renameBusy and the rename then fails, the field stays open without focus, and selectOnMount does not run again. Ask: refocus the field on failure.
    • Saving on blur, as most trees do, is the more usual choice. Your call; if you keep it, state it in the menu or placeholder.
  5. Low.

    • Stuck drag state: draggingId is cleared on drop or dragend only. If the dragged row unmounts mid-drag (a list reload from a daemon event), dragend may not fire and draggingId stays set. The dragover handlers then accept any later foreign drag as a collection drop. Clear it in the destroy action as well, or on window dragend.
    • Message area: the one message area is reused by rename, move and un-nest, so a stale rename error can sit under an unrelated action. The role="alert" is rendered together with its text, so it is announced, which is fine.
    • Performance: moveTargetsFor and parentsOf run per row on every render, each O(N) to O(N·depth) (ancestorIds rebuilds its map per call). That is O(N²) for N collections. Fine for hundreds of collections. A $derived map per render would be cleaner.

Verified OK

  • Cycle: the frontend refusalForMove names both collections, and the backend collection_cycle text is mapped to the same message (nodes.rs:3166 and later emit the code). It cannot recurse infinitely, because the tree shows each node once and a data cycle's nodes become unreachable, not looped.
  • The moveTargets dialog excludes itself, descendants and current parents, and also pending and root collections.
  • Expansion state is per node, and that is consistent with the one-display-parent tree.
  • Failures are not optimistic: nothing is applied before the backend answers, so there is nothing to roll back, and a database switched mid-call is guarded by the generation check.
  • Dialog selection is no longer reset on recompute (untrack).

Tests

  • The cycle refusal, backend-refusal, dismiss and drop-target tests are real: they dispatch dragStart, dragOver and drop on the rows and assert add was not called.
  • Gap: there is no sidebar-level test with a collection that has two parents rendering two "Remove from" entries. Only the store's parentsOf covers it.
  • Gap: the "no request on drag-cancel" test only checks that the class clears; a dragEnd with no drop cannot call anything, so it is weak but not wrong.
  • Gap: I did not re-run the 42 mutations.

Not verified: real webview drag (drag image, cursor, auto-scroll), light and dark look, VoiceOver behaviour. User should eyeball: dragging a nested row onto another (finding 1), a long scrolled list, the dialog and menu in both themes, and rename then click away.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review findings addressed in new commits on the PR branch (no force-push), head 784e23c. bun run test:changed passes on exactly this head; frontend lint, design-token check and svelte-check are clean.

  1. Nested rows (medium): a collection is now listed under every parent that is not an ancestor of another of its parents, so dragging a nested row onto an unrelated collection shows it there (the old one-parent choice survives only for the container-plus-real-parent case, where listing both would show it twice with one inside the other). Parent edges that would close a cycle in the data are ignored and nesting is shown to a fixed depth (24). When the result would be invisible (a move into the ancestor of a parent it already has, or an un-nest from a parent it was not listed under) a notice says what happened. Expansion state stays per collection (an open collection that appears twice is open in both places): stated in the PR body. Tests: a collection with two parents renders two Remove from entries and is listed under both; drag onto an unrelated collection; both notices; the tree tests.
  2. Rename (medium): the stale-version case is an update error with the Aborted status and 'Version conflict' in the message (the dead VERSION_CONFLICT branch is deleted); the message says the collection changed, a failed rename reloads so the retry goes out with the current version. Test: first rename uses version 7, the retry after the reload uses 8.
  3. Accessibility (medium): labelled tree of treeitems with aria-level, aria-expanded and aria-selected; arrow keys, Home and End; focus lands on the collection name after a rename, on the moved collection under its new parent, and on the collection or its parent after a removal (the menu's own focus return is cancelled after a choice, which was overriding it). The repo has no other tree pattern, so this follows the ARIA tree pattern.
  4. Lows: dismissing a message no longer closes an open rename field; a failed rename after the field lost focus mid-save puts focus back; a row removed mid-drag clears the drag state. On memoizing the per-row work: Svelte reads a component's props lazily, so a row's parents and move check are evaluated only when its menu opens; my first memoization did more work and is reverted, and the move check now exits at the first place the collection can go (test: opening one menu works out that row only and builds no list of places).
  5. Mutation checks: 33 new mutations on the review fixes, all killed (six survived the first pass and each exposed a test gap that is now covered), and the original 42 re-verified. Details in the PR body.

Still not visually verified: the real drag in the webview, the look of the new rows in light and dark, and how a real screen reader announces the tree.

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (re-review of head 784e23c). All three mediums and the lows from my first review are fixed. The remaining notes are low and non-blocking.

Checked in the worktree: the four relevant test files pass (146 tests), check-sync-boundary is clean, and the added lines have no console., @html, any or ticket numbers.

Verified

  1. Nested rows.
    • displayParentIds lists a collection under each parent that is not an ancestor of another of its parents. The workspace-wide-container exception is sound, since otherwise the child would show twice with one copy inside the other. It is stated in the PR body.
    • A data cycle is ignored: buildCollectionsTree drops an edge when the parent is the collection itself, is missing, or is a descendant of it. A pair like A and B that are each other's parents then both become top-level, so nothing loops.
    • Keys in the keyed each are unique, because each collection is attached once per parent and so appears once among any one parent's children. The depth cap is applied in pruneEmptyCollections.
    • Expansion state is per collection, so opening a two-parent collection opens it in both places. I find that acceptable and it is stated in the body.
    • The notices cover the "looks like nothing happened" cases, in both directions (move and un-nest). The tests pin the exact wording.
    • The sidebar test with two parents covers two rows and two "Remove from" entries. Focus lands on the copy under the new parent.
  2. Rename.
    • The dead VERSION_CONFLICT branch is gone. The daemon maps a version conflict to Code::Aborted (node_service.rs ~3829-3847). The command's fallback records details: format!("{:?}", s.code()), which is "Aborted". isStaleVersion matches on that, and also on the message text.
    • The store reloads on failure, and the test checks that the retry goes out with version 8 after version 7 failed.
  3. Accessibility.
    • The tree is a labelled role=tree with treeitems that have aria-level, aria-expanded (only when there are children) and aria-selected. Each treeitem has an aria-label.
    • Flat treeitems with aria-level are valid ARIA. There is no group role, which is fine, but note that the PR text did not claim one.
    • The repo has no other role="tree" to compare against.
    • Arrow keys, Home and End act only from a row's name button, so the rename input keeps its own keys, and a test pins this.
    • Focus after a choice: the menu's focus return is cancelled only after a chosen action, so Escape still returns focus to the trigger. Focus lands on the right row after a rename, a move and a removal, falling back to the parent.
    • The Dismiss button no longer takes focus (onmousedown prevented), so it does not close an open rename.
    • The refusal is role=alert and the notice is role=status.
  4. Lows.
    • Focus is restored to the field after a failed rename.
    • draggingId is cleared in the action's destroy.
    • On per-render work, I accept the author's reasoning. The expensive per-row calls (parentsOf, shownUnderIds, the move targets) run when a menu opens or an action is taken, and canMove now uses hasMoveTarget, which stops at the first valid target. That is cheap in the common case.
  5. Tests. Spot-checked four tests: the two-parent listing with two Remove entries, the focus-on-new-parent test (it distinguishes the first copy from the second), the stale-version retry test, and the drag-state-on-unmount test. All assert real behaviour. I did not re-run the 33 or 42 mutations. The PR body is accurate.

Non-blocking notes

  • Low: the depth cap of 24 bounds depth but not width. A chain of diamonds (each collection in two unrelated parents, repeated) unfolds 2^depth rows, in the tree build and in pruneEmptyCollections. This is unrealistic data, but a cap on total rows would be the real bound.
  • Low: buildCollectionsTree now calls ancestorIds (which rebuilds a map of every collection) once per parent edge, so the build is O(N·E). That is fine for thousands of collections and noticeable at tens of thousands.
  • Low: treeitems contain buttons and an input, and Tab visits every row's buttons (no roving tabindex). That is usable, if noisier than a strict tree widget.

User should eyeball in the real app

  • A real drag: the drag image, the cursor, and auto-scroll in a long list. Also a drop on a collapsed row.
  • Light and dark look of the drop-target highlight, the ⋯ menu, the move dialog, and the error and notice rows (wrapping, with horizontal scroll in a narrow sidebar).
  • With VoiceOver: whether the tree, the level and expanded state, and the refusal or notice are announced, and where focus lands after rename, move and remove.
  • A two-parent collection: opening it in one place opens it in the other. Nested rows at depth 4 or more, for indentation.
  • Rename then click away: the abandon-on-blur choice is deliberate and stated.

mstomar125 and others added 6 commits November 16, 2026 13:12
…ebar

A collection row now has a menu (Rename, Move to collection, and a Remove from entry for each parent), a collection can be dragged onto another, and a double click renames it in place. The move refuses a collection into itself, into one it is already in, and into one of its own descendants, with a message naming both collections; any other refusal from the backend comes back as a message instead of doing nothing. The Collections list renders any depth of nesting through one recursive row.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The drag tests now check that a dragged collection's drop is accepted and a foreign drop is not, that the target opens after a move, that the row menu stays mounted but hidden while a name is edited, and that a collection still being created cannot be renamed, moved or dragged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The focus rule allows a focus treatment to change only what a control is painted with. The select's outline and offset are replaced by a border colour.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Both described collections as flat, which the nesting contradicts.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ible

A collection in several unrelated collections is now listed under each of them (a parent that is an ancestor of another of its parents is still left out), a parent edge that would close a cycle in the data is ignored, and nesting is shown to a fixed depth. A move or un-nest that leaves the list looking the same says what it did.

The Collections list is a tree for assistive technology (roles, levels, open and selected state) with arrow-key navigation, focus lands on the right row after a rename, a move or a removal, a failed rename refreshes the list so the retry uses the current version, and the stale-version failure the rename command really reports is recognised. Dismissing a message no longer closes a rename field, a row removed mid-drag clears the drag state, and each collection's parents are worked out once per change of the list.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…found

Svelte evaluates a component's props only when they are read, so a row's parents and move check are worked out when its menu opens, not for every row on every draw. The first attempt to memoize them for the whole list did more work (every collection's entries on the first menu opened) and is reverted; the move check now exits at the first place the collection can go.

The tests now also cover which parents a notice names, focus returning to a rename field that lost it mid-save, Up and Right in the arrow-key walk, and that opening one menu builds no list of places.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-4280-collections branch from 784e23c to 40560c4 Compare November 16, 2026 12:12
@mstomar125
mstomar125 merged commit ec7b855 into main Nov 16, 2026
@mstomar125
mstomar125 deleted the issue-4280-collections branch November 16, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant