import React, { FC, Fragment, useMemo, useState } from 'react'; import { useDispatch } from 'react-redux'; import { ConfirmModal, useStyles2 } from '@grafana/ui'; import { contextSrv } from 'app/core/services/context_srv'; import { AlertManagerCortexConfig } from 'app/plugins/datasource/alertmanager/types'; import { Authorize } from '../../components/Authorize'; import { deleteTemplateAction } from '../../state/actions'; import { getAlertTableStyles } from '../../styles/table'; import { getNotificationsPermissions } from '../../utils/access-control'; import { makeAMLink } from '../../utils/misc'; import { CollapseToggle } from '../CollapseToggle'; import { DetailsField } from '../DetailsField'; import { ActionIcon } from '../rules/ActionIcon'; import { ReceiversSection } from './ReceiversSection'; interface Props { config: AlertManagerCortexConfig; alertManagerName: string; } export const TemplatesTable: FC = ({ config, alertManagerName }) => { const dispatch = useDispatch(); const [expandedTemplates, setExpandedTemplates] = useState>({}); const tableStyles = useStyles2(getAlertTableStyles); const permissions = getNotificationsPermissions(alertManagerName); const templateRows = useMemo(() => Object.entries(config.template_files), [config]); const [templateToDelete, setTemplateToDelete] = useState(); const deleteTemplate = () => { if (templateToDelete) { dispatch(deleteTemplateAction(templateToDelete, alertManagerName)); } setTemplateToDelete(undefined); }; return ( {!templateRows.length && ( )} {templateRows.map(([name, content], idx) => { const isExpanded = !!expandedTemplates[name]; return ( {isExpanded && ( )} ); })}
Template Actions
No templates defined.
setExpandedTemplates({ ...expandedTemplates, [name]: !isExpanded })} /> {name} setTemplateToDelete(name)} tooltip="delete template" icon="trash-alt" />
{content}
{!!templateToDelete && ( setTemplateToDelete(undefined)} /> )}
); };