Skip to content

Smart canonical-order column insertion in table picker#751

Merged
ajslater merged 1 commit into
developfrom
claude/intelligent-sanderson-4e491c
May 9, 2026
Merged

Smart canonical-order column insertion in table picker#751
ajslater merged 1 commit into
developfrom
claude/intelligent-sanderson-4e491c

Conversation

@ajslater
Copy link
Copy Markdown
Owner

@ajslater ajslater commented May 9, 2026

Summary

  • Browser table-view column picker now slots newly-toggled columns into their natural canonical position — favorite lands after cover, imprint after publisher, series after the publishing group, etc.
  • Detection rule: if the draft is in strictly-increasing canonical-rank order (rank = index in flattened _CATEGORIES), splice into the unique sorted slot. If the user has manually rearranged the draft out of canonical order, fall back to appending so we don't reshuffle their layout.
  • Pure-function helper smartInsertIndex exported from the picker SFC and covered by 16 new vitest cases.

Why

Always-append meant every newly-toggled column landed at the tail and required a drag to position. Most drafts (defaults plus light additions) are still in canonical order, so we can place the new column correctly without touching anything the user has intentionally arranged.

What changed

  • frontend/src/components/browser/table/browser-table-column-picker.vue: precompute _CANONICAL_RANK from _CATEGORIES, add smartInsertIndex(draft, key), wire toggleColumn to use it.
  • frontend/tests/unit/browser-table-column-picker.test.js: new — covers canonical-order insertion, append-on-non-canonical fallback, edge cases (empty/single-element drafts), and orphan keys (rank +∞).

Out of scope (intentionally)

  • "All" button, drag-reorder, and reset-to-defaults are unchanged.
  • No "longest-prefix-sorted" or majority-sorted heuristic — strict sortedness is the only "smart" branch; everything else appends. Keeps the behavior predictable.

Test plan

  • make lint-frontend clean
  • bun run test:ci — 5 files, 55 tests, all pass (16 new in this PR)
  • Manual: open the picker on each top-group, toggle favorite / imprint / publisher / series in various combinations and confirm placement matches expectations
  • Manual: drag a column out of canonical order, then toggle a new column on, confirm it appends (not reshuffled)

🤖 Generated with Claude Code

…cker

Previously the column picker always appended newly-toggled columns to
the end of the order list. This adds canonical-rank-aware insertion: if
the existing draft is in strictly-increasing canonical order (the order
implicit in `_CATEGORIES`), splice the new column into the unique slot
that keeps the sequence sorted. If the user has manually rearranged the
draft out of canonical order, fall back to appending so we don't reshuffle
their layout.

Examples (against the default "p" group `[cover, name, child_count]`):
  toggle favorite  → [cover, favorite, name, child_count]
  toggle imprint   → [cover, imprint_name, name, child_count]
  toggle publisher → [cover, publisher_name, name, child_count]

Covered by 16 new pure-function vitest cases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ajslater ajslater merged commit cfbac48 into develop May 9, 2026
3 checks passed
@ajslater ajslater deleted the claude/intelligent-sanderson-4e491c branch May 11, 2026 00:10
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