/** * Types and interfaces for the Query Data Grid component. * These are tailored for query results which differ from entity data: * - Read-only (no CRUD operations) * - Client-side sorting only (query SQL defines ORDER BY) * - No smart filter (parameters only) * - Support for entity linking via SourceEntityID */ import { IMetadataProvider } from '@memberjunction/core'; import { MJQueryFieldEntity } from '@memberjunction/core-entities'; /** * Selection mode for the query grid * - 'none': No selection allowed * - 'single': Only one row can be selected at a time * - 'multiple': Multiple rows can be selected (click to toggle) * - 'checkbox': Checkbox column for selection */ export type QueryGridSelectionMode = 'none' | 'single' | 'multiple' | 'checkbox'; /** * Configuration for a query grid column * Derived from QueryFieldInfo metadata */ export interface QueryGridColumnConfig { /** Field name from query results */ field: string; /** Display title (defaults to field name) */ title: string; /** Description/tooltip for the column header */ description?: string; /** Column width in pixels */ width?: number; /** Minimum width for resizing */ minWidth?: number; /** Maximum width for resizing */ maxWidth?: number; /** Column is visible */ visible: boolean; /** Column is sortable (client-side) */ sortable: boolean; /** Column is resizable */ resizable: boolean; /** Column is reorderable */ reorderable: boolean; /** SQL base type for formatting */ sqlBaseType: string; /** SQL full type for display */ sqlFullType: string; /** Text alignment */ align?: 'left' | 'center' | 'right'; /** Order/sequence of this column */ order: number; /** Source entity ID if this column references an entity */ sourceEntityId?: string; /** Source entity name if this column references an entity */ sourceEntityName?: string; /** Source field name in the entity (e.g., 'ID' for primary key) */ sourceFieldName?: string; /** Whether this column contains linkable entity IDs */ isEntityLink: boolean; /** * The entity name to navigate to when clicking the link. * - For primary keys: this is the source entity itself * - For foreign keys: this is the related entity the FK points to */ targetEntityName?: string; /** * The entity ID to navigate to when clicking the link. */ targetEntityId?: string; /** * Whether this field is a primary key of the source entity */ isPrimaryKey?: boolean; /** * Whether this field is a foreign key to another entity */ isForeignKey?: boolean; /** * Icon class for the target entity (from EntityInfo.Icon) * Used to display the entity's icon in the column header */ targetEntityIcon?: string; /** Column pinning position */ pinned?: 'left' | 'right' | null; /** Flex grow factor for auto-sizing */ flex?: number; } /** * Sort state for a column (client-side sorting) */ export interface QueryGridSortState { /** Field name being sorted */ field: string; /** Sort direction */ direction: 'asc' | 'desc'; /** Index for multi-sort ordering */ index: number; } /** * Complete grid state for persistence to User Settings */ export interface QueryGridState { /** Column states */ columns: Array<{ field: string; width?: number; visible: boolean; order: number; pinned?: 'left' | 'right' | null; }>; /** Sort state (client-side) */ sort: QueryGridSortState[]; } /** * Parameter values for a query execution */ export interface QueryParameterValues { [parameterName: string]: string | number | boolean | Date | string[] | null; } /** * Header style preset options */ export type QueryGridHeaderStyle = 'flat' | 'elevated' | 'gradient' | 'bold'; /** * Configuration for query grid visual appearance */ export interface QueryGridVisualConfig { /** Header style preset */ headerStyle?: QueryGridHeaderStyle; /** Custom header background color */ headerBackground?: string; /** Custom header text color */ headerTextColor?: string; /** Show bottom shadow/border on header */ headerShadow?: boolean; /** Enable alternating row colors (zebra striping) */ alternateRows?: boolean; /** Contrast level for alternating rows */ alternateRowContrast?: 'subtle' | 'medium' | 'strong'; /** Enable smooth hover transitions */ hoverTransitions?: boolean; /** Right-align numeric columns automatically */ rightAlignNumbers?: boolean; /** Format dates with a friendly format */ friendlyDates?: boolean; /** Render email cells as clickable mailto links */ clickableEmails?: boolean; /** Render boolean cells as checkmark/x icons */ booleanIcons?: boolean; /** Render URL cells as clickable links */ clickableUrls?: boolean; /** Selection indicator color */ selectionIndicatorColor?: string; /** Selection indicator width */ selectionIndicatorWidth?: number; /** Selection background color */ selectionBackground?: string; /** Checkbox style */ checkboxStyle?: 'default' | 'rounded' | 'filled'; /** Checkbox accent color */ checkboxColor?: string; /** Show skeleton loading rows */ skeletonLoading?: boolean; /** Number of skeleton rows */ skeletonRowCount?: number; /** Border radius for container */ borderRadius?: number; /** Cell padding preset */ cellPadding?: 'compact' | 'normal' | 'comfortable'; /** Primary accent color */ accentColor?: string; } /** * Default visual configuration for query grid */ export declare const DEFAULT_QUERY_VISUAL_CONFIG: Required; /** * Export options for query results */ export interface QueryExportOptions { /** Export only visible columns */ visibleColumnsOnly?: boolean; /** Export only selected rows */ selectedRowsOnly?: boolean; /** Include headers */ includeHeaders?: boolean; /** Custom column mapping */ columnMapping?: Record; } /** * Event fired when a row is clicked */ export interface QueryRowClickEvent { /** The row data */ rowData: Record; /** Row index */ rowIndex: number; /** Column that was clicked */ column?: QueryGridColumnConfig; /** Cell value */ cellValue?: unknown; /** Original mouse event */ mouseEvent: MouseEvent; } /** * Event fired when an entity link is clicked */ export interface QueryEntityLinkClickEvent { /** Entity name */ entityName: string; /** Record ID (primary key value) */ recordId: string; /** The column config (null if clicked from row detail panel) */ column: QueryGridColumnConfig | null; /** The row data */ rowData: Record; } /** * Event fired when grid state changes */ export interface QueryGridStateChangedEvent { /** The new grid state */ state: QueryGridState; /** What changed */ changeType: 'column-resize' | 'column-move' | 'column-visibility' | 'sort'; } /** * Event fired when selection changes */ export interface QuerySelectionChangedEvent { /** Selected row indices */ selectedIndices: number[]; /** Selected row data */ selectedRows: Record[]; } /** * Result of resolving the target entity for navigation */ export interface TargetEntityInfo { targetEntityName?: string; targetEntityId?: string; targetEntityIcon?: string; isPrimaryKey: boolean; isForeignKey: boolean; } /** * Determines the target entity for navigation based on source entity field metadata. * - If the source field is a primary key, target is the source entity itself * - If the source field is a foreign key, target is the related entity * Also retrieves the target entity's icon for display in column headers. */ export declare function resolveTargetEntity(sourceEntityName: string | undefined, sourceFieldName: string | undefined, md: IMetadataProvider): TargetEntityInfo; /** * Builds column configs from QueryFieldInfo metadata */ export declare function buildColumnsFromQueryFields(fields: MJQueryFieldEntity[], provider?: IMetadataProvider): QueryGridColumnConfig[]; /** * Gets the User Settings key for query grid state */ export declare function getQueryGridStateKey(queryId: string): string; /** * Gets the User Settings key for query parameters */ export declare function getQueryParamsKey(queryId: string): string; /** * Infers column configuration from actual data when query has no field metadata. * Examines the first row to determine column names and types. */ export declare function buildColumnsFromData(data: Record[]): QueryGridColumnConfig[]; //# sourceMappingURL=query-grid-types.d.ts.map