From 78f9c0fd4144ac6b0fc671bbbad40176c98f3ff8 Mon Sep 17 00:00:00 2001
From: Adela Almasan <88068998+adela-almasan@users.noreply.github.com>
Date: Mon, 1 Jul 2024 13:01:19 -0600
Subject: [PATCH] Table: Filter hidden fields for text wrapping (#89800)

---
 packages/grafana-ui/src/components/Table/RowsList.tsx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/packages/grafana-ui/src/components/Table/RowsList.tsx b/packages/grafana-ui/src/components/Table/RowsList.tsx
index 29ee0701a7a..c5bb9ae817a 100644
--- a/packages/grafana-ui/src/components/Table/RowsList.tsx
+++ b/packages/grafana-ui/src/components/Table/RowsList.tsx
@@ -286,7 +286,8 @@ export const RowsList = (props: RowsListProps) => {
 
       // If there's a text wrapping field we set the height of it here
       if (textWrapField) {
-        const seriesIndex = data.fields.findIndex((field) => field.name === textWrapField.name);
+        const visibleFields = data.fields.filter((field) => !Boolean(field.config.custom?.hidden));
+        const seriesIndex = visibleFields.findIndex((field) => field.name === textWrapField.name);
         const pxLineHeight = theme.typography.body.lineHeight * theme.typography.fontSize;
         const bbox = guessTextBoundingBox(
           textWrapField.values[index],
@@ -369,7 +370,8 @@ export const RowsList = (props: RowsListProps) => {
     }
 
     if (textWrapField) {
-      const seriesIndex = data.fields.findIndex((field) => field.name === textWrapField.name);
+      const visibleFields = data.fields.filter((field) => !Boolean(field.config.custom?.hidden));
+      const seriesIndex = visibleFields.findIndex((field) => field.name === textWrapField.name);
       const pxLineHeight = theme.typography.fontSize * theme.typography.body.lineHeight;
       return guessTextBoundingBox(
         textWrapField.values[index],