2021-05-04 13:38:01 +02:00
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
2021-05-27 13:47:26 +03:00
|
|
|
import { Alert } from 'app/types/unified-alerting';
|
2021-06-23 09:27:47 +03:00
|
|
|
import { css } from '@emotion/css';
|
|
|
|
|
import React, { FC, useMemo } from 'react';
|
2021-04-07 08:42:43 +03:00
|
|
|
import { alertInstanceKey } from '../../utils/rules';
|
|
|
|
|
import { AlertLabels } from '../AlertLabels';
|
|
|
|
|
import { AlertInstanceDetails } from './AlertInstanceDetails';
|
2021-05-06 11:21:58 +03:00
|
|
|
import { AlertStateTag } from './AlertStateTag';
|
2021-06-23 09:27:47 +03:00
|
|
|
import { DynamicTable, DynamicTableColumnProps, DynamicTableItemProps } from '../DynamicTable';
|
2021-05-27 13:47:26 +03:00
|
|
|
|
2021-04-07 08:42:43 +03:00
|
|
|
interface Props {
|
2021-05-27 13:47:26 +03:00
|
|
|
instances: Alert[];
|
2021-04-07 08:42:43 +03:00
|
|
|
}
|
|
|
|
|
|
2021-06-23 09:27:47 +03:00
|
|
|
type AlertTableColumnProps = DynamicTableColumnProps<Alert>;
|
|
|
|
|
type AlertTableItemProps = DynamicTableItemProps<Alert>;
|
2021-04-07 08:42:43 +03:00
|
|
|
|
2021-06-23 09:27:47 +03:00
|
|
|
export const AlertInstancesTable: FC<Props> = ({ instances }) => {
|
|
|
|
|
const items = useMemo(
|
|
|
|
|
(): AlertTableItemProps[] =>
|
2021-12-13 05:54:36 -05:00
|
|
|
instances.map((instance) => ({
|
|
|
|
|
data: instance,
|
|
|
|
|
id: alertInstanceKey(instance),
|
|
|
|
|
})),
|
2021-05-27 13:47:26 +03:00
|
|
|
[instances]
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-07 08:42:43 +03:00
|
|
|
return (
|
2021-06-23 09:27:47 +03:00
|
|
|
<DynamicTable
|
|
|
|
|
cols={columns}
|
|
|
|
|
isExpandable={true}
|
|
|
|
|
items={items}
|
|
|
|
|
renderExpandedContent={({ data }) => <AlertInstanceDetails instance={data} />}
|
|
|
|
|
/>
|
2021-04-07 08:42:43 +03:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-04 13:38:01 +02:00
|
|
|
export const getStyles = (theme: GrafanaTheme2) => ({
|
2021-04-07 08:42:43 +03:00
|
|
|
colExpand: css`
|
|
|
|
|
width: 36px;
|
|
|
|
|
`,
|
|
|
|
|
colState: css`
|
|
|
|
|
width: 110px;
|
|
|
|
|
`,
|
|
|
|
|
labelsCell: css`
|
2021-05-04 13:38:01 +02:00
|
|
|
padding-top: ${theme.spacing(0.5)} !important;
|
|
|
|
|
padding-bottom: ${theme.spacing(0.5)} !important;
|
2021-04-07 08:42:43 +03:00
|
|
|
`,
|
|
|
|
|
createdCell: css`
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
`,
|
|
|
|
|
table: css`
|
|
|
|
|
td {
|
|
|
|
|
vertical-align: top;
|
2021-05-04 13:38:01 +02:00
|
|
|
padding-top: ${theme.spacing(1)};
|
|
|
|
|
padding-bottom: ${theme.spacing(1)};
|
2021-04-07 08:42:43 +03:00
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
});
|
2021-06-23 09:27:47 +03:00
|
|
|
|
|
|
|
|
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 } }) => (
|
2022-04-04 11:08:06 +02:00
|
|
|
<>{activeAt.startsWith('0001') ? '-' : activeAt.slice(0, 19).replace('T', ' ')}</>
|
2021-06-23 09:27:47 +03:00
|
|
|
),
|
|
|
|
|
size: '150px',
|
|
|
|
|
},
|
|
|
|
|
];
|