import { BaseContext } from '../types'; import { IRowNode } from 'ag-grid-enterprise'; /** * Options for managing the Data Import function */ export interface DataImportOptions> { /** * Custom File Handlers to use for Data Import */ fileHandlers?: DataImportFileHandler[]; /** * Handles Importing Data using text */ textHandler?: (text: string) => T[] | Promise; /** * Function to validate the Imported Data */ validate?: (context: DataImportValidateContext) => DataImportValidationError[] | undefined; /** * Function to handle the Imported Data and apply it to the Grid. If not provided then the Data will be applied to the Grid automatically. */ handleImportedData?: (context: HandleImportedDataContext) => Promise; /** * Function to pre-process the data before it is imported * * @experimental It might change in a future version */ _preprocessRowData?: (context: PreprocessRowDataContext) => Record; /** * Function to get the Primary Key value for a data row (defaults to value of the primaryKey column) * * @experimental It might change in a future version */ _getPrimaryKeyValue?: (context: GetPrimaryKeyValueContext) => string | number; } /** * Context used when pre-processing Import Data */ export interface PreprocessRowDataContext> extends BaseContext { /** * Data which has been imported */ rowData: T; } /** * Context used when importing Data */ export interface HandleImportedDataContext> extends BaseContext { /** * Data which has been imported */ data: T[]; } /** * Files that can be handled by Data Import */ export interface DataImportFileHandler> { /** * Name of File Extension */ fileExtension?: string; /** * Async function which handles the import returning a Data Record */ handleFile: (file: File) => Promise; } /** * Defines a Validation Error */ export interface DataImportValidationError { /** * Column which contains the Error */ columnId: string; /** * The validatoin error text */ error: string; } /** * Context passed to the `validate` function */ export interface DataImportValidateContext> extends BaseContext { /** * Imported Row Data */ rowData: T; } /** * Context passed to the `getPrimaryKeyValue` function */ export interface GetPrimaryKeyValueContext> extends BaseContext { /** * Data being imported */ rowData: T; } /** * Resolution returned by the `handleImportedData` function */ export interface HandleImportedDataResolution { /** * Whether to emit the `DataImported` event */ emitDataImportedEvent: boolean; /** * Rows that were added */ addedRows: IRowNode[]; /** * Rows that were updated */ updatedRows: IRowNode[]; }