Grids: support compound keys in AI Column - #34520
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends Grid AI Column support to compound (multi-field) row keys by normalizing row keys to a stable hash for caching/lookup and by updating key-field validation to handle array-based keyExpr. It also restructures Jest coverage by moving large “Cache” and “AI data” suites into dedicated test files and adding explicit compound-key scenarios.
Changes:
- Hash row keys (via
getKeyHash) when reading/writing AI Column cache entries, enabling compound key support. - Update key-field presence validation to work with
keyExpr: string[]and add unit tests forisKeyMissingInData. - Split large integration tests into
ai_column.cache.test.tsandai_column.ai_data.test.ts, adding compound-key test cases.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/devextreme/js/__internal/grids/grid_core/ai_column/utils.ts | Updates cached-data reduction to accept a key getter and changes key-missing validation for compound keys. |
| packages/devextreme/js/__internal/grids/grid_core/ai_column/utils.test.ts | Updates reduceDataCachedKeys tests and adds coverage for isKeyMissingInData (including compound keys). |
| packages/devextreme/js/__internal/grids/grid_core/ai_column/controllers/m_ai_column_integration_controller.ts | Uses getKeyHash for cache keying and updates public cache access methods to accept RowKey. |
| packages/devextreme/js/__internal/grids/grid_core/ai_column/controllers/m_ai_column_controller.ts | Propagates RowKey through store event handlers and AI cache invalidation. |
| packages/devextreme/js/__internal/grids/grid_core/ai_column/tests/ai_column.integration.test.ts | Removes the “Cache” and “AI data” sections now covered by separate test files. |
| packages/devextreme/js/__internal/grids/grid_core/ai_column/tests/ai_column.cache.test.ts | New test file covering cache behavior, including compound-key pagination and push updates. |
| packages/devextreme/js/__internal/grids/grid_core/ai_column/tests/ai_column.api_handlers.test.ts | Adds a regression test ensuring E1046 is raised when a compound-key subfield is removed by the request-creating handler. |
| packages/devextreme/js/__internal/grids/grid_core/ai_column/tests/ai_column.ai_data.test.ts | New test file covering AI data rendering/refresh behavior plus compound-key rendering. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
packages/devextreme/js/__internal/grids/grid_core/ai_column/controllers/m_ai_column_integration_controller.ts:193
getKeyHashmay return an object for some keys (see its{}fallback), butAIColumnCacheControlleruses a plain object map where object keys are coerced to "[object Object]". Normalize the key hash to a string before looking up cached values to avoid collisions and cache misses.
public getAIColumnText(columnName: string, key: RowKey): string | undefined {
return this.aiColumnCacheController.getCachedString(columnName, getKeyHash(key) as PropertyKey);
}
packages/devextreme/js/__internal/grids/grid_core/ai_column/controllers/m_ai_column_integration_controller.ts:201
- Same issue as in
getAIColumnText:getKeyHashcan return an object, but the cache is a plain object map. Normalize the key hash before clearing by key to ensure the same key format is used for both caching and invalidation.
public clearAIColumnByKey(columnName: string, key: RowKey): void {
this.aiColumnCacheController.clearCacheByKey(columnName, getKeyHash(key) as PropertyKey);
}
packages/devextreme/js/__internal/grids/grid_core/ai_column/controllers/m_ai_column_integration_controller.ts:81
getKeyHashcan return an object (e.g., whenJSON.stringify(key) === '{}'), but this method casts it toPropertyKeyand uses it as a record key later. That coerces to "[object Object]" and can cause cache key collisions / mismatches for edge-case compound keys. Normalize object hashes to a string before returning.
This issue also appears in the following locations of the same file:
- line 191
- line 199
private getRowKeyHash(item: UserData): PropertyKey {
return getKeyHash(this.dataController.keyOf(item)) as PropertyKey;
}
f8835f2 to
6d3b157
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
packages/devextreme/js/__internal/grids/grid_core/ai_column/utils.ts:48
- For compound keys, this validation only checks that each key field exists (
field in item) but allowsundefinedvalues. When compound keys are later hashed viagetKeyHash(JSON.stringify),undefinedproperties are omitted (e.g.{ id1: 1, id2: undefined }→{"id1":1}), which can cause key-hash collisions and incorrect AI cache lookups. Consider treatingundefined/nullkey-part values as “missing” for the array (compound) keyExpr case, similar to the function-keyExpr branch.
const keyFields = Array.isArray(keyField) ? keyField : [keyField];
return data.some(
(item) => keyFields.some((field) => !(field in item)),
);
No description provided.