reuse getCellLinks from TableNG

pull/105495/head
Adela Almasan 2 months ago
parent db828d0f00
commit cb0d8494c9
  1. 4
      packages/grafana-ui/src/components/Table/Cells/DataLinksCell.tsx
  2. 6
      packages/grafana-ui/src/components/Table/Cells/DefaultCell.tsx
  3. 6
      packages/grafana-ui/src/components/Table/Cells/ImageCell.tsx
  4. 6
      packages/grafana-ui/src/components/Table/Cells/JSONViewCell.tsx

@ -1,10 +1,10 @@
import { getCellLinks } from '../../../utils';
import { getCellLinks } from '../TableNG/utils';
import { TableCellProps } from '../types';
export const DataLinksCell = (props: TableCellProps) => {
const { field, row, cellProps, tableStyles } = props;
const links = getCellLinks(field, row);
const links = getCellLinks(field, row.index);
return (
<div {...cellProps} className={tableStyles.cellContainerText}>

@ -6,11 +6,11 @@ import { DisplayValue, formattedValueToString } from '@grafana/data';
import { TableCellDisplayMode } from '@grafana/schema';
import { useStyles2 } from '../../../themes';
import { getCellLinks } from '../../../utils';
import { clearLinkButtonStyles } from '../../Button';
import { DataLinksContextMenu } from '../../DataLinks/DataLinksContextMenu';
import { CellActions } from '../CellActions';
import { TableCellInspectorMode } from '../TableCellInspector';
import { getCellLinks } from '../TableNG/utils';
import { TableStyles } from '../TableRT/styles';
import { TableCellProps, CustomCellRendererProps, TableCellOptions } from '../types';
import { getCellColors, getCellOptions } from '../utils';
@ -23,7 +23,7 @@ export const DefaultCell = (props: TableCellProps) => {
const showFilters = props.onCellFilterAdded && field.config.filterable;
const showActions = (showFilters && cell.value !== undefined) || inspectEnabled;
const cellOptions = getCellOptions(field);
const cellLinks = getCellLinks(field, row);
const cellLinks = getCellLinks(field, row.index);
const hasLinks = cellLinks?.some((link) => link.href || link.onClick != null);
const clearButtonStyle = useStyles2(clearLinkButtonStyles);
let value: string | ReactElement;
@ -81,7 +81,7 @@ export const DefaultCell = (props: TableCellProps) => {
<div key={key} {...rest} className={cellStyle}>
{hasLinks ? (
<DataLinksContextMenu
links={() => getCellLinks(field, row)?.filter((link) => link.href || link.onClick != null) || []}
links={() => getCellLinks(field, row.index)?.filter((link) => link.href || link.onClick != null) || []}
>
{(api) => {
if (api.openMenu) {

@ -1,7 +1,7 @@
import * as React from 'react';
import { getCellLinks } from '../../../utils';
import { DataLinksContextMenu } from '../../DataLinks/DataLinksContextMenu';
import { getCellLinks } from '../TableNG/utils';
import { TableCellDisplayMode, TableCellProps } from '../types';
import { getCellOptions } from '../utils';
@ -13,7 +13,7 @@ export const ImageCell = (props: TableCellProps) => {
const { title, alt } =
cellOptions.type === TableCellDisplayMode.Image ? cellOptions : { title: undefined, alt: undefined };
const displayValue = field.display!(cell.value);
const hasLinks = Boolean(getCellLinks(field, row)?.length);
const hasLinks = Boolean(getCellLinks(field, row.index)?.length);
// The image element
const img = (
@ -33,7 +33,7 @@ export const ImageCell = (props: TableCellProps) => {
{hasLinks ? (
<DataLinksContextMenu
style={{ height: tableStyles.cellHeight - DATALINKS_HEIGHT_OFFSET, width: 'auto' }}
links={() => getCellLinks(field, row) || []}
links={() => getCellLinks(field, row.index) || []}
>
{(api) => {
if (api.openMenu) {

@ -2,11 +2,11 @@ import { css, cx } from '@emotion/css';
import { isString } from 'lodash';
import { useStyles2 } from '../../../themes';
import { getCellLinks } from '../../../utils';
import { Button, clearLinkButtonStyles } from '../../Button';
import { DataLinksContextMenu } from '../../DataLinks/DataLinksContextMenu';
import { CellActions } from '../CellActions';
import { TableCellInspectorMode } from '../TableCellInspector';
import { getCellLinks } from '../TableNG/utils';
import { TableCellProps } from '../types';
export function JSONViewCell(props: TableCellProps): JSX.Element {
@ -28,14 +28,14 @@ export function JSONViewCell(props: TableCellProps): JSX.Element {
displayValue = JSON.stringify(value, null, ' ');
}
const hasLinks = Boolean(getCellLinks(field, row)?.length);
const hasLinks = Boolean(getCellLinks(field, row.index)?.length);
const clearButtonStyle = useStyles2(clearLinkButtonStyles);
return (
<div {...cellProps} className={inspectEnabled ? tableStyles.cellContainerNoOverflow : tableStyles.cellContainer}>
<div className={cx(tableStyles.cellText, txt)}>
{hasLinks ? (
<DataLinksContextMenu links={() => getCellLinks(field, row) || []}>
<DataLinksContextMenu links={() => getCellLinks(field, row.index) || []}>
{(api) => {
if (api.openMenu) {
return (

Loading…
Cancel
Save