-
Notifications
You must be signed in to change notification settings - Fork 664
GridCore: add ai assistant toolbar item #33189
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
Open
anna-shakhova
wants to merge
4
commits into
DevExpress:26_1
Choose a base branch
from
anna-shakhova:26_1__ai_assistant_toolbar_item
base: 26_1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1ae5f62
GridCore: add ai assistant toolbar item
anna-shakhova 94a38e7
GridCore: remove m_ prefix from new modules file names
anna-shakhova 45124c6
set ai assistant button to active state when popup visible, refactor
anna-shakhova 81ee689
copilot review fix
anna-shakhova 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
12 changes: 10 additions & 2 deletions
12
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
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
146 changes: 146 additions & 0 deletions
146
...l/grids/grid_core/ai_assistant/__tests__/ai_assistant_view_controller.integration.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,146 @@ | ||
| import { | ||
| afterEach, | ||
| beforeEach, | ||
| describe, | ||
| expect, | ||
| it, | ||
| jest, | ||
| } from '@jest/globals'; | ||
| import type { Properties as DataGridProperties } from '@js/ui/data_grid'; | ||
|
|
||
| import { | ||
| afterTest, | ||
| beforeTest, | ||
| createDataGrid as commonCreateDataGrid, | ||
| type DataGridInstance, | ||
| } from '../../__tests__/__mock__/helpers/utils'; | ||
|
|
||
| // TODO remove when types added to public dts | ||
| interface AIAssistantDataGridProperties extends DataGridProperties { | ||
| aiAssistant?: { | ||
| enabled?: boolean; | ||
| title?: string; | ||
| }; | ||
| } | ||
|
|
||
| // TODO remove when types added to public dts | ||
| const createDataGrid = ( | ||
| options: AIAssistantDataGridProperties = {}, | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| ): ReturnType<typeof commonCreateDataGrid> => commonCreateDataGrid(options as any); | ||
|
|
||
| const AI_ASSISTANT_BUTTON_SELECTOR = '.dx-datagrid-ai-assistant-button'; | ||
| const HIDDEN_CLASS = 'dx-hidden'; | ||
|
|
||
| const getAiAssistantButton = ( | ||
| instance: DataGridInstance, | ||
| ): Element | null => instance | ||
| .element() | ||
| .querySelector(AI_ASSISTANT_BUTTON_SELECTOR); | ||
|
|
||
| const isAiAssistantButtonVisible = (instance: DataGridInstance): boolean => { | ||
| const button = getAiAssistantButton(instance); | ||
|
|
||
| if (!button) { | ||
| return false; | ||
| } | ||
|
|
||
| return !button.closest(`.${HIDDEN_CLASS}`); | ||
| }; | ||
|
|
||
| describe('AIAssistantViewController', () => { | ||
| beforeEach(beforeTest); | ||
| afterEach(afterTest); | ||
|
|
||
| describe('init', () => { | ||
| it('should register toolbar button when aiAssistant.enabled is true', async () => { | ||
| const { instance } = await createDataGrid({ | ||
| dataSource: [{ id: 1 }], | ||
| aiAssistant: { enabled: true, title: 'AI Assistant' }, | ||
| }); | ||
|
|
||
| const button = getAiAssistantButton(instance); | ||
|
|
||
| expect(button).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('should not register toolbar button when aiAssistant.enabled is false', async () => { | ||
| const { instance } = await createDataGrid({ | ||
| dataSource: [{ id: 1 }], | ||
| aiAssistant: { enabled: false }, | ||
| }); | ||
|
|
||
| const button = getAiAssistantButton(instance); | ||
|
|
||
| expect(button).toBeNull(); | ||
| }); | ||
|
|
||
| it('should not register toolbar button when aiAssistant is not set', async () => { | ||
| const { instance } = await createDataGrid({ | ||
| dataSource: [{ id: 1 }], | ||
| }); | ||
|
|
||
| const button = getAiAssistantButton(instance); | ||
|
|
||
| expect(button).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('optionChanged', () => { | ||
| it('should add toolbar button when aiAssistant.enabled changes to true', async () => { | ||
| const { instance } = await createDataGrid({ | ||
| dataSource: [{ id: 1 }], | ||
| aiAssistant: { enabled: false, title: 'AI Assistant' }, | ||
| }); | ||
|
|
||
| instance.option('aiAssistant.enabled', true); | ||
| jest.runAllTimers(); | ||
| await Promise.resolve(); | ||
| jest.runAllTimers(); | ||
|
|
||
| const button = getAiAssistantButton(instance); | ||
|
|
||
| expect(button).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('should hide ai assistant button when aiAssistant.enabled changes to false', async () => { | ||
| const { instance } = await createDataGrid({ | ||
| dataSource: [{ id: 1 }], | ||
| aiAssistant: { enabled: true, title: 'AI Assistant' }, | ||
| }); | ||
|
|
||
| expect(isAiAssistantButtonVisible(instance)).toBe(true); | ||
|
|
||
| instance.option('aiAssistant.enabled', false); | ||
| jest.runAllTimers(); | ||
| await Promise.resolve(); | ||
| jest.runAllTimers(); | ||
|
|
||
| expect(isAiAssistantButtonVisible(instance)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('toolbar button', () => { | ||
| it('should have aria-haspopup dialog attribute', async () => { | ||
| const { instance } = await createDataGrid({ | ||
| dataSource: [{ id: 1 }], | ||
| aiAssistant: { enabled: true, title: 'AI Assistant' }, | ||
| }); | ||
|
|
||
| const button = getAiAssistantButton(instance); | ||
|
|
||
| expect(button?.getAttribute('aria-haspopup')).toBe('dialog'); | ||
| }); | ||
|
|
||
| it('should have correct hint text from aiAssistant.title', async () => { | ||
| const { instance } = await createDataGrid({ | ||
| dataSource: [{ id: 1 }], | ||
| aiAssistant: { enabled: true, title: 'My Custom Title' }, | ||
| }); | ||
|
|
||
| const button = getAiAssistantButton(instance); | ||
|
|
||
| expect(button?.getAttribute('title')).toBe('My Custom Title'); | ||
| }); | ||
| }); | ||
| }); |
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.