Skip to content

Grids: support compound keys in AI Column - #34520

Open
anna-shakhova wants to merge 8 commits into
DevExpress:mainfrom
anna-shakhova:ai_column_compound_keys_main
Open

Grids: support compound keys in AI Column#34520
anna-shakhova wants to merge 8 commits into
DevExpress:mainfrom
anna-shakhova:ai_column_compound_keys_main

Conversation

@anna-shakhova

Copy link
Copy Markdown
Contributor

No description provided.

@anna-shakhova anna-shakhova self-assigned this Jul 28, 2026
Copilot AI review requested due to automatic review settings July 28, 2026 12:27
@anna-shakhova
anna-shakhova requested a review from a team as a code owner July 28, 2026 12:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for isKeyMissingInData.
  • Split large integration tests into ai_column.cache.test.ts and ai_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.

Comment thread packages/devextreme/js/__internal/grids/grid_core/ai_column/utils.ts Outdated
@anna-shakhova anna-shakhova reopened this Jul 28, 2026
Copilot AI review requested due to automatic review settings July 28, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • getKeyHash may return an object for some keys (see its {} fallback), but AIColumnCacheController uses 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: getKeyHash can 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

  • getKeyHash can return an object (e.g., when JSON.stringify(key) === '{}'), but this method casts it to PropertyKey and 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;
  }

@anna-shakhova
anna-shakhova force-pushed the ai_column_compound_keys_main branch from f8835f2 to 6d3b157 Compare July 30, 2026 08:24
Copilot AI review requested due to automatic review settings July 30, 2026 08:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 allows undefined values. When compound keys are later hashed via getKeyHash (JSON.stringify), undefined properties are omitted (e.g. { id1: 1, id2: undefined }{"id1":1}), which can cause key-hash collisions and incorrect AI cache lookups. Consider treating undefined/null key-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)),
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants