-
Notifications
You must be signed in to change notification settings - Fork 21
981174: Add Grid with AI Assist view sample #27
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
Vignesh050801
wants to merge
8
commits into
master
Choose a base branch
from
EJ2-981174-smart-grid
base: master
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
8 commits
Select commit
Hold shift + click to select a range
4fb813f
981174: Add Grid with AI Assist view sample.
Vigneshwaran-SF4319 47cab84
891174: Add Grid with AI Assist view sample
Vigneshwaran-SF4319 516b398
981174: Add Grid with AI Assist view sample.
Vigneshwaran-SF4319 462a2cc
981174: Add Grid with AI Assist view sample
Vigneshwaran-SF4319 3815098
981174: Add Grid with AI Assist view sample
Vigneshwaran-SF4319 e17b5e5
981174: Add Grid with AI Assist view sample
Vigneshwaran-SF4319 ff6c49b
981174: Add Grid with AI Assist view sample
Vigneshwaran-SF4319 87ea2fd
981174: Add Grid with AI Assist view sample
Vigneshwaran-SF4319 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { getAzureChatAIRequest } from '../../../ai-models'; | ||
import {executeGridAction} from './GridAction'; | ||
|
||
|
||
function fetchAI(text: string | undefined, grid: any, dialog: any, assistView: any, columns: any) { | ||
let textArea = `Convert the following natural language query into a JSON object representing Syncfusion Query operations. | ||
|
||
Rules: | ||
- Output only the JSON object, no extra text. | ||
- Field names must be from: ${JSON.stringify(columns)}. | ||
- Sort direction must be either "Ascending" or "Descending". | ||
|
||
Action Handling: | ||
- Include only the actions explicitly mentioned in the query: filter, sort, page, group, clearFilter, clearSort, clearGroup. | ||
- Operator shold be (startswith, endswith, contains, doesnotstartwith, doesnotendwith, doesnotcontain, equal, notequal, greaterthan, greaterthanorequal, lessthan, lessthanorequal, isnull, isnotnull, isempty, isnotempty, between, in, notin) | ||
- If the query only involves filtering, include only the "filter" key. | ||
- If the query only involves sorting, include only the "sort" key. | ||
- If the query includes a clear action: | ||
- Use 'clearFilter: []' to clear **all filters**. | ||
- Use 'clearSort: []' to clear **all sorting**. | ||
- Use 'clearGroup: []' to clear **all grouping**. | ||
- If the query specifies clearing filters/sorting/grouping for specific fields, include those field names as string arrays: clearFilter: ["field1"], clearSort: ["field2"], clearGroup: ["field3"]. | ||
|
||
Supported Operations: | ||
- filter: array of objects with { field, operator, value (array for "in"/"notin", otherwise single value), ignoreCase } | ||
- sort: array of { field, direction } | ||
- page: object with { pageNumber, pageSize } | ||
- group: array of field names | ||
|
||
Additional Requirement: | ||
- Include a "message" field in the JSON object that explains the query action, referencing the original query text. | ||
|
||
Query: ${text}`; | ||
|
||
let aiOutput = getAzureChatAIRequest({ messages: [{ role: 'user', content: textArea }] }); | ||
aiOutput.then((result: any) => { | ||
if (!result) { | ||
return; | ||
} | ||
let jsonResult = result; | ||
if (result.indexOf("```json") !== -1) { | ||
jsonResult = result.split("```json")[1].split("```")[0].trim(); | ||
} | ||
let data; | ||
try { | ||
data = JSON.parse(jsonResult); | ||
executeGridAction(data, grid); | ||
} catch (error) { | ||
assistView.addPromptResponse({ prompt: error, response: error }); | ||
return; | ||
} | ||
assistView.addPromptResponse({ prompt: data.message, response: data }); | ||
dialog.hide(); | ||
}); | ||
} | ||
|
||
export {fetchAI}; |
67 changes: 67 additions & 0 deletions
67
react/src/ai-components/grid/assistive-grid/GridAction.tsx
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,67 @@ | ||
import { GridComponent } from '@syncfusion/ej2-react-grids'; | ||
interface Filter { | ||
field: string; | ||
operator: string; | ||
value: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use any here. use string | number | boolean | date |
||
} | ||
|
||
interface Sort { | ||
field: string; | ||
direction: 'Ascending' | 'Descending'; | ||
} | ||
|
||
interface Page { | ||
pageNumber: number; | ||
pageSize: number; | ||
} | ||
|
||
interface GridActionData { | ||
filter?: Filter[]; | ||
clearFilter?: string[]; | ||
sort?: Sort[]; | ||
clearSort?: string[]; | ||
page?: Page; | ||
group?: string[]; | ||
clearGroup?: string[]; | ||
} | ||
export const executeGridAction = (data: GridActionData, grid: GridComponent) => { | ||
if (data.filter && data.filter.length) { | ||
data.filter.forEach((filter: Filter) => { | ||
grid.filterByColumn(filter.field, filter.operator, filter.value); | ||
}) | ||
} | ||
if (data.clearFilter) { | ||
if (data.clearFilter.length === 0) { | ||
grid.clearFiltering(); | ||
} else { | ||
grid.clearFiltering(data.clearFilter); | ||
} | ||
} | ||
if (data.sort && data.sort.length) { | ||
data.sort.forEach((sort: Sort) => { | ||
grid.sortColumn(sort.field, sort.direction, true); | ||
}) | ||
} | ||
else if (data.clearSort) { | ||
grid.clearSorting(); | ||
} | ||
if (data.page && data.page.pageNumber && data.page.pageSize) { | ||
grid.goToPage(data.page.pageNumber); | ||
} | ||
if (data.group && data.group.length) { | ||
const groupColumns: string[] = [...(grid.groupSettings.columns ?? [])]; | ||
if (groupColumns.indexOf(data.group[0]) === -1) { | ||
grid.groupColumn(data.group[0]); | ||
} | ||
} | ||
if (data.clearGroup) { | ||
if (data.clearGroup.length === 0) { | ||
grid.clearGrouping(); | ||
} else { | ||
const groupColumns: string[] = [...(grid.groupSettings.columns ?? [])]; | ||
if (groupColumns.indexOf(data.clearGroup[0]) !== -1) { | ||
grid.ungroupColumn(data.clearGroup[0]); | ||
} | ||
} | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
react/src/ai-components/grid/assistive-grid/assistive-grid.css
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,131 @@ | ||
#ai-grid-aiassistview .response-header .e-assistview-icon:before { | ||
margin-right: 10px; | ||
} | ||
|
||
#ai-grid-aiassistview .responseItemContent { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
margin-left: 20px | ||
} | ||
|
||
#ai-grid-aiassistview .responseItemContent .response-header { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
#ai-grid-aiassistview .responseItemContent .assist-response-content { | ||
margin-left: 35px; | ||
} | ||
|
||
#ai-grid-aiassistview .responseItemContent .response-header .e-assistview-icon:before { | ||
margin-right: 10px; | ||
} | ||
|
||
#ai-grid-aiassistview .e-response-item-template .e-toolbar-items { | ||
margin-left: 35px; | ||
} | ||
|
||
#ai-grid-aiassistview.e-aiassistview .e-footer { | ||
width: 90%; | ||
} | ||
|
||
#ai-grid-aiassistview.e-aiassistview .e-output-container { | ||
width: 100%; | ||
} | ||
#ai-grid-aiassistview.e-aiassistview .e-content-container .e-content { | ||
overflow-y: auto; | ||
} | ||
#ai-grid-aiassistview .e-response-item-template .e-content-footer, | ||
.e-aiassistview .e-prompt-container { | ||
display: none; | ||
} | ||
|
||
#ai-grid-aiassistview.e-aiassistview .e-view-container { | ||
margin: 0; | ||
} | ||
|
||
#ai-grid .e-badge { | ||
padding: 6px; | ||
width: 70px; | ||
} | ||
|
||
#ai-grid .email { | ||
color: gray; | ||
} | ||
|
||
#ai-grid .product-items { | ||
display: flex; | ||
gap: 0.75rem; | ||
align-items: center; | ||
} | ||
#ai-grid .product-items p { | ||
margin: 0px; | ||
} | ||
|
||
|
||
#ai-assist-dialog .e-suggestions { | ||
max-width: 100%; | ||
padding: 0 0 10px 0; | ||
} | ||
|
||
#ai-assist-dialog .e-suggestion-header { | ||
font-weight: bold; | ||
margin-bottom: 8px; | ||
font-size: 14px; | ||
text-align: left; | ||
} | ||
|
||
#ai-assist-dialog .e-suggestion-list { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 4px; | ||
} | ||
|
||
#ai-assist-dialog .e-suggestion-list ul { | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 4px; | ||
width: 100%; | ||
} | ||
|
||
#ai-assist-dialog .e-suggestion-list li { | ||
display: inline-block; | ||
padding: 6px 10px; | ||
border-radius: 16px; | ||
font-size: 13px; | ||
cursor: pointer; | ||
white-space: normal; | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); | ||
margin: 5px 2px; | ||
} | ||
|
||
#ai-assist-dialog .e-suggestion-list li:hover { | ||
background: rgba(28, 27, 31, 0.05); | ||
} | ||
|
||
#dialog-target .e-dialog .e-footer-content { | ||
border-top: 1px solid rgb(209, 213, 219); | ||
} | ||
|
||
.fluent-dark #ai-assist-dialog .e-suggestion-list li, | ||
.fluent2-dark #ai-assist-dialog .e-suggestion-list li, | ||
.tailwind-dark #ai-assist-dialog .e-suggestion-list li, | ||
.material-dark #ai-assist-dialog .e-suggestion-list li, | ||
.bootstrap5\.3-dark #ai-assist-dialog .e-suggestion-list li, | ||
.tailwind3-dark #ai-assist-dialog .e-suggestion-list li, | ||
.tailwind33-dark #ai-assist-dialog .e-suggestion-list li, | ||
.fabric-dark #ai-assist-dialog .e-suggestion-list li, | ||
.bootstrap-dark #ai-assist-dialog .e-suggestion-list li, | ||
.bootstrap4-dark #ai-assist-dialog .e-suggestion-list li, | ||
.bootstrap5-dark #ai-assist-dialog .e-suggestion-list li, | ||
.highcontrast #ai-assist-dialog .e-suggestion-list li { | ||
box-shadow: 0 2px 4px rgb(228 228 228 / 15%); | ||
} | ||
|
||
#ai-grid.e-grid { | ||
margin: 20px; | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use value type as any. Provide proper type for all the variables.