Repository navigation
fix(table-core): serialize array values as map keys in getFacetedUniqueValues #6634
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,7 @@ function _createFacetedUniqueValues< | |
| .map((column) => column.id) | ||
| : [columnId] | ||
|
|
||
| const facetedUniqueValues = new Map<any, number>() | ||
| const facetedUniqueValues = new ArrayKeyMap() | ||
|
|
||
| for (let i = 0; i < flatRows.length; i++) { | ||
| for (let c = 0; c < columnIds.length; c++) { | ||
|
|
@@ -94,3 +94,26 @@ function _createFacetedUniqueValues< | |
|
|
||
| return facetedUniqueValues | ||
| } | ||
|
|
||
| /** | ||
| * A Map subclass that normalises array keys so that: | ||
| * - Two distinct array instances with the same contents map to the same entry. | ||
| * - A serialised string like `'["a","b"]'` never collides with an array `['a','b']`. | ||
| * | ||
| * Internally arrays are stored under a null-byte-prefixed JSON key, which cannot | ||
| * appear in ordinary strings. | ||
| */ | ||
| class ArrayKeyMap extends Map<any, number> { | ||
| static toKey(key: unknown): unknown { | ||
| return Array.isArray(key) ? '\0' + JSON.stringify(key) : key | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift Handle array values that JSON cannot serialize. If a facet value is 🤖 Prompt for AI Agents |
||
| } | ||
| override get(key: unknown): number | undefined { | ||
| return super.get(ArrayKeyMap.toKey(key)) | ||
| } | ||
| override set(key: unknown, value: number): this { | ||
| return super.set(ArrayKeyMap.toKey(key), value) | ||
| } | ||
| override has(key: unknown): boolean { | ||
| return super.has(ArrayKeyMap.toKey(key)) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Preserve array keys when callers iterate the facet map.
ArrayKeyMapinheritsMap.keys(),entries(), andforEach(). For an array facet such as['a', 'b'], those methods expose'\0["a","b"]'instead of the array. A caller that builds facet choices from the returnedMaptherefore receives a string, despite the declaredMap<any, number>contract. Keep an original array as the stored key, and use a separate index for equal-content lookup.🤖 Prompt for AI Agents