import { css } from '@emotion/css'; import { useMemo } from 'react'; import { ActionModel, DashboardCursorSync, DataFrame, FieldMatcherID, getFrameDisplayName, InterpolateFunction, PanelProps, SelectableValue, Field, cacheFieldDisplayNames, } from '@grafana/data'; import { config, PanelDataErrorView } from '@grafana/runtime'; import { Select, usePanelContext, useTheme2 } from '@grafana/ui'; import { TableSortByFieldState } from '@grafana/ui/internal'; import { TableNG } from '@grafana/ui/unstable'; import { getActions } from '../../../../features/actions/utils'; import { hasDeprecatedParentRowIndex, migrateFromParentRowIndexToNestedFrames } from './migrations'; import { Options } from './panelcfg.gen'; interface Props extends PanelProps {} export function TablePanel(props: Props) { const { data, height, width, options, fieldConfig, id, timeRange, replaceVariables } = props; useMemo(() => { cacheFieldDisplayNames(data.series); }, [data.series]); const theme = useTheme2(); const panelContext = usePanelContext(); const frames = hasDeprecatedParentRowIndex(data.series) ? migrateFromParentRowIndexToNestedFrames(data.series) : data.series; const count = frames?.length; const hasFields = frames.some((frame) => frame.fields.length > 0); const currentIndex = getCurrentFrameIndex(frames, options); const main = frames[currentIndex]; let tableHeight = height; if (!count || !hasFields) { return ; } if (count > 1) { const inputHeight = theme.spacing.gridSize * theme.components.height.md; const padding = theme.spacing.gridSize; tableHeight = height - inputHeight - padding; } const enableSharedCrosshair = panelContext.sync && panelContext.sync() !== DashboardCursorSync.Off; const tableElement = ( onSortByChange(sortBy, props)} onColumnResize={(displayName, resizedWidth) => onColumnResize(displayName, resizedWidth, props)} onCellFilterAdded={panelContext.onAddAdHocFilter} footerOptions={options.footer} enablePagination={options.footer?.enablePagination} cellHeight={options.cellHeight} timeRange={timeRange} enableSharedCrosshair={config.featureToggles.tableSharedCrosshair && enableSharedCrosshair} fieldConfig={fieldConfig} getActions={getCellActions} replaceVariables={replaceVariables} structureRev={data.structureRev} /> ); if (count === 1) { return tableElement; } const names = frames.map((frame, index) => { return { label: getFrameDisplayName(frame), value: index, }; }); return (
{tableElement}