@grafana/ui
Version:
Grafana Components Library
1 lines • 6.17 kB
Source Map (JSON)
{"version":3,"file":"types.mjs","sources":["../../../../src/components/Table/types.ts"],"sourcesContent":["import { Property } from 'csstype';\nimport { FC } from 'react';\nimport { CellProps, Column, Row, TableState, UseExpandedRowProps } from 'react-table';\n\nimport {\n DataFrame,\n Field,\n KeyValue,\n SelectableValue,\n TimeRange,\n FieldConfigSource,\n ActionModel,\n InterpolateFunction,\n} from '@grafana/data';\nimport * as schema from '@grafana/schema';\n\nimport { TableCellInspectorMode } from './TableCellInspector';\nimport { TableStyles } from './TableRT/styles';\n\nexport {\n type FieldTextAlignment,\n TableCellBackgroundDisplayMode,\n TableCellDisplayMode,\n type TableAutoCellOptions,\n type TableSparklineCellOptions,\n type TableBarGaugeCellOptions,\n type TableColoredBackgroundCellOptions,\n type TableColorTextCellOptions,\n type TableImageCellOptions,\n type TableJsonViewCellOptions,\n} from '@grafana/schema';\n\nexport interface TableRow {\n [x: string]: any;\n}\n\nexport type InspectCell = { value: any; mode: TableCellInspectorMode };\n\nexport const FILTER_FOR_OPERATOR = '=';\nexport const FILTER_OUT_OPERATOR = '!=';\nexport type AdHocFilterOperator = typeof FILTER_FOR_OPERATOR | typeof FILTER_OUT_OPERATOR;\nexport type AdHocFilterItem = { key: string; value: string; operator: AdHocFilterOperator };\nexport type TableFilterActionCallback = (item: AdHocFilterItem) => void;\nexport type TableColumnResizeActionCallback = (fieldDisplayName: string, width: number) => void;\nexport type TableSortByActionCallback = (state: TableSortByFieldState[]) => void;\nexport type TableInspectCellCallback = (state: InspectCell) => void;\n\nexport interface TableSortByFieldState {\n displayName: string;\n desc?: boolean;\n}\n\nexport interface TableCellProps extends CellProps<any> {\n tableStyles: TableStyles;\n cellProps: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;\n field: Field;\n onCellFilterAdded?: TableFilterActionCallback;\n innerWidth: number;\n frame: DataFrame;\n actions?: ActionModel[]; // unused in NG\n setInspectCell?: TableInspectCellCallback;\n}\n\nexport type CellComponent = FC<TableCellProps>;\n\nexport type FooterItem = Array<KeyValue<string>> | string | undefined;\n\nexport type GrafanaTableColumn = Column & {\n field: Field;\n sortType: 'number' | 'basic' | 'alphanumeric-insensitive';\n filter: (rows: Row[], id: string, filterValues?: SelectableValue[]) => SelectableValue[];\n justifyContent: Property.JustifyContent;\n minWidth: number;\n};\n\nexport interface TableFooterCalc {\n show: boolean;\n reducer: string[]; // actually 1 value\n fields?: string[];\n enablePagination?: boolean;\n countRows?: boolean;\n}\n\nexport interface GrafanaTableState extends TableState {\n // We manually track this to know where to reset the row heights. This is needed because react-table removed the\n // collapsed IDs/indexes from the state.expanded map so when collapsing we would have to do a diff of current and\n // previous state.expanded to know what changed.\n lastExpandedOrCollapsedIndex?: number;\n}\n\nexport interface GrafanaTableRow extends Row, UseExpandedRowProps<{}> {}\n\nexport interface TableStateReducerProps {\n onColumnResize?: TableColumnResizeActionCallback;\n onSortByChange?: TableSortByActionCallback;\n data: DataFrame;\n}\n\n// export interface Props {\nexport interface TableRTProps {\n ariaLabel?: string;\n data: DataFrame;\n width: number;\n height: number;\n maxHeight?: number;\n /** Minimal column width specified in pixels */\n columnMinWidth?: number;\n noHeader?: boolean;\n showTypeIcons?: boolean;\n resizable?: boolean;\n initialSortBy?: TableSortByFieldState[];\n onColumnResize?: TableColumnResizeActionCallback;\n onSortByChange?: TableSortByActionCallback;\n onCellFilterAdded?: TableFilterActionCallback;\n footerOptions?: TableFooterCalc;\n footerValues?: FooterItem[];\n enablePagination?: boolean;\n cellHeight?: schema.TableCellHeight;\n /** @alpha Used by SparklineCell when provided */\n timeRange?: TimeRange;\n enableSharedCrosshair?: boolean;\n // The index of the field value that the table will initialize scrolled to\n initialRowIndex?: number;\n fieldConfig?: FieldConfigSource;\n getActions?: GetActionsFunction;\n replaceVariables?: InterpolateFunction;\n}\n\n/**\n * @alpha\n * Props that will be passed to the TableCustomCellOptions.cellComponent when rendered.\n */\nexport interface CustomCellRendererProps {\n field: Field;\n rowIndex: number;\n frame: DataFrame;\n // Would be great to have generic type for this but that would need having a generic DataFrame type where the field\n // types could be propagated here.\n value: unknown;\n}\n\n/**\n * @alpha\n * Can be used to define completely custom cell contents by providing a custom cellComponent.\n */\nexport interface TableCustomCellOptions {\n cellComponent: FC<CustomCellRendererProps>;\n type: schema.TableCellDisplayMode.Custom;\n}\n\n/**\n * @alpha\n * Props that will be passed to the TableCustomCellOptions.cellComponent when rendered.\n */\nexport interface CustomHeaderRendererProps {\n field: Field;\n defaultContent: React.ReactNode;\n}\n\n// As cue/schema cannot define function types (as main point of schema is to be serializable) we have to extend the\n// types here with the dynamic API. This means right now this is not usable as a table panel option for example.\nexport type TableCellOptions = schema.TableCellOptions | TableCustomCellOptions;\nexport type TableFieldOptions = Omit<schema.TableFieldOptions, 'cellOptions'> & {\n cellOptions: TableCellOptions;\n headerComponent?: React.ComponentType<CustomHeaderRendererProps>;\n};\n\n// Cell background and text colors\n// Can also be used for table rows\nexport interface CellColors {\n textColor?: string;\n bgColor?: string;\n bgHoverColor?: string;\n}\n\nexport type GetActionsFunction = (\n frame: DataFrame,\n field: Field,\n rowIndex: number,\n replaceVariables?: InterpolateFunction\n) => ActionModel[];\n"],"names":[],"mappings":";;;AAsCO,MAAM,mBAAA,GAAsB;AAC5B,MAAM,mBAAA,GAAsB;;;;"}