The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/packages/grafana-ui/src/components/Table/TableCell.tsx

45 lines
1.2 KiB

import React, { FC } from 'react';
import { Cell } from 'react-table';
import { TableStyles } from './styles';
import { GrafanaTableColumn, TableFilterActionCallback } from './types';
export interface Props {
cell: Cell;
tableStyles: TableStyles;
onCellFilterAdded?: TableFilterActionCallback;
columnIndex: number;
columnCount: number;
userProps?: object;
}
export const TableCell: FC<Props> = ({ cell, tableStyles, onCellFilterAdded, columnIndex, columnCount, userProps }) => {
const cellProps = cell.getCellProps();
const field = (cell.column as any 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;
// last child sometimes have extra padding if there is a non overlay scrollbar
if (columnIndex === columnCount - 1) {
innerWidth -= tableStyles.lastChildExtraPadding;
}
return cell.render('Cell', {
field,
tableStyles,
onCellFilterAdded,
cellProps,
innerWidth,
userProps,
}) as React.ReactElement;
};