import {Fragment} from 'react'; import styled from '@emotion/styled'; import {Location} from 'history'; import PanelTable, { PanelTableHeader, PanelTableProps, } from 'sentry/components/panels/panelTable'; import Tooltip from 'sentry/components/tooltip'; import Truncate from 'sentry/components/truncate'; import space from 'sentry/styles/space'; import {Organization} from 'sentry/types'; import {TableData, TableDataRow} from 'sentry/utils/discover/discoverQuery'; import EventView, {MetaType} from 'sentry/utils/discover/eventView'; import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers'; import {fieldAlignment} from 'sentry/utils/discover/fields'; import withOrganization from 'sentry/utils/withOrganization'; import TopResultsIndicator from 'sentry/views/eventsV2/table/topResultsIndicator'; import {decodeColumnOrder} from 'sentry/views/eventsV2/utils'; type Props = { eventView: EventView; fieldAliases: string[]; fields: string[]; loading: boolean; location: Location; organization: Organization; title: string; className?: string; data?: TableData['data']; fieldHeaderMap?: Record; getCustomFieldRenderer?: ( field: string, meta: MetaType, organization?: Organization ) => ReturnType | null; loader?: PanelTableProps['loader']; metadata?: TableData['meta']; stickyHeaders?: boolean; topResultsIndicators?: number; }; function SimpleTableChart({ className, loading, eventView, fields, metadata, data, title, fieldHeaderMap, stickyHeaders, getCustomFieldRenderer, organization, topResultsIndicators, location, fieldAliases, loader, }: Props) { function renderRow( index: number, row: TableDataRow, tableMeta: NonNullable, columns: ReturnType ) { return columns.map((column, columnIndex) => { const fieldRenderer = getCustomFieldRenderer?.(column.key, tableMeta, organization) ?? getFieldRenderer(column.key, tableMeta); const unit = tableMeta.units?.[column.key]; return ( {topResultsIndicators && columnIndex === 0 && ( )} {fieldRenderer(row, {organization, location, eventView, unit})} ); }); } const meta = metadata ?? {}; const usingEvents = organization.features.includes( 'discover-frontend-use-events-endpoint' ); const columns = decodeColumnOrder( fields.map((field, index) => ({field, alias: fieldAliases[index]})), usingEvents ); return ( {title &&

{title}

} { const align = fieldAlignment(column.name, column.type, meta); const header = column.column.alias || (fieldHeaderMap?.[column.key] ?? column.name); return ( ); })} isEmpty={!data?.length} stickyHeaders={stickyHeaders} disablePadding > {data?.map((row, index) => renderRow(index, row, meta, columns))}
); } const StyledTruncate = styled(Truncate)` white-space: nowrap; `; const StyledPanelTable = styled(PanelTable)` border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; margin: 0; ${PanelTableHeader} { height: min-content; } `; type HeadCellProps = { align: string | undefined; }; const HeadCell = styled('div')` ${(p: HeadCellProps) => (p.align ? `text-align: ${p.align};` : '')} padding: ${space(1)} ${space(3)}; `; export const TableCell = styled('div')` padding: ${space(1)} ${space(3)}; `; export default withOrganization(SimpleTableChart);