fix(datagrid): track who chose the row order and let the sort direction be set - #2670
Open
datlechin wants to merge 1 commit into
Open
fix(datagrid): track who chose the row order and let the sort direction be set#2670datlechin wants to merge 1 commit into
datlechin wants to merge 1 commit into
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2665.
Three reported symptoms, one mechanism.
Root cause
SortStateanswered two different questions with one value: what order the rows are in, and what order the user asked for. The click cycle (HeaderSortCycle) and the header rendering (applySortIndicators) both read only itscolumnsand ignoredsourceentirely, whose single reader in the whole app wasQueryTab.hasUserActiveSort. On top of that, direction was hard-coded ascending in two places:DefaultSortResolverfor the app-applied default, andsingleSortTransitionfor the first click on any column.Measured, not assumed
Driven against the Chinook sample in a throwaway sandbox, with the SQL read out of the app's own
query_history.db:AlbumORDER BY \AlbumId` ASC`AlbumId#1ORDER BY \AlbumId` DESC`AlbumId#2CustomerCustomerId#1ORDER BY \CustomerId` ASC`CustomerId#2ORDER BY \CustomerId` DESC`So the third symptom is not a swallowed click. The query really re-runs; ascending on a rowid table is the order already on screen.
Against stock AppKit (swiftc harness, real
NSTableView, macOS 27.0 build 26A5406e):sortDescriptorPrototype.ascendingsets the first-click direction.DataGridColumnPoolalready set a prototype on every data column, hard-codedascending: true, so AppKit has been running a second sort model underneath this one.tableView.sortDescriptorsreaches no accessibility client: every header cell'saccessibilitySortDirectionstayed.unknownthrough every change to it.setAccessibilitySortDirectionis the real channel, and nothing called it, so the sorted column was silent to VoiceOver.mouseDraggedoverride is called zero times, and column order and widths do not change, so all three of the old drag guards passed and the grid sorted. AppKit itself correctly declined to.The fix
SortSourceis three-valued:.unset,.defaultSort,.user. An empty sort the user chose is now a different value from a tab that has not decided, which is what makes Don't Sort stick. It persists onPersistedTaband onTabNavigationEntry; a file written before the key existed decodes to the behaviour it was written under.DefaultSortResolver,HeaderSortCycle, and the column'ssortDescriptorPrototype, so AppKit's model stops diverging.setAccessibilitySortDirection, cleared on the rest, and the descriptor mirror writes the whole list rather than only its leading entry.Collateral fixed in the same change
Found while investigating, each verified against the code before it was fixed:
column: -1descriptor.browse_tablelosing its ORDER BY when the sort column was outsidecolumns. The missing sort column is appended, so every requested column keeps the position it was asked for;docs/external-api/mcp-tools.mdxrecords that.Verification
build: PASS.swiftlint --strict: clean on the app target and on both test targets.docs:check-writing-style.shandcheck-docs-against-source.pyboth pass.testmanagerdon this machine has been wedged since 27 Aug ("The test runner hung before establishing connection"), every run returns 0 cases executed, and SIP refuseslaunchctl kickstart, so it needs a logout to clear. The same 25 suites ran 224/225 before the review fixes, the one failure being a bad fixture in a test added here, since rebuilt from a real encoder round-trip. CI runs them on this PR.HeaderSortUITestsis new and has not been executed locally for the same reason.CLAUDE.md's header invariant claimedsortDescriptorswas published "for accessibility". That half was wrong and is corrected.https://claude.ai/code/session_01CCwzDmzDy9SW2DT5peRhAm