diff --git a/packages/grafana-ui/src/components/Table/TableNG/Cells/TableCellNG.tsx b/packages/grafana-ui/src/components/Table/TableNG/Cells/TableCellNG.tsx index f9a91fa226c..f80642b1448 100644 --- a/packages/grafana-ui/src/components/Table/TableNG/Cells/TableCellNG.tsx +++ b/packages/grafana-ui/src/components/Table/TableNG/Cells/TableCellNG.tsx @@ -74,7 +74,10 @@ export function TableCellNG(props: TableCellNGProps) { const [divWidth, setDivWidth] = useState(0); const [isHovered, setIsHovered] = useState(false); - const actions = getActions ? getActions(frame, field, rowIdx) : []; + const actions = useMemo( + () => (getActions ? getActions(frame, field, rowIdx) : []), + [getActions, frame, field, rowIdx] + ); useLayoutEffect(() => { if (divWidthRef.current && divWidthRef.current.clientWidth !== 0) { @@ -83,60 +86,66 @@ export function TableCellNG(props: TableCellNGProps) { }, [divWidthRef.current]); // eslint-disable-line react-hooks/exhaustive-deps // Common props for all cells - const commonProps = { - value, - field, - rowIdx, - justifyContent, - }; + const commonProps = useMemo( + () => ({ + value, + field, + rowIdx, + justifyContent, + }), + [value, field, rowIdx, justifyContent] + ); // Get the correct cell type - let cell: ReactNode = null; - switch (cellType) { - case TableCellDisplayMode.Sparkline: - cell = ; - break; - case TableCellDisplayMode.Gauge: - case TableCellDisplayMode.BasicGauge: - case TableCellDisplayMode.GradientGauge: - case TableCellDisplayMode.LcdGauge: - cell = ; - break; - case TableCellDisplayMode.Image: - cell = ; - break; - case TableCellDisplayMode.JSONView: - cell = ; - break; - case TableCellDisplayMode.DataLinks: - cell = ; - break; - case TableCellDisplayMode.Actions: - cell = ; - break; - case TableCellDisplayMode.Custom: - const CustomCellComponent: React.ComponentType = cellOptions.cellComponent; - cell = ; - break; - case TableCellDisplayMode.Auto: - default: - // Handle auto cell type detection - if (field.type === FieldType.geo) { - cell = ; - } else if (field.type === FieldType.frame) { - const firstValue = field.values[0]; - if (isDataFrame(firstValue) && isTimeSeriesFrame(firstValue)) { - cell = ; - } else { - cell = ; - } - } else if (field.type === FieldType.other) { + const renderedCell = useMemo(() => { + let cell: ReactNode = null; + switch (cellType) { + case TableCellDisplayMode.Sparkline: + cell = ; + break; + case TableCellDisplayMode.Gauge: + case TableCellDisplayMode.BasicGauge: + case TableCellDisplayMode.GradientGauge: + case TableCellDisplayMode.LcdGauge: + cell = ; + break; + case TableCellDisplayMode.Image: + cell = ; + break; + case TableCellDisplayMode.JSONView: cell = ; - } else { - cell = ; - } - break; - } + break; + case TableCellDisplayMode.DataLinks: + cell = ; + break; + case TableCellDisplayMode.Actions: + cell = ; + break; + case TableCellDisplayMode.Custom: + const CustomCellComponent: React.ComponentType = cellOptions.cellComponent; + cell = ; + break; + case TableCellDisplayMode.Auto: + default: + // Handle auto cell type detection + if (field.type === FieldType.geo) { + cell = ; + } else if (field.type === FieldType.frame) { + const firstValue = field.values[0]; + if (isDataFrame(firstValue) && isTimeSeriesFrame(firstValue)) { + cell = ; + } else { + cell = ; + } + } else if (field.type === FieldType.other) { + cell = ; + } else { + cell = ; + } + break; + } + return cell; + }, [cellType, commonProps, theme, timeRange, divWidth, height, cellOptions, field, rowIdx, actions, value, frame]); const handleMouseEnter = () => { setIsHovered(true); @@ -182,7 +191,7 @@ export function TableCellNG(props: TableCellNGProps) { return ( - {cell} + {renderedCell} {isHovered && (cellInspect || showFilters) && ( {cellInspect && (