fix(desktop): keep new sidebar group orders on the integer lane
Problem
"New group" in a sidebar workspace's context menu throws and does nothing when
that workspace is already inside a group: no group is created, the workspace
does not move, and the inline rename never opens. The insert is rejected with a
schema validation error on tabOrder (DESKTOP-193, 1.29.0).
Root cause
getNewGroupTabOrder (#7381) placed the new group at the midpoint between its
source group and the next lane item: first.tabOrder + (next - first.tabOrder) / 2.
Every sidebar lane order is z.number().int() (projects, workspaces, sections,
presets alike), and the lane is renumbered densely (index + 1) on every
reorder — so next - first.tabOrder is normally 1 and the midpoint is a
half-integer the section schema refuses. The helper's own test asserted 2.25,
which is why this shipped green.
Widening the field is not an option: the lane feeds getPrependTabOrder
(min - 1) and getNextTabOrder (max + 1), which would hand fractional
orders straight to the workspace row schema — turning one crash into a crash on
the next workspace added to that project.
The same call also read folder orders out of the derived tag-folder index,
whose tag-only folders carry the synthetic 2 ** 31 floor that
workspaceTagFolders documents as never-to-be-persisted.
Fix
Take the slot directly after the source group (first.tabOrder + 1) and drop
the midpoint math and its topLevelOrders parameter. Orders stay integers, and
the new group shares that slot with whatever already held it until the next
reorder renumbers the lane densely. Against a workspace it renders first (the
builder adds sections before workspaces and sorts stably); against another
folder the two order by section id, so the new group can land just below that
neighbour rather than just above it. Both are adjacent to the source, and the
inline rename opens on the new group either way.
Placement anchors on the stored section row only. A folder without one carries
an order the lane does not own — the derived 2 ** 31 floor, or a host tag
setting (which is how a v1-migrated group arrives on a device that did not run
the migration itself) — and such a source now falls back to the end of the
lane, as it did before #7381, instead of persisting a foreign order.
Verification
Repro of the reported path against the code before this change — the value
computed for the insert, and the schema's answer to it:
computed tabOrder: 1.5
ZodError: [
{
"expected": "int",
"format": "safeint",
"code": "invalid_type",
"path": [ "tabOrder" ],
"message": "Invalid input: expected int, received number"
}
]
(fail) getNewGroupTabOrder > returns an order the section row accepts [1.44ms]
The new returns an order the section row accepts test is that assertion, run
against the real section schema; it passes after the change.
bunx biome check <changed files>
Checked 3 files in 24ms. No fixes applied.
cd apps/desktop && bun run typecheck
$ tsr generate
$ tsc --noEmit
(clean)
bun test over the sidebar state hook, the sidebar components and the tag
folder utils:
bun test v1.3.14 (0d9b296a)
229 pass
0 fail
440 expect() calls
Ran 229 tests across 27 files. [558.00ms]
No user-facing strings changed, so check:i18n does not apply.
Refs DESKTOP-193
Summary by CodeRabbit
- Bug Fixes
- Improved dashboard sidebar ordering for grouped sections and workspaces.
- Group members now appear in consistent integer positions immediately after their group.
- Improved ordering when resolving sidebar sections and source folders.
- Preserved predictable fallback ordering when no source section is available.
- Updated ordering validation to ensure generated sidebar positions remain valid.