fix(desktop): hide interaction-materialized tag folders once empty

LU
2mo ago
+154-3

What & why

Desktop sidebar tag folders can outlive their last workspace as empty groups.

Problem. Collapsing, expanding or reordering a folder that exists only because a workspace carries its tag makes useDashboardSidebarState -> ensureSectionRow mint a row in the local v2SidebarSections collection ("materialize-on-interaction"). deriveTagFolders renders every stored row, so once the last workspace carrying that tag is deleted or archived the folder stays behind as an empty group. The only way to get rid of it is "Delete group".

Root cause. A row created purely as a presentation cache (collapse/order) is indistinguishable from a folder the user created on purpose, so it is rendered unconditionally.

Fix.

  • Rows minted by ensureSectionRow get materializedByInteraction: true (new optional schema field, default(false), so every previously persisted row parses unchanged).
  • New omitStaleMaterializedFolders (in workspaceTagFolders) drops such rows while no workspace in the same project/scope carries their tag. deriveTagFolders applies it, and so does the lane's top-level item list in getProjectTopLevelItems, so reorder indexes keep matching what is rendered. The stored row is left in place, so its collapse state returns if the tag is used again.
  • Folders made on purpose stay visible while empty: "New folder" (createSection), v1 group import and the legacy-folder migration never set the flag. Existing rows have no flag either, so nothing already persisted changes behaviour (they are kept, conservatively).
  • I did not use "no host tag setting" as the discriminator: createSection writes a host setting, but so do rename and recolour of derived folders, and the v1 import / legacy migration insert rows without one, so it would hide folders that were created on purpose.
  • createSection now replaces a stale flagged row with the same key rather than returning it (it would have been invisible).
  • The two live-query projections feeding deriveTagFolders select the new field.

How I tested it

  • Added unit tests to workspaceTagFolders.test.ts: flagged row kept while a member carries the tag (with normalization and per-project scoping), dropped once the last member is gone, folders created on purpose and legacy tagless rows kept while empty.
  • cd apps/desktop && bun test src/renderer/routes/_authenticated/utils/workspaceTagFolders src/renderer/routes/_authenticated/hooks/useDashboardSidebarState src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/utils -> 104 pass, 0 fail.
  • bun run lint (root) -> clean. NODE_OPTIONS=--max-old-space-size=8192 bun run typecheck in apps/desktop -> clean (default heap OOMs here).
  • Full bun test in apps/desktop: 7732 pass, 34 fail. The same 34 fail on unmodified main in my environment (git/shell-dependent suites), so they are unrelated.
  • No before/after screenshots: I did not run the desktop app, so this is verified by unit tests and type/lint checks only.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs

šŸ¤– Generated with Claude Code


Summary by cubic

Fixes desktop sidebar tag folders lingering as empty groups after the last workspace carrying their tag is deleted or archived.

Tag-derived folders only gain a stored row when interacted with (collapse, reorder, rename). Those interaction-materialized rows are now flagged and hidden once no workspace in the project carries their tag, while folders created on purpose (New folder, v1 import, legacy migration) and all pre-existing rows keep rendering when empty. Creating a new folder over a stale flagged row now replaces it instead of silently returning it.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected dashboard sidebar tag-folder handling: interaction-created folders remain available while a matching tag exists in the same project, and stale folders are removed when no workspace uses that tag.
    • Preserved folder collapse state for matching tags and kept intentionally created empty folders and legacy folders distinct from interaction-created folders.