mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 06:12:49 +08:00
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:
@ -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]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user