-
Notifications
You must be signed in to change notification settings - Fork 664
DataGrid/TreeList - AI Assistant: Create skeletons for classes and register new modules #33121
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
Merged
Alyar666
merged 8 commits into
DevExpress:26_1
from
Alyar666:AI_Assistant_create_classes_26_1
Apr 2, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f016eae
feat: add AIChat class with Popup and Chat integration
32d3288
feat: add AIAssistantView and AIAssistantViewController with grid reg…
e3a3bad
test: add unit tests for AIChat, AIAssistantView, and AIAssistantView…
e7d00da
Fix themebuilder tests
5ed6170
Fix copilot comments
f4437d0
feat: add aiAssistant visibility to AIAssistantView
33a10f9
fix: use aiAssistant enabled option in AIAssistantView
122434a
Fix jest tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
13 changes: 13 additions & 0 deletions
13
packages/devextreme/js/__internal/grids/data_grid/module_not_extended/ai_assistant.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { AIAssistantView } from '@ts/grids/grid_core/ai_assistant/m_ai_assistant_view'; | ||
| import { AIAssistantViewController } from '@ts/grids/grid_core/ai_assistant/m_ai_assistant_view_controller'; | ||
|
|
||
| import gridCore from '../m_core'; | ||
|
|
||
| gridCore.registerModule('aiAssistant', { | ||
| controllers: { | ||
| aiAssistant: AIAssistantViewController, | ||
| }, | ||
| views: { | ||
| aiAssistantView: AIAssistantView, | ||
| }, | ||
| }); |
196 changes: 196 additions & 0 deletions
196
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/m_ai_assistant_view.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| import { | ||
| afterEach, | ||
| beforeEach, | ||
| describe, | ||
| expect, | ||
| it, | ||
| jest, | ||
| } from '@jest/globals'; | ||
| import fx from '@js/common/core/animation/fx'; | ||
| import type { dxElementWrapper } from '@js/core/renderer'; | ||
| import $ from '@js/core/renderer'; | ||
| import wrapInstanceWithMocks from '@ts/grids/grid_core/__tests__/__mock__/helpers/wrapInstance'; | ||
|
|
||
| import { AIChat } from '../ai_chat/ai_chat'; | ||
| import { AIAssistantView } from './m_ai_assistant_view'; | ||
|
|
||
| jest.mock('../ai_chat/ai_chat', (): any => { | ||
| const original = jest.requireActual<any>('../ai_chat/ai_chat'); | ||
|
|
||
| return { | ||
| ...original, | ||
| AIChat: jest.fn((...args: any[]) => { | ||
| const instance: AIChat = new original.AIChat(...args); | ||
| return wrapInstanceWithMocks(instance); | ||
| }), | ||
| }; | ||
| }); | ||
|
|
||
| const createComponentMock = jest.fn(( | ||
| el: dxElementWrapper, | ||
| Widget: any, | ||
| options: any, | ||
| ): any => new Widget(el, options)); | ||
|
|
||
| const createAIAssistantView = ({ | ||
| initialEnabled = true, | ||
| render = true, | ||
| }: { | ||
| initialEnabled?: boolean; | ||
| render?: boolean; | ||
| } = {}): { | ||
| $container: dxElementWrapper; | ||
| aiAssistantView: AIAssistantView; | ||
| optionMock: jest.Mock<(name: string) => boolean | undefined>; | ||
| setEnabled: (value: boolean) => void; | ||
| } => { | ||
| const $container = $('<div>').appendTo(document.body); | ||
| let isEnabled = initialEnabled; | ||
| const optionMock = jest.fn((name: string): boolean | undefined => { | ||
| if (name === 'aiAssistant.enabled') { | ||
| return isEnabled; | ||
| } | ||
|
|
||
| return undefined; | ||
| }); | ||
| const mockComponent = { | ||
| element: (): any => $container.get(0), | ||
| _createComponent: createComponentMock, | ||
| _controllers: {}, | ||
| option: optionMock, | ||
| }; | ||
|
|
||
| const aiAssistantView = new AIAssistantView(mockComponent); | ||
| if (render) { | ||
| aiAssistantView.render($container); | ||
| } | ||
|
|
||
| return { | ||
| $container, | ||
| aiAssistantView, | ||
| optionMock, | ||
| setEnabled: (value: boolean): void => { | ||
| isEnabled = value; | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| const beforeTest = (): void => { | ||
| fx.off = true; | ||
| jest.useFakeTimers(); | ||
| jest.clearAllMocks(); | ||
| }; | ||
|
|
||
| const afterTest = (): void => { | ||
| document.body.innerHTML = ''; | ||
| fx.off = false; | ||
| jest.useRealTimers(); | ||
| }; | ||
|
|
||
| describe('AIAssistantView', () => { | ||
| beforeEach(beforeTest); | ||
| afterEach(afterTest); | ||
|
|
||
| describe('isVisible', () => { | ||
| it('should return aiAssistant.enabled option value', () => { | ||
| const { aiAssistantView, optionMock, setEnabled } = createAIAssistantView({ render: false }); | ||
|
|
||
| expect(aiAssistantView.isVisible()).toBe(true); | ||
|
|
||
| setEnabled(false); | ||
|
|
||
| expect(aiAssistantView.isVisible()).toBe(false); | ||
| expect(optionMock).toHaveBeenNthCalledWith(1, 'aiAssistant.enabled'); | ||
| expect(optionMock).toHaveBeenNthCalledWith(2, 'aiAssistant.enabled'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('initialization', () => { | ||
| it('should create AIChat instance on first render', () => { | ||
| createAIAssistantView(); | ||
|
|
||
| expect(AIChat).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should pass container and createComponent to AIChat', () => { | ||
| const { aiAssistantView } = createAIAssistantView(); | ||
|
|
||
| expect(AIChat).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| container: aiAssistantView.element(), | ||
| createComponent: expect.any(Function), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('should not create a new AIChat instance on subsequent renders', () => { | ||
| const { $container, aiAssistantView } = createAIAssistantView(); | ||
|
|
||
| aiAssistantView.render($container); | ||
|
|
||
| expect(AIChat).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should not create AIChat instance when aiAssistant is disabled', () => { | ||
| const { aiAssistantView } = createAIAssistantView({ initialEnabled: false }); | ||
|
|
||
| expect(AIChat).not.toHaveBeenCalled(); | ||
| expect(aiAssistantView.element().hasClass('dx-hidden')).toBe(true); | ||
| }); | ||
|
|
||
| it('should create AIChat instance when aiAssistant becomes enabled', () => { | ||
| const { $container, aiAssistantView, setEnabled } = createAIAssistantView({ | ||
| initialEnabled: false, | ||
| }); | ||
|
|
||
| setEnabled(true); | ||
| aiAssistantView.render($container); | ||
|
|
||
| expect(AIChat).toHaveBeenCalledTimes(1); | ||
| expect(aiAssistantView.element().hasClass('dx-hidden')).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('show', () => { | ||
| it('should delegate to AIChat show method', async () => { | ||
| const { aiAssistantView } = createAIAssistantView(); | ||
|
|
||
| await aiAssistantView.show(); | ||
|
|
||
| const aiChatInstance = (AIChat as jest.Mock) | ||
| .mock.results[0].value as { show: jest.Mock; hide: jest.Mock }; | ||
|
|
||
| expect(aiChatInstance.show).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('hide', () => { | ||
| it('should delegate to AIChat hide method', async () => { | ||
| const { aiAssistantView } = createAIAssistantView(); | ||
|
|
||
| await aiAssistantView.hide(); | ||
|
|
||
| const aiChatInstance = (AIChat as jest.Mock) | ||
| .mock.results[0].value as { show: jest.Mock; hide: jest.Mock }; | ||
|
|
||
| expect(aiChatInstance.hide).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('show when not initialized', () => { | ||
| it('should return resolved false promise when aiChatInstance is not created', () => { | ||
| const { aiAssistantView } = createAIAssistantView({ render: false }); | ||
|
|
||
| return expect(aiAssistantView.show()).resolves.toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('hide when not initialized', () => { | ||
| it('should return resolved false promise when aiChatInstance is not created', () => { | ||
| const { aiAssistantView } = createAIAssistantView({ render: false }); | ||
|
|
||
| return expect(aiAssistantView.hide()).resolves.toBe(false); | ||
| }); | ||
| }); | ||
| }); |
34 changes: 34 additions & 0 deletions
34
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/m_ai_assistant_view.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { AIChat } from '../ai_chat/ai_chat'; | ||
| import type { AIChatOptions } from '../ai_chat/types'; | ||
| import { View } from '../m_modules'; | ||
|
|
||
| export class AIAssistantView extends View { | ||
| private aiChatInstance!: AIChat; | ||
Alyar666 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private getAIChatConfig(): AIChatOptions { | ||
| return { | ||
| container: this.element(), | ||
| createComponent: this._createComponent.bind(this), | ||
| }; | ||
| } | ||
|
|
||
| protected _renderCore(): void { | ||
| const config = this.getAIChatConfig(); | ||
|
|
||
| if (!this.aiChatInstance) { | ||
| this.aiChatInstance = new AIChat(config); | ||
| } | ||
| } | ||
|
|
||
| public isVisible(): boolean { | ||
| return this.option('aiAssistant.enabled'); | ||
| } | ||
|
|
||
| public show(): Promise<boolean> { | ||
| return this.aiChatInstance?.show() ?? Promise.resolve(false); | ||
| } | ||
|
|
||
| public hide(): Promise<boolean> { | ||
| return this.aiChatInstance?.hide() ?? Promise.resolve(false); | ||
| } | ||
| } | ||
79 changes: 79 additions & 0 deletions
79
...extreme/js/__internal/grids/grid_core/ai_assistant/m_ai_assistant_view_controller.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { | ||
| afterEach, | ||
| beforeEach, | ||
| describe, | ||
| expect, | ||
| it, | ||
| jest, | ||
| } from '@jest/globals'; | ||
|
|
||
| import { AIAssistantViewController } from './m_ai_assistant_view_controller'; | ||
|
|
||
| interface MockAIAssistantView { | ||
| show: jest.Mock<() => Promise<boolean>>; | ||
| hide: jest.Mock<() => Promise<boolean>>; | ||
| } | ||
|
|
||
| const createMockAIAssistantView = (): MockAIAssistantView => ({ | ||
| show: jest.fn<() => Promise<boolean>>().mockResolvedValue(true), | ||
| hide: jest.fn<() => Promise<boolean>>().mockResolvedValue(true), | ||
| }); | ||
|
|
||
| const createAIAssistantViewController = (): { | ||
| controller: AIAssistantViewController; | ||
| mockView: ReturnType<typeof createMockAIAssistantView>; | ||
| } => { | ||
| const mockView = createMockAIAssistantView(); | ||
| const mockComponent = { | ||
| _views: { | ||
| aiAssistantView: mockView, | ||
| }, | ||
| _controllers: {}, | ||
| }; | ||
|
|
||
| const controller = new AIAssistantViewController(mockComponent); | ||
| controller.init(); | ||
|
|
||
| return { controller, mockView }; | ||
| }; | ||
|
|
||
| const beforeTest = (): void => { | ||
| jest.clearAllMocks(); | ||
| }; | ||
|
|
||
| describe('AIAssistantViewController', () => { | ||
| beforeEach(beforeTest); | ||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('init', () => { | ||
| it('should get aiAssistantView reference', () => { | ||
| const { controller } = createAIAssistantViewController(); | ||
|
|
||
| expect(controller).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('show', () => { | ||
| it('should delegate to aiAssistantView show method', async () => { | ||
| const { controller, mockView } = createAIAssistantViewController(); | ||
|
|
||
| const result = await controller.show(); | ||
|
|
||
| expect(mockView.show).toHaveBeenCalledTimes(1); | ||
| expect(result).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('hide', () => { | ||
| it('should delegate to aiAssistantView hide method', async () => { | ||
| const { controller, mockView } = createAIAssistantViewController(); | ||
|
|
||
| const result = await controller.hide(); | ||
|
|
||
| expect(mockView.hide).toHaveBeenCalledTimes(1); | ||
| expect(result).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
18 changes: 18 additions & 0 deletions
18
...s/devextreme/js/__internal/grids/grid_core/ai_assistant/m_ai_assistant_view_controller.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { ViewController } from '../m_modules'; | ||
| import type { AIAssistantView } from './m_ai_assistant_view'; | ||
|
|
||
| export class AIAssistantViewController extends ViewController { | ||
| private aiAssistantView!: AIAssistantView; | ||
|
|
||
| public init(): void { | ||
| this.aiAssistantView = this.getView('aiAssistantView'); | ||
| } | ||
|
|
||
| public show(): Promise<boolean> { | ||
| return this.aiAssistantView.show(); | ||
| } | ||
|
|
||
| public hide(): Promise<boolean> { | ||
| return this.aiAssistantView.hide(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.