{"version":3,"file":"renderers.cjs","sources":["../../../../../../src/components/Table/TableNG/Cells/renderers.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { memo, MemoExoticComponent } from 'react';\n\nimport { Field, FieldType, GrafanaTheme2, isDataFrame, isTimeSeriesFrame } from '@grafana/data';\n\nimport { TableCellDisplayMode, TableCellOptions, TableCustomCellOptions } from '../../types';\nimport { TableCellRenderer, TableCellRendererProps, TableCellStyleOptions, TableCellStyles } from '../types';\nimport { getCellOptions } from '../utils';\n\nimport { ActionsCell, getStyles as getActionsCellStyles } from './ActionsCell';\nimport { AutoCell, getStyles as getAutoCellStyles, getJsonCellStyles } from './AutoCell';\nimport { BarGaugeCell } from './BarGaugeCell';\nimport { DataLinksCell, getStyles as getDataLinksStyles } from './DataLinksCell';\nimport { GeoCell, getStyles as getGeoCellStyles } from './GeoCell';\nimport { ImageCell, getStyles as getImageStyles } from './ImageCell';\nimport { MarkdownCell, getStyles as getMarkdownCellStyles } from './MarkdownCell';\nimport { PillCell, getStyles as getPillStyles } from './PillCell';\nimport { SparklineCell, getStyles as getSparklineCellStyles } from './SparklineCell';\n\nexport const AutoCellRenderer = memo((props: TableCellRendererProps) => (\n  <AutoCell value={props.value} field={props.field} rowIdx={props.rowIdx} />\n));\nAutoCellRenderer.displayName = 'AutoCellRenderer';\n\nfunction isCustomCellOptions(options: TableCellOptions): options is TableCustomCellOptions {\n  return options.type === TableCellDisplayMode.Custom;\n}\n\nfunction mixinAutoCellStyles(fn: TableCellStyles): TableCellStyles {\n  return (theme, options) => {\n    const styles = fn(theme, options);\n    return clsx(styles, getAutoCellStyles(theme, options));\n  };\n}\n\ninterface CellRegistryEntry {\n  renderer: MemoExoticComponent<TableCellRenderer>;\n  getStyles?: TableCellStyles;\n  testField?: (field: Field) => boolean;\n}\n\nconst CELL_REGISTRY: Record<TableCellOptions['type'], CellRegistryEntry> = {\n  [TableCellDisplayMode.Auto]: {\n    renderer: AutoCellRenderer,\n    getStyles: getAutoCellStyles,\n  },\n  [TableCellDisplayMode.ColorBackground]: {\n    renderer: AutoCellRenderer,\n    getStyles: getAutoCellStyles,\n  },\n  [TableCellDisplayMode.ColorText]: {\n    renderer: AutoCellRenderer,\n    getStyles: getAutoCellStyles,\n  },\n  [TableCellDisplayMode.JSONView]: {\n    renderer: AutoCellRenderer,\n    getStyles: mixinAutoCellStyles(getJsonCellStyles),\n  },\n  [TableCellDisplayMode.Actions]: {\n    // eslint-disable-next-line react/display-name\n    renderer: memo((props: TableCellRendererProps) => (\n      <ActionsCell field={props.field} rowIdx={props.rowIdx} getActions={props.getActions ?? (() => [])} />\n    )),\n    getStyles: getActionsCellStyles,\n  },\n  [TableCellDisplayMode.DataLinks]: {\n    // eslint-disable-next-line react/display-name\n    renderer: memo((props: TableCellRendererProps) => <DataLinksCell field={props.field} rowIdx={props.rowIdx} />),\n    getStyles: getDataLinksStyles,\n  },\n  [TableCellDisplayMode.Gauge]: {\n    // eslint-disable-next-line react/display-name\n    renderer: memo((props: TableCellRendererProps) => (\n      <BarGaugeCell\n        field={props.field}\n        value={props.value}\n        theme={props.theme}\n        height={props.height}\n        width={props.width}\n        rowIdx={props.rowIdx}\n      />\n    )),\n  },\n  [TableCellDisplayMode.Sparkline]: {\n    // eslint-disable-next-line react/display-name\n    renderer: memo((props: TableCellRendererProps) => (\n      <SparklineCell\n        value={props.value}\n        field={props.field}\n        timeRange={props.timeRange}\n        rowIdx={props.rowIdx}\n        theme={props.theme}\n        width={props.width}\n      />\n    )),\n    getStyles: getSparklineCellStyles,\n  },\n  [TableCellDisplayMode.Geo]: {\n    // eslint-disable-next-line react/display-name\n    renderer: memo((props: TableCellRendererProps) => <GeoCell value={props.value} height={props.height} />),\n    getStyles: getGeoCellStyles,\n  },\n  [TableCellDisplayMode.Image]: {\n    // eslint-disable-next-line react/display-name\n    renderer: memo((props: TableCellRendererProps) => (\n      <ImageCell cellOptions={props.cellOptions} field={props.field} value={props.value} rowIdx={props.rowIdx} />\n    )),\n    getStyles: getImageStyles,\n  },\n  [TableCellDisplayMode.Pill]: {\n    // eslint-disable-next-line react/display-name\n    renderer: memo((props: TableCellRendererProps) => (\n      <PillCell\n        rowIdx={props.rowIdx}\n        field={props.field}\n        theme={props.theme}\n        getTextColorForBackground={props.getTextColorForBackground}\n      />\n    )),\n    getStyles: getPillStyles,\n    testField: (field: Field) =>\n      field.type === FieldType.string ||\n      (field.type === FieldType.other && field.values.some((val) => Array.isArray(val))),\n  },\n  [TableCellDisplayMode.Markdown]: {\n    // eslint-disable-next-line react/display-name\n    renderer: memo((props: TableCellRendererProps) => (\n      <MarkdownCell field={props.field} rowIdx={props.rowIdx} disableSanitizeHtml={props.disableSanitizeHtml} />\n    )),\n    getStyles: getMarkdownCellStyles,\n    testField: (field: Field) => field.type === FieldType.string,\n  },\n  [TableCellDisplayMode.Custom]: {\n    // eslint-disable-next-line react/display-name\n    renderer: memo((props: TableCellRendererProps) => {\n      if (!isCustomCellOptions(props.cellOptions) || !props.cellOptions.cellComponent) {\n        return null; // nonsensical case, but better to typeguard it than throw.\n      }\n      const CustomCellComponent = props.cellOptions.cellComponent;\n      return (\n        <CustomCellComponent field={props.field} rowIndex={props.rowIdx} frame={props.frame} value={props.value} />\n      );\n    }),\n  },\n};\n\n/** @internal */\nexport function getCellRenderer(\n  field: Field,\n  cellOptions: TableCellOptions = getCellOptions(field)\n): TableCellRenderer {\n  const cellType = cellOptions?.type ?? TableCellDisplayMode.Auto;\n  if (cellType === TableCellDisplayMode.Auto) {\n    return CELL_REGISTRY[getAutoRendererDisplayMode(field)].renderer;\n  }\n\n  // if the field fails the test for a specific renderer, fallback to Auto\n  if (CELL_REGISTRY[cellType]?.testField && CELL_REGISTRY[cellType].testField(field) !== true) {\n    return AutoCellRenderer;\n  }\n\n  // cautious fallback to Auto renderer in case some garbage cell type has been provided.\n  return CELL_REGISTRY[cellType]?.renderer ?? AutoCellRenderer;\n}\n\n/** @internal */\nexport function getCellSpecificStyles(\n  cellType: TableCellOptions['type'],\n  field: Field,\n  theme: GrafanaTheme2,\n  options: TableCellStyleOptions\n): string | undefined {\n  if (cellType === TableCellDisplayMode.Auto) {\n    return getAutoRendererStyles(theme, options, field);\n  }\n  return CELL_REGISTRY[cellType]?.getStyles?.(theme, options);\n}\n\n/** @internal */\nexport function getAutoRendererStyles(\n  theme: GrafanaTheme2,\n  options: TableCellStyleOptions,\n  field: Field\n): string | undefined {\n  const impliedDisplayMode = getAutoRendererDisplayMode(field);\n  if (impliedDisplayMode !== TableCellDisplayMode.Auto) {\n    return CELL_REGISTRY[impliedDisplayMode]?.getStyles?.(theme, options);\n  }\n  return getAutoCellStyles(theme, options);\n}\n\n/** @internal */\nexport function getAutoRendererDisplayMode(field: Field): TableCellOptions['type'] {\n  if (field.type === FieldType.geo) {\n    return TableCellDisplayMode.Geo;\n  }\n  if (field.type === FieldType.frame) {\n    const firstValue = field.values[0];\n    if (isDataFrame(firstValue) && isTimeSeriesFrame(firstValue)) {\n      return TableCellDisplayMode.Sparkline;\n    }\n  }\n  return TableCellDisplayMode.Auto;\n}\n"],"names":["memo","AutoCell","TableCellDisplayMode","clsx","getAutoCellStyles","getJsonCellStyles","jsx","ActionsCell","getActionsCellStyles","DataLinksCell","getDataLinksStyles","BarGaugeCell","SparklineCell","getSparklineCellStyles","GeoCell","getGeoCellStyles","ImageCell","getImageStyles","PillCell","getPillStyles","FieldType","MarkdownCell","getMarkdownCellStyles","getCellOptions","isDataFrame","isTimeSeriesFrame"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBO,MAAM,gBAAA,GAAmBA,UAAA,CAAK,CAAC,KAAA,oCACnCC,iBAAA,EAAA,EAAS,KAAA,EAAO,KAAA,CAAM,KAAA,EAAO,OAAO,KAAA,CAAM,KAAA,EAAO,MAAA,EAAQ,KAAA,CAAM,QAAQ,CACzE;AACD,gBAAA,CAAiB,WAAA,GAAc,kBAAA;AAE/B,SAAS,oBAAoB,OAAA,EAA8D;AACzF,EAAA,OAAO,OAAA,CAAQ,SAASC,2BAA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