diff --git a/packages/grafana-ui/src/components/Table/BarGaugeCell.tsx b/packages/grafana-ui/src/components/Table/BarGaugeCell.tsx index d008fc8fe27..1d68b923893 100644 --- a/packages/grafana-ui/src/components/Table/BarGaugeCell.tsx +++ b/packages/grafana-ui/src/components/Table/BarGaugeCell.tsx @@ -1,7 +1,9 @@ import React, { FC } from 'react'; -import { ThresholdsConfig, ThresholdsMode, VizOrientation, getFieldConfigWithMinMax } from '@grafana/data'; +import { ThresholdsConfig, ThresholdsMode, VizOrientation, getFieldConfigWithMinMax, LinkModel } from '@grafana/data'; import { BarGauge, BarGaugeDisplayMode } from '../BarGauge/BarGauge'; import { TableCellProps, TableCellDisplayMode } from './types'; +import { DataLinksContextMenu, DataLinksContextMenuApi } from '../DataLinks/DataLinksContextMenu'; +import { isFunction } from 'lodash'; const defaultScale: ThresholdsConfig = { mode: ThresholdsMode.Absolute, @@ -18,7 +20,7 @@ const defaultScale: ThresholdsConfig = { }; export const BarGaugeCell: FC = (props) => { - const { field, innerWidth, tableStyles, cell, cellProps } = props; + const { field, innerWidth, tableStyles, cell, cellProps, row } = props; let config = getFieldConfigWithMinMax(field, false); if (!config.thresholds) { @@ -37,8 +39,20 @@ export const BarGaugeCell: FC = (props) => { barGaugeMode = BarGaugeDisplayMode.Basic; } - return ( -
+ const getLinks = () => { + if (!isFunction(field.getLinks)) { + return [] as LinkModel[]; + } + + return field.getLinks({ valueRowIndex: row.index }); + }; + + const hasLinks = !!getLinks().length; + + const renderComponent = (menuProps: DataLinksContextMenuApi) => { + const { openMenu, targetClassName } = menuProps; + + return ( = (props) => { value={displayValue} orientation={VizOrientation.Horizontal} theme={tableStyles.theme} + onClick={openMenu} + className={targetClassName} itemSpacing={1} lcdCellWidth={8} displayMode={barGaugeMode} /> + ); + }; + + return ( +
+ {hasLinks && ( + + {(api) => renderComponent(api)} + + )} + {!hasLinks && ( + + )}
); }; diff --git a/packages/grafana-ui/src/components/Table/JSONViewCell.tsx b/packages/grafana-ui/src/components/Table/JSONViewCell.tsx index 3f118d24dc7..7cc76d7a53b 100644 --- a/packages/grafana-ui/src/components/Table/JSONViewCell.tsx +++ b/packages/grafana-ui/src/components/Table/JSONViewCell.tsx @@ -6,9 +6,10 @@ import { JSONFormatter } from '../JSONFormatter/JSONFormatter'; import { useStyles2 } from '../../themes'; import { TableCellProps } from './types'; import { GrafanaTheme2 } from '@grafana/data'; +import { getCellLinks } from '../../utils'; export function JSONViewCell(props: TableCellProps): JSX.Element { - const { cell, tableStyles, cellProps } = props; + const { cell, tableStyles, cellProps, field, row } = props; const txt = css` cursor: pointer; @@ -28,10 +29,23 @@ export function JSONViewCell(props: TableCellProps): JSX.Element { const content = ; + const { link, onClick } = getCellLinks(field, row); + return (
-
{displayValue}
+ {!link &&
{value}
} + {link && ( + + {displayValue} + + )}
);