Fix packed multitext chart colors for gates#406
Conversation
📝 WalkthroughWalkthroughThis PR modifies the color mapping logic for multitext-typed columns in DataStore. For multitext columns with capacity greater than 1, the implementation now iterates through packed values instead of using a single index, returning the color of the first non-empty semantic value or a computed fallback color. Single-capacity multitext retains legacy behavior. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Deploy Preview for mdv-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/tests/datastore-color.multitext.spec.ts (1)
32-61: Add coverage for the empty-item-skip path.The packed fixture covers “fallback only” and “real value first”, but it never exercises the branch where
"N/A"is encountered before a real value. A row like[0, 2, 65535]would catch a regression that returns the fallback color too early.Possible test extension
const column = { field: "__gates__", name: "gates", datatype: "multitext" as const, delimiter: ",", stringLength: 3, values: ["N/A", "a", "b"], data: new Uint16Array([ 0, 65535, 65535, 2, 65535, 65535, - 1, 2, 65535, + 0, 2, 65535, + 1, 2, 65535, ]), }; @@ expect(colorFn(0)).toBe("#999999"); expect(colorFn(1)).toBe("#00ff00"); - expect(colorFn(2)).toBe("#ff0000"); + expect(colorFn(2)).toBe("#00ff00"); + expect(colorFn(3)).toBe("#ff0000");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/datastore-color.multitext.spec.ts` around lines 32 - 61, The test for multitext packed colors misses the path where an empty/fallback entry appears before a real value; extend the "reads packed multitext colors using row stride" test by adding another row in the column.data that represents [0, 2, 65535] (i.e., fallback then real value then sentinel) and assert the produced colorFn for that row index returns the real value color (use DataStore.prototype.getColorFunction.call(store, "__gates__", {}) to obtain colorFn and verify the returned color matches the expected "#00ff00" instead of the fallback "#999999"), ensuring the test exercises the empty-item-skip branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/datastore/DataStore.js`:
- Around line 1514-1517: The loop in DataStore.js that iterates "for (let offset
= 0; offset < capacity; offset++)" currently breaks when valueIndex == null ||
valueIndex === 65535, causing it to stop scanning packed rows prematurely;
change the logic in that loop so it only treats null/undefined (valueIndex ==
null) as a break/stop condition but treats the 65535 sentinel as "skip this
slot" and continues scanning (i.e., do not break on valueIndex === 65535),
matching the behavior in valueReplacementUtil.ts and the handling at line ~503;
ensure you still return the first non-sentinel semantic value found within the
packed slice or fall back appropriately if none exist.
---
Nitpick comments:
In `@src/tests/datastore-color.multitext.spec.ts`:
- Around line 32-61: The test for multitext packed colors misses the path where
an empty/fallback entry appears before a real value; extend the "reads packed
multitext colors using row stride" test by adding another row in the column.data
that represents [0, 2, 65535] (i.e., fallback then real value then sentinel) and
assert the produced colorFn for that row index returns the real value color (use
DataStore.prototype.getColorFunction.call(store, "__gates__", {}) to obtain
colorFn and verify the returned color matches the expected "#00ff00" instead of
the fallback "#999999"), ensuring the test exercises the empty-item-skip branch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 18d71f2b-420f-412d-a246-5d36d394abf9
📒 Files selected for processing (2)
src/datastore/DataStore.jssrc/tests/datastore-color.multitext.spec.ts
| for (let offset = 0; offset < capacity; offset++) { | ||
| const valueIndex = data[start + offset]; | ||
| if (valueIndex == null || valueIndex === 65535) { | ||
| break; |
There was a problem hiding this comment.
Keep scanning past 65535 sentinels inside packed rows.
Line 1516 currently breaks on the first empty slot. That disagrees with Line 503 and src/react/utils/valueReplacementUtil.ts:100-110, which both skip 65535 values anywhere in the packed slice. A row like [0, 65535, 2] would now fall back too early instead of returning the later semantic value.
Possible fix
- if (valueIndex == null || valueIndex === 65535) {
- break;
+ if (valueIndex == null) {
+ break;
+ }
+ if (valueIndex === 65535) {
+ continue;
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| for (let offset = 0; offset < capacity; offset++) { | |
| const valueIndex = data[start + offset]; | |
| if (valueIndex == null || valueIndex === 65535) { | |
| break; | |
| for (let offset = 0; offset < capacity; offset++) { | |
| const valueIndex = data[start + offset]; | |
| if (valueIndex == null) { | |
| break; | |
| } | |
| if (valueIndex === 65535) { | |
| continue; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/datastore/DataStore.js` around lines 1514 - 1517, The loop in
DataStore.js that iterates "for (let offset = 0; offset < capacity; offset++)"
currently breaks when valueIndex == null || valueIndex === 65535, causing it to
stop scanning packed rows prematurely; change the logic in that loop so it only
treats null/undefined (valueIndex == null) as a break/stop condition but treats
the 65535 sentinel as "skip this slot" and continues scanning (i.e., do not
break on valueIndex === 65535), matching the behavior in valueReplacementUtil.ts
and the handling at line ~503; ensure you still return the first non-sentinel
semantic value found within the packed slice or fall back appropriately if none
exist.
Summary
DataStore.getColorFunctionto resolve packedmultitextvalues by row stride instead of treating the buffer as one value per rowmultitextcolumnsmultitextcolor lookupsTesting
Summary by CodeRabbit
Bug Fixes
Tests