123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 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<Alert>;
- type AlertTableItemProps = DynamicTableItemProps<Alert>;
- export const AlertInstancesTable: FC<Props> = ({ instances }) => {
- const items = useMemo(
- (): AlertTableItemProps[] =>
- instances.map((instance) => ({
- data: instance,
- id: alertInstanceKey(instance),
- })),
- [instances]
- );
- return (
- <DynamicTable
- cols={columns}
- isExpandable={true}
- items={items}
- renderExpandedContent={({ data }) => <AlertInstanceDetails instance={data} />}
- />
- );
- };
- 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 } }) => <AlertStateTag state={state} />,
- size: '80px',
- },
- {
- id: 'labels',
- label: 'Labels',
- // eslint-disable-next-line react/display-name
- renderCell: ({ data: { labels } }) => <AlertLabels labels={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',
- },
- ];
|