fix: keep the default table sorting alive past the first grid state save - #1787
Merged
Conversation
`resolveSorting` falls back to the block's default sorting only while the
persisted user sorting is `null`; `[]` means the user cleared the sorting and
deliberately suppresses the default. The grid state never produced that `null`:
AG Grid omits `sort` while nothing is sorted, and the converter turned the
absent state into `[]`. Since `onStateUpdated` fires as the grid initialises,
the first persisted state entry stamped `sorting: []` and the default was gone
from that moment on — the sorted column stayed in the table, just unsorted.
The absent sort state now converts to `null`, and `normalizeSort` promotes it
to an explicit empty sort model only after the grid has reported an explicit
one, so clearing the sorting by hand still suppresses the default. This mirrors
`normalizeColumnVisibility`, which already draws the same distinction for
hidden columns.
`stateForReloadCompare` treats an empty sort model as absent, so the promoted
`{ sortModel: [] }` does not read as a state change and trigger a grid reload.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1787 +/- ##
=======================================
Coverage 52.97% 52.97%
=======================================
Files 412 412
Lines 21322 21322
Branches 4761 4761
=======================================
Hits 11296 11296
Misses 8665 8665
Partials 1361 1361 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mzueva
self-requested a review
August 19, 2026 08:15
mzueva
approved these changes
Aug 19, 2026
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.
The problem
The default sorting a block passes to
createPlDataTableV3({ sorting })applies on the first render and then silently disappears: the sorted column stays in the table, the rows just stop being sorted.resolveSorting(sdk/model/.../createPlDataTableV3.ts) reads the persisted user sorting three ways:null— the user never touched sorting → apply the block's default;[]— the user explicitly cleared the sorting → suppress the default.The grid state never produced that
null. AG Grid omitssortfrom its state while nothing is sorted, andconvertAgSortingToPTableSortingturned the absent state into[].onStateUpdatedfires as the grid initialises, so the first entry written tostateCachealready stampedsorting: []and the block's default was gone from that moment on.Before
@platforma-sdk/model@1.80.0resolveSortingusedisEmptyinstead ofisNil, so[]still fell through to the default and the bug stayed hidden. Going back toisEmptyis not the fix — it breaks clearing the sorting by hand.The change
convertAgSortingToPTableSortingreturnsnullfor an absent sort state, and[]only for a genuinely emptysortModel.normalizeSortinPlAgDataTableV2.vuepromotes the absent state to an explicit{ sortModel: [] }only once the grid has reported an explicit sort model before — so clearing the sorting by hand still suppresses the default. This is the same treatment the neighbouringnormalizeColumnVisibilityalready gives hidden columns; both are now applied throughnormalizeGridState.stateForReloadComparetreats an emptysortModelas equivalent to an absent one, so the promoted{ sortModel: [] }does not read as a state change and trigger a grid reload.Compatibility
Existing projects recover on the next render without a state migration: their stored
gridState.sortis absent, which now reads as "untouched".Verification
pnpm --filter @platforma-sdk/ui-vue run types:check— no errors in the changed files (the 18 errors elsewhere reproduce on a clean tree).formatter:check,linter:check— clean.table-state-v2.test.tscovering the three converter states, plus the package's existing node suites — green.PlDatasetSelector.jsdomtest.tsfails on a clean tree too in this environment.Greptile Summary
The PR preserves a block’s default table sorting until the user explicitly changes or clears sorting, while retaining the distinction between untouched and intentionally empty state.
sortobject; an omitted object now remains distinguishable from an explicit emptysortModel.nullmeans untouched, while[]means explicitly cleared.Confidence Score: 4/5
The PR appears safe to merge, with the non-blocking concern that its central sort-state transition logic is not directly covered by tests.
The nullable converter matches the receiving schema and model fallback semantics, and AG Grid initialization ordering contradicts the suspected sort-erasure path; only focused regression coverage for normalizeSort remains advisable.
Files Needing Attention: sdk/ui-vue/src/components/PlAgDataTable/PlAgDataTableV2.vue; sdk/ui-vue/src/components/PlAgDataTable/sources/table-state-v2.test.ts
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[AG Grid state update] --> B{sort present?} B -- Yes --> C[Persist explicit sortModel] B -- No --> D{Previous sort present?} D -- No --> E[Keep sort absent] D -- Yes --> F[Persist empty sortModel] E --> G[Converter returns null] F --> H[Converter returns empty array] C --> I[Converter returns user sorting] G --> J[Use block default sorting] H --> K[Suppress block default] I --> L[Use user sorting]Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix: keep the default table sorting aliv..." | Re-trigger Greptile
Context used: