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'; import { TableCellProps } from '../types';
export const DataLinksCell = (props: TableCellProps) => { export const DataLinksCell = (props: TableCellProps) => {
const { field, row, cellProps, tableStyles } = props; const { field, row, cellProps, tableStyles } = props;
const links = getCellLinks(field, row); const links = getCellLinks(field, row.index);
return ( return (
<div {...cellProps} className={tableStyles.cellContainerText}> <div {...cellProps} className={tableStyles.cellContainerText}>

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

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

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

Loading…
Cancel
Save