Skip to content

feat(datagrid): add default row sort setting (#1284)#1295

Merged
datlechin merged 2 commits into
mainfrom
feat/issue-1284-default-row-sort
May 16, 2026
Merged

feat(datagrid): add default row sort setting (#1284)#1295
datlechin merged 2 commits into
mainfrom
feat/issue-1284-default-row-sort

Conversation

@datlechin
Copy link
Copy Markdown
Member

@datlechin datlechin commented May 16, 2026

Summary

  • Adds opt-in Default row sort setting in Settings > Data Grid with three modes: No sorting (default), Primary key, First column. Closes Improve default row sorting #1284.
  • New opt-in plugin protocol PluginDefaultSortProvider (no PluginKit ABI bump, uses runtime cast like PluginDiagnosticProvider). Plugins can return .suppress or .forceColumns([String]) to override the app setting.
  • Sort provenance lives in SortState.source (.user vs .defaultSort). Default-applied sort does not count as "active work", so preview tabs and Cmd+Click reuse still work.

Implementation notes

  • DefaultSortResolver is a pure enum with one static func, fully covered by unit tests in TableProTests/Services/DefaultSortResolverTests.swift.
  • Two-pass execution: phase 1 runs without ORDER BY (schema/PK not yet known). Then applyPhase1Result resolves the default sort once PK is available and triggers a single re-run. Mirrors the existing restoreFiltersForTable pattern. Gated by TabExecutionState.didEvaluateDefaultSort so it only fires once per tab lifetime.
  • User-initiated sort writes are unchanged. Any SortState constructed by user code naturally gets source: .user from the default initializer. No sprinkled flag resets at write sites.

Test plan

  • Build clean in Xcode (Debug + Release).
  • `swiftlint lint --strict` passes.
  • Run `DefaultSortResolverTests`, all cases green.
  • Open table with PK, setting = Primary key: rows sort by PK ASC, header shows indicator.
  • Open table without PK, setting = Primary key: no sort, no indicator.
  • Setting = First column: sorts column 0. Setting = No sorting: engine order.
  • Click header to sort by another column: default sort replaced. Refresh keeps user sort.
  • Triple-click header to clear sort: default does not re-apply on next refresh.
  • Settings > Data Grid > Default row sort picker shows all three options with correct labels.
  • Preview tab mode on: opening table B from table A (default-sort active on A) reuses the preview tab (does not open new native tab).
  • Opening table B from table A after user-clicked a header on A: opens new native tab.
  • Restore tabs from disk: default sort applies on first load.

@datlechin datlechin merged commit c7c7991 into main May 16, 2026
1 check passed
@datlechin datlechin deleted the feat/issue-1284-default-row-sort branch May 16, 2026 13:46
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.

Improve default row sorting

1 participant