fix(data-table) Harden sort whitelist and row_id selection handling#50
Merged
Conversation
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.
Summary
Hardens
Corex.DataTablesort and selection handling without breaking existing apps.Sort.assign_for_sort/3infers:sort_columnsfrom row map keys when omitted. Database handlers must still assign an explicit whitelist and useparse_sort_by/2.row_idkeep the legacyinspect/1fallback but log a dev warning when:debugis enabled on:corex. Stream rows still default to the stream dom id. Docs and e2e demos recommend explicitrow_id.Changes
Library
Corex.DataTable.Sortparse_sort_by/2rejects forged or unknown sort params.handle_sort/3uses strict parsing; invalid params are ignored (no crash).assign_for_sort/3infers:sort_columnsfrom atom keys on the first row when the option is omitted.parse_sort_by(param, nil)returns:errorfor DB-backed handlers that must set:sort_columnsexplicitly.Corex.DataTableresolve_row_id/1: stream + selectable defaults tofn {id, _} -> id end; list + selectable withoutrow_idfalls back toinspect/1with optional dev warning.@row_id.(row)after resolution.Corex.DataTable.Selection:row_idmust match the component and should not rely on the inspect fallback.Tests
test/components/data_table_sort_test.exs: inference, forged atoms, empty rows, explicitsort_columns: nil.test/components/data_table_test.exs: inspect fallback and tuple/stream-shaped row id behavior.E2e
Sort.parse_sort_by/2,Sort.assign_for_sort/3, andSelectionhelpers consistently.Non-breaking behavior
:sort_columns:sort_columnsparse_sort_by/2returns:erroruntil whitelist is assignedrow_idinspect/1fallback:debugis onrow_idresolve_row_id/1)