Alerting: Swap templates and contact points places (#61808)

Alerting: swap templates and contact points places
pull/61648/head
Gilles De Mey 2 years ago committed by GitHub
parent 511dab3b4b
commit 845128dde9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      public/app/features/alerting/unified/components/receivers/ReceiversAndTemplatesView.tsx
  2. 8
      public/app/features/alerting/unified/components/receivers/ReceiversSection.tsx
  3. 25
      public/app/features/alerting/unified/components/receivers/ReceiversTable.tsx

@ -1,8 +1,7 @@
import { css } from '@emotion/css';
import React, { FC } from 'react'; import React, { FC } from 'react';
import { GrafanaTheme2 } from '@grafana/data'; import { Stack } from '@grafana/experimental';
import { Alert, LinkButton, useStyles2 } from '@grafana/ui'; import { Alert, LinkButton } from '@grafana/ui';
import { AlertManagerCortexConfig } from 'app/plugins/datasource/alertmanager/types'; import { AlertManagerCortexConfig } from 'app/plugins/datasource/alertmanager/types';
import { AccessControlAction } from 'app/types'; import { AccessControlAction } from 'app/types';
@ -20,15 +19,15 @@ interface Props {
export const ReceiversAndTemplatesView: FC<Props> = ({ config, alertManagerName }) => { export const ReceiversAndTemplatesView: FC<Props> = ({ config, alertManagerName }) => {
const isCloud = alertManagerName !== GRAFANA_RULES_SOURCE_NAME; const isCloud = alertManagerName !== GRAFANA_RULES_SOURCE_NAME;
const styles = useStyles2(getStyles);
const isVanillaAM = isVanillaPrometheusAlertManagerDataSource(alertManagerName); const isVanillaAM = isVanillaPrometheusAlertManagerDataSource(alertManagerName);
return ( return (
<> <Stack direction="column" gap={4}>
{!isVanillaAM && <TemplatesTable config={config} alertManagerName={alertManagerName} />}
<ReceiversTable config={config} alertManagerName={alertManagerName} /> <ReceiversTable config={config} alertManagerName={alertManagerName} />
{!isVanillaAM && <TemplatesTable config={config} alertManagerName={alertManagerName} />}
{isCloud && ( {isCloud && (
<Authorize actions={[AccessControlAction.AlertingNotificationsExternalWrite]}> <Authorize actions={[AccessControlAction.AlertingNotificationsExternalWrite]}>
<Alert className={styles.section} severity="info" title="Global config for contact points"> <Alert severity="info" title="Global config for contact points">
<p> <p>
For each external Alertmanager you can define global settings, like server addresses, usernames and For each external Alertmanager you can define global settings, like server addresses, usernames and
password, for all the supported contact points. password, for all the supported contact points.
@ -39,12 +38,6 @@ export const ReceiversAndTemplatesView: FC<Props> = ({ config, alertManagerName
</Alert> </Alert>
</Authorize> </Authorize>
)} )}
</> </Stack>
); );
}; };
const getStyles = (theme: GrafanaTheme2) => ({
section: css`
margin-top: ${theme.spacing(4)};
`,
});

@ -3,6 +3,7 @@ import React from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { GrafanaTheme2 } from '@grafana/data'; import { GrafanaTheme2 } from '@grafana/data';
import { Stack } from '@grafana/experimental';
import { Button, useStyles2 } from '@grafana/ui'; import { Button, useStyles2 } from '@grafana/ui';
interface Props { interface Props {
@ -25,11 +26,11 @@ export const ReceiversSection = ({
}: React.PropsWithChildren<Props>) => { }: React.PropsWithChildren<Props>) => {
const styles = useStyles2(getStyles); const styles = useStyles2(getStyles);
return ( return (
<> <Stack direction="column" gap={2}>
<div className={cx(styles.heading, className)}> <div className={cx(styles.heading, className)}>
<div> <div>
<h4>{title}</h4> <h4>{title}</h4>
<p className={styles.description}>{description}</p> <div className={styles.description}>{description}</div>
</div> </div>
{showButton && ( {showButton && (
<Link to={addButtonTo}> <Link to={addButtonTo}>
@ -40,7 +41,7 @@ export const ReceiversSection = ({
)} )}
</div> </div>
{children} {children}
</> </Stack>
); );
}; };
@ -48,6 +49,7 @@ const getStyles = (theme: GrafanaTheme2) => ({
heading: css` heading: css`
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: flex-end;
`, `,
description: css` description: css`
color: ${theme.colors.text.secondary}; color: ${theme.colors.text.secondary};

@ -1,8 +1,7 @@
import { css } from '@emotion/css';
import pluralize from 'pluralize'; import pluralize from 'pluralize';
import React, { FC, useMemo, useState } from 'react'; import React, { FC, useMemo, useState } from 'react';
import { GrafanaTheme2, dateTime, dateTimeFormat } from '@grafana/data'; import { dateTime, dateTimeFormat } from '@grafana/data';
import { Stack } from '@grafana/experimental'; import { Stack } from '@grafana/experimental';
import { Button, ConfirmModal, Modal, useStyles2, Badge, Icon } from '@grafana/ui'; import { Button, ConfirmModal, Modal, useStyles2, Badge, Icon } from '@grafana/ui';
import { contextSrv } from 'app/core/services/context_srv'; import { contextSrv } from 'app/core/services/context_srv';
@ -241,7 +240,6 @@ interface Props {
export const ReceiversTable: FC<Props> = ({ config, alertManagerName }) => { export const ReceiversTable: FC<Props> = ({ config, alertManagerName }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const styles = useStyles2(getStyles);
const isVanillaAM = isVanillaPrometheusAlertManagerDataSource(alertManagerName); const isVanillaAM = isVanillaPrometheusAlertManagerDataSource(alertManagerName);
const permissions = getNotificationsPermissions(alertManagerName); const permissions = getNotificationsPermissions(alertManagerName);
const grafanaNotifiers = useUnifiedAlertingSelector((state) => state.grafanaNotifiers); const grafanaNotifiers = useUnifiedAlertingSelector((state) => state.grafanaNotifiers);
@ -299,7 +297,6 @@ export const ReceiversTable: FC<Props> = ({ config, alertManagerName }) => {
return ( return (
<ReceiversSection <ReceiversSection
className={styles.section}
title="Contact points" title="Contact points"
description="Define where the notifications will be sent to, for example email or Slack." description="Define where the notifications will be sent to, for example email or Slack."
showButton={!isVanillaAM && contextSrv.hasPermission(permissions.create)} showButton={!isVanillaAM && contextSrv.hasPermission(permissions.create)}
@ -436,23 +433,3 @@ function useGetColumns(
}, },
]; ];
} }
const getStyles = (theme: GrafanaTheme2) => ({
section: css`
margin-top: ${theme.spacing(4)};
`,
warning: css`
color: ${theme.colors.warning.text};
`,
countMessage: css``,
onCallBadgeWrapper: css`
text-align: left;
height: 22px;
display: inline-flex;
padding: 1px 4px;
border-radius: 3px;
border: 1px solid rgba(245, 95, 62, 1);
color: rgba(245, 95, 62, 1);
font-weight: ${theme.typography.fontWeightRegular};
`,
});

Loading…
Cancel
Save