UNPKG

@progress/kendo-react-grid

Version:

React Data Grid (Table) provides 100+ ready-to-use data grid features. KendoReact Grid package

151 lines (150 loc) 4.33 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2026 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { AxiosResponse, AxiosRequestConfig } from 'axios'; import { GridAIState } from '../utils/handleAIResponse.js'; import { GridHandle } from '../interfaces/index.js'; /** * Represents the request data structure for the Grid AI request. */ export interface GridAIRequestData { /** * The role or context for the AI request. */ role: string; /** * The array of column definitions with their field names. */ columns: Array<{ field: string; id?: string; values?: any[]; }>; /** * The headers object containing key-value pairs for the request. */ headers: Record<string, string>; /** * The prompt message sent to the AI assistant. */ promptMessage: string; /** * The request configuration options for the HTTP request. */ requestOptions: { url?: string; method?: string; withCredentials?: boolean; responseType?: string; cancelToken?: any; [key: string]: any; }; } /** * Options for the useGridAIRequest hook. */ export interface UseGridAIRequestOptions { /** * The URL to send the AI request to. */ requestUrl?: string; /** * Additional axios request options. */ requestOptions?: AxiosRequestConfig; /** * The role for the AI request. Defaults to 'user'. */ role?: string; /** * The columns to include in the request. */ columns?: Array<{ field: string; id?: string; values?: any[]; }>; /** * The current grid state. */ gridState?: GridAIState; /** * Reference to grid methods. */ gridRef?: Pick<GridHandle, 'getLeafDataItems' | 'getTotal' | 'exportAsPdf' | 'props'> | null; /** * Callback fired before the request is sent. */ onPromptRequest?: (request: GridAIRequestData, isRetry?: boolean) => void; /** * Callback fired when the response is received successfully. */ onResponseSuccess?: (response: AxiosResponse<any>, promptMessage?: string, isRetry?: boolean) => void; /** * Callback fired when the response returns an error. */ onResponseError?: (error: any) => void; /** * Callback fired when the grid state should be updated. */ onStateChange?: (newState: GridAIState) => void; /** * Callback fired when messages are received from AI. */ onMessages?: (messages: string[], promptMessage?: string, isRetry?: boolean) => void; /** * Callback fired when PDF export is requested. */ onExportPdf?: () => void; } /** * Return type for the useGridAIRequest hook. */ export interface UseGridAIRequestReturn { /** * Whether a request is currently loading. */ loading: boolean; /** * Whether a request is currently streaming. */ streaming: boolean; /** * Send a prompt request to the AI. */ sendRequest: (promptMessage: string, isRetry?: boolean) => void; /** * Cancel the current request. */ cancelRequest: () => void; } /** * A custom hook that encapsulates the AI request logic for the Grid. * This hook can be used by both GridToolbarAIAssistant and SmartBox components. * * @param options - Configuration options for the hook * @returns Object containing loading state and request methods * * @example * ```tsx * const { loading, streaming, sendRequest, cancelRequest } = useGridAIRequest({ * requestUrl: '/api/ai/grid', * columns: gridColumns, * gridState: currentState, * gridRef: gridRef.current, * onStateChange: (newState) => setGridState(newState), * onMessages: (messages) => console.log(messages) * }); * * // Send a request * sendRequest('Sort by price descending'); * * // Cancel if needed * cancelRequest(); * ``` */ export declare function useGridAIRequest(options: UseGridAIRequestOptions): UseGridAIRequestReturn;