Files
grafana/packages/grafana-ui/src/components/Table/TableCell.tsx
2023-07-17 11:20:33 +02:00

46 lines
1.1 KiB
TypeScript

import React from 'react';
import { Cell } from 'react-table';
import { TimeRange, DataFrame } from '@grafana/data';
import { TableStyles } from './styles';
import { GrafanaTableColumn, TableFilterActionCallback } from './types';
export interface Props {
cell: Cell;
tableStyles: TableStyles;
onCellFilterAdded?: TableFilterActionCallback;
columnIndex: number;
columnCount: number;
timeRange?: TimeRange;
userProps?: object;
frame: DataFrame;
}
export const TableCell = ({ cell, tableStyles, onCellFilterAdded, timeRange, userProps, frame }: Props) => {
const cellProps = cell.getCellProps();
const field = (cell.column as unknown as GrafanaTableColumn).field;
if (!field?.display) {
return null;
}
if (cellProps.style) {
cellProps.style.minWidth = cellProps.style.width;
cellProps.style.justifyContent = (cell.column as any).justifyContent;
}
let innerWidth = ((cell.column.width as number) ?? 24) - tableStyles.cellPadding * 2;
return cell.render('Cell', {
field,
tableStyles,
onCellFilterAdded,
cellProps,
innerWidth,
timeRange,
userProps,
frame,
}) as React.ReactElement;
};