TableNG: Extract links and actions tooltip into cell root renderer (#107667)

* TableNG: Extract links and actions tooltip into cell root renderer

* make TS happy

* fixes & tweaks

* lint

* skip datalinks and actions tooltip on those cell types

* add todo

* withTooltip lookup

* fix

* optional getActions

* fix

* kill cursor: 'context-menu'

* stop event propagation from TableCellActions

* update tests to move tooltip tests up to TableNG

* remove safety assertion

* add value back to DataLinksActionsTooltip

---------

Co-authored-by: Paul Marbach <paul.marbach@grafana.com>
This commit is contained in:
Leon Sorokin
2025-07-08 13:24:03 -05:00
committed by GitHub
parent 412415ab39
commit 68ee251c5c
18 changed files with 291 additions and 362 deletions

View File

@ -2,7 +2,7 @@ import { useState, useMemo, useEffect, useCallback, useRef, useLayoutEffect } fr
import { Column, DataGridProps, SortColumn } from 'react-data-grid';
import { varPreLine } from 'uwrap';
import { Field, fieldReducers, FieldType, formattedValueToString, reduceField } from '@grafana/data';
import { Field, fieldReducers, FieldType, formattedValueToString, LinkModel, reduceField } from '@grafana/data';
import { useTheme2 } from '../../../themes/ThemeContext';
import { TableCellDisplayMode, TableColumnResizeActionCallback } from '../types';
@ -17,6 +17,7 @@ import {
getColumnTypes,
GetMaxWrapCellOptions,
getMaxWrapCell,
getCellLinks,
} from './utils';
// Helper function to get displayed value
@ -597,3 +598,10 @@ export function useColumnResize(
return dataGridResizeHandler;
}
export function useSingleLink(field: Field, rowIdx: number): LinkModel | undefined {
const linksCount = field.config.links?.length ?? 0;
const actionsCount = field.config.actions?.length ?? 0;
const shouldShowLink = linksCount === 1 && actionsCount === 0;
return useMemo(() => (shouldShowLink ? (getCellLinks(field, rowIdx) ?? []) : [])[0], [field, shouldShowLink, rowIdx]);
}