Skip to content

Commit

Permalink
PMM-12741 Add check for alerting enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
matejkubinec committed Feb 29, 2024
1 parent f0d8b6b commit c7eef3e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
21 changes: 13 additions & 8 deletions public/app/features/alerting/unified/MoreActionsRuleButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useToggle } from 'react-use';

import { urlUtil } from '@grafana/data';
import { Button, Dropdown, Icon, LinkButton, Menu, MenuItem } from '@grafana/ui';
import { usePerconaAlertingEnabled } from 'app/percona/integrated-alerting/hooks';

import { logInfo, LogMessages } from './Analytics';
import { GrafanaRulesExporter } from './components/export/GrafanaRulesExporter';
Expand All @@ -18,6 +19,8 @@ export function MoreActionsRuleButtons({}: Props) {
const [exportRulesSupported, exportRulesAllowed] = useAlertingAbility(AlertingAction.ExportGrafanaManagedRules);

const location = useLocation();
// @PERCONA
const perconaAlertingEnabled = usePerconaAlertingEnabled();
const [showExportDrawer, toggleShowExportDrawer] = useToggle(false);

const canCreateGrafanaRules = createRuleSupported && createRuleAllowed;
Expand Down Expand Up @@ -49,15 +52,17 @@ export function MoreActionsRuleButtons({}: Props) {
{(canCreateGrafanaRules || canCreateCloudRules) && (
<>
{/* @PERCONA */}
{perconaAlertingEnabled && (
<LinkButton
href={urlUtil.renderUrl('alerting/new-from-template', { returnTo: location.pathname + location.search })}
icon="plus"
onClick={() => logInfo(LogMessages.alertRuleFromScratch)}
>
New alert rule from template
</LinkButton>
)}
<LinkButton
href={urlUtil.renderUrl('alerting/new-from-template', { returnTo: location.pathname + location.search })}
icon="plus"
onClick={() => logInfo(LogMessages.alertRuleFromScratch)}
>
New alert rule from template
</LinkButton>
<LinkButton
variant="secondary"
variant={perconaAlertingEnabled ? 'secondary' : 'primary'}
href={urlUtil.renderUrl('alerting/new/alerting', { returnTo: location.pathname + location.search })}
icon="plus"
onClick={() => logInfo(LogMessages.alertRuleFromScratch)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@ import React from 'react';
import { GrafanaTheme2 } from '@grafana/data/src/themes';
import { CallToActionCard, useStyles2, Stack } from '@grafana/ui';
import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA';
import { usePerconaAlertingEnabled } from 'app/percona/integrated-alerting/hooks';

import { logInfo, LogMessages } from '../../Analytics';
import { useRulesAccess } from '../../utils/accessControlHooks';

export const NoRulesSplash = () => {
// @PERCONA
const perconaAlertingEnabled = usePerconaAlertingEnabled();
const { canCreateGrafanaRules, canCreateCloudRules } = useRulesAccess();
const styles = useStyles2(getStyles);
if (canCreateGrafanaRules || canCreateCloudRules) {
return (
<div>
<p>{"You haven't created any alert rules yet"}</p>
<Stack gap={1} wrap="wrap">
<div className={cx(styles.newRuleCard, styles.fullWidth)}>
<EmptyListCTA
title=""
buttonIcon="plus"
buttonLink="alerting/new-from-template"
buttonTitle="New alert rule from template"
onClick={() => logInfo(LogMessages.alertRuleFromScratch)}
/>
</div>
{perconaAlertingEnabled && (
<div className={cx(styles.newRuleCard, styles.fullWidth)}>
<EmptyListCTA
title=""
buttonIcon="plus"
buttonLink="alerting/new-from-template"
buttonTitle="New alert rule from template"
onClick={() => logInfo(LogMessages.alertRuleFromScratch)}
/>
</div>
)}

<div className={styles.newRuleCard}>
<EmptyListCTA
Expand Down
1 change: 1 addition & 0 deletions public/app/percona/integrated-alerting/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './usePerconaAlertingEnabled';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getPerconaSettings } from 'app/percona/shared/core/selectors';
import { useSelector } from 'app/types';

export const usePerconaAlertingEnabled = (): boolean => {
const { result: settings } = useSelector(getPerconaSettings);

return !!settings?.alertingEnabled;
};

0 comments on commit c7eef3e

Please sign in to comment.