-
Notifications
You must be signed in to change notification settings - Fork 1
fix: keep the default table sorting alive past the first grid state save #1787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+120
−12
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| "@platforma-sdk/ui-vue": patch | ||
| --- | ||
|
|
||
| Keep the default `sorting` passed to `createPlDataTableV3` alive | ||
|
|
||
| `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` from its state while nothing is sorted, and | ||
| `convertAgSortingToPTableSorting` turned the absent state into `[]`. | ||
|
|
||
| `onStateUpdated` fires as soon as the grid initialises, so the first persisted | ||
| state entry stamped `sorting: []` and the block's default sorting was dropped | ||
| from that moment on — the sorted column stayed in the table, just unsorted. | ||
|
|
||
| The absent sort state now converts to `null`, and `normalizeSort` (next to the | ||
| existing `normalizeColumnVisibility`, which solves the same problem for hidden | ||
| columns) turns it into an explicit `{ sortModel: [] }` only once the grid has | ||
| reported an explicit sort model before — so clearing the sorting by hand still | ||
| suppresses the default. Existing projects recover on the next render without a | ||
| state migration: their stored `gridState.sort` is absent, which now reads as | ||
| "untouched". |
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
37 changes: 37 additions & 0 deletions
37
sdk/ui-vue/src/components/PlAgDataTable/sources/table-state-v2.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // @vitest-environment happy-dom | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { computed } from "vue"; | ||
|
|
||
| // The module pulls in uikit for `computedCached`; stub it so the test does not | ||
| // drag the whole component library (and its DOM-time side effects) in. | ||
| vi.mock("@milaboratories/uikit", () => ({ | ||
| computedCached: computed, | ||
| })); | ||
|
|
||
| const { convertAgSortingToPTableSorting } = await import("./table-state-v2"); | ||
|
|
||
| describe("convertAgSortingToPTableSorting", () => { | ||
| it("reports an absent sort state as untouched, so the model keeps its default sorting", () => { | ||
| expect(convertAgSortingToPTableSorting(undefined)).toBeNull(); | ||
| }); | ||
|
|
||
| it("reports an empty sort model as explicitly cleared, which suppresses the default", () => { | ||
| expect(convertAgSortingToPTableSorting({ sortModel: [] })).toEqual([]); | ||
| }); | ||
|
|
||
| it("converts a sort model, taking NA/absent as least values only when ascending", () => { | ||
| const column = { type: "column", id: "colId" }; | ||
| const colId = JSON.stringify(column) as never; | ||
| expect( | ||
| convertAgSortingToPTableSorting({ | ||
| sortModel: [ | ||
| { colId, sort: "asc" }, | ||
| { colId, sort: "desc" }, | ||
| ], | ||
| }), | ||
| ).toEqual([ | ||
| { column, ascending: true, naAndAbsentAreLeastValues: true }, | ||
| { column, ascending: false, naAndAbsentAreLeastValues: false }, | ||
| ]); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.