Repository navigation
feat(json-viewer): sort object keys alphabetically in read-only JSON trees - #1427
Conversation
…trees Add a Sort keys toggle to read-only JSON trees, next to Expand all and Collapse all, in both the compact and full-height layouts. It passes json-edit-react's keySort a numeric-aware collator, so "2" sorts before "10" and case is ignored at the first pass. Arrays keep their element order, the value and onChange are untouched, and editable trees do not offer the toggle. Closes TabularisDB#1394
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (18 files)
Reviewed by claude-sonnet-5.5 · Input: 248 · Output: 1.4K · Cached: 200.1K Review guidance: REVIEW.md from base branch |
1-DARK
left a comment
There was a problem hiding this comment.
Thanks for a very thorough PR.
I verified it locally on macOS against main (c7ce199):
- The 16 new tests pass (74 vs 58 on main for the touched files).
- pnpm typecheck, ESLint, Prettier and check-theme-tokens.mjs are clean.
- All 13 locales have jsonInput.sortKeys.
- A full canonical suite run came back green: 499 files / 8,159 tests.
- keySort?: boolean | CompareFunction confirmed in [email protected] - no new dependency, as described.
- Manually exercised against a real SQLite DB: sorting is recursive, arrays keep element order, disabling restores the original order, the toggle is absent on editable trees and disabled for scalar roots, and Tab + Space work with aria-pressed announced.
LGTM - approving.
debba
left a comment
There was a problem hiding this comment.
Thanks for using the JSON editor's display sorting without replacing the underlying value, and for covering nested objects, array order and both viewer layouts.
Thanks for your first PR here! We would be happy to see you on Discord if you would like to join in: https://discord.com/invite/K2hmhfHRSt
All 74 targeted frontend tests pass on this branch, and typecheck passes.
I haven't found a blocking issue in the diff. I'll run end-to-end tests for a final verification, then proceed with the merge if those checks pass.
|
I tested the read-only JSON viewer from a PostgreSQL materialized view in the real web app. Nested keys sort correctly, numeric keys keep 2 before 10, array elements retain their order, and switching sorting off restores the original tree. The raw JSON stays unchanged. The editable compact tree in the SQLite row editor correctly hides Sort keys. It works and is ready to merge. Lint, typecheck and all 8,159 frontend tests passed. The unchanged Rust tree matches the one tested for #1443; host test:all has the same GLib setup failure as main. Compact read-only and scalar-root cases were covered by unit tests, not manual app checks; desktop was not tested. |
Closes #1394
Read-only JSON trees get a Sort keys toggle next to Expand all / Collapse all. When it is on, every object in the tree lists its properties alphabetically, at every level. Turning it off brings back the original order. It works in both layouts: the full-height JSON viewer and the compact tree in the row editor.
It changes only how the tree is shown:
onChangeis never called.Key order
The tree uses
json-edit-react's ownkeySortprop; no new dependency. Its default comparison treats keys as plain strings, which puts"10"before"2". JavaScript already lists integer-like keys in numeric order, so turning that default on would have made objects keyed by id look worse than with the toggle off.So
keySortgetscompareJsonKeys(inutils/jsonTree.ts), built onIntl.Collatorwithnumeric: true:1, 2, 10;apple, Banana, cherry.UI
The toggle is a native button with
aria-pressed, so screen readers announce its state. It uses the same pressed style as the JSON input's Diff and Side by side toggles and is disabled for a scalar root, just like Expand all and Collapse all. ThejsonInput.sortKeyslabel is added to all 13 locales.Testing
tests/utils/jsonTree.test.ts: four new tests.compareJsonKeysorders numeric-looking keys, mixed-case words, and numbers before words.JsonEditorwithkeySort={compareJsonKeys}. It checks that nested object keys are sorted (2, 10, list, …, nested, alpha, Beta, y, z) and that the array underlistkeeps its element order.tests/components/ui/JsonTreeView.test.tsx: newsort keystests.keySorton and off,aria-pressedfollows it, the data is passed through unchanged, andonChangeis never called.tests/setup.ts: addedArrowDownAZto thelucide-reactmock.pnpm typecheckpassed. ESLint and Prettier passed on the changed files, and so didnode scripts/check-theme-tokens.mjs.routing,EditorResultChart,VisualExplainPage,VisualExplainModalandNewConnectionModal. All 164 tests in those files pass when run on their own, onmainand on this branch.How to try it
In SQLite, create a table without a primary key, so the JSON editor opens read-only:
Open the table, right-click the
doccell and choose Open in JSON Editor, then switch to Tree.Click Sort keys. The keys show as
2, 10, list, nested, z, withalpha, Beta, yinsidenestedandc, dinside the first array item. The array items stay in order: the object first, then"x".Click it again. The original order
2, 10, z, nested, listcomes back.Open a table with a primary key in the JSON editor. The tree is editable there, and there is no Sort keys button.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.