import { css } from '@emotion/css'; import React, { FC, useMemo } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { Alert } from 'app/types/unified-alerting'; import { alertInstanceKey } from '../../utils/rules'; import { AlertLabels } from '../AlertLabels'; import { DynamicTable, DynamicTableColumnProps, DynamicTableItemProps } from '../DynamicTable'; import { AlertInstanceDetails } from './AlertInstanceDetails'; import { AlertStateTag } from './AlertStateTag'; interface Props { instances: Alert[]; } type AlertTableColumnProps = DynamicTableColumnProps; type AlertTableItemProps = DynamicTableItemProps; export const AlertInstancesTable: FC = ({ instances }) => { const items = useMemo( (): AlertTableItemProps[] => instances.map((instance) => ({ data: instance, id: alertInstanceKey(instance), })), [instances] ); return ( } /> ); }; export const getStyles = (theme: GrafanaTheme2) => ({ colExpand: css` width: 36px; `, colState: css` width: 110px; `, labelsCell: css` padding-top: ${theme.spacing(0.5)} !important; padding-bottom: ${theme.spacing(0.5)} !important; `, createdCell: css` white-space: nowrap; `, table: css` td { vertical-align: top; padding-top: ${theme.spacing(1)}; padding-bottom: ${theme.spacing(1)}; } `, }); const columns: AlertTableColumnProps[] = [ { id: 'state', label: 'State', // eslint-disable-next-line react/display-name renderCell: ({ data: { state } }) => , size: '80px', }, { id: 'labels', label: 'Labels', // eslint-disable-next-line react/display-name renderCell: ({ data: { labels } }) => , }, { id: 'created', label: 'Created', // eslint-disable-next-line react/display-name renderCell: ({ data: { activeAt } }) => ( <>{activeAt.startsWith('0001') ? '-' : activeAt.slice(0, 19).replace('T', ' ')} ), size: '150px', }, ];