Alerting: Improve incident button (#61372)

pull/61175/head^2
Gilles De Mey 2 years ago committed by GitHub
parent 39e429a14b
commit 11a8628381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      public/app/features/alerting/unified/components/bridges/DeclareIncidentButton.tsx
  2. 2
      public/app/features/alerting/unified/components/rules/RuleDetailsActionButtons.tsx

@ -1,39 +1,38 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { useHistory } from 'react-router-dom';
import { Button, Tooltip } from '@grafana/ui'; import { Button, LinkButton, Tooltip } from '@grafana/ui';
import { createBridgeURL, usePluginBridge, SupportedPlugin } from '../PluginBridge'; import { createBridgeURL, usePluginBridge, SupportedPlugin } from '../PluginBridge';
interface Props { interface Props {
title?: string; title?: string;
severity?: 'minor' | 'major' | 'critical'; severity?: 'minor' | 'major' | 'critical';
url?: string;
} }
export const DeclareIncident: FC<Props> = ({ title = '', severity = '' }) => { export const DeclareIncident: FC<Props> = ({ title = '', severity = '', url = '' }) => {
const history = useHistory(); const bridgeURL = createBridgeURL(SupportedPlugin.Incident, '/incidents/declare', { title, severity, url });
const bridgeURL = createBridgeURL(SupportedPlugin.Incident, '/incidents/declare', { title, severity });
const { loading, installed, settings } = usePluginBridge(SupportedPlugin.Incident); const { loading, installed, settings } = usePluginBridge(SupportedPlugin.Incident);
return ( return (
<> <>
{loading === true && ( {loading === true && (
<Button size="sm" type="button" disabled> <Button icon="fire" size="sm" type="button" disabled>
Declare Incident Declare Incident
</Button> </Button>
)} )}
{installed === false && ( {installed === false && (
<Tooltip content={'Grafana Incident is not installed or is not configured correctly'}> <Tooltip content={'Grafana Incident is not installed or is not configured correctly'}>
<Button size="sm" type="button" disabled> <Button icon="fire" size="sm" type="button" disabled>
Declare Incident Declare Incident
</Button> </Button>
</Tooltip> </Tooltip>
)} )}
{settings && ( {settings && (
<Button size="sm" type="button" onClick={() => history.push(bridgeURL)}> <LinkButton icon="fire" size="sm" type="button" href={bridgeURL}>
Declare Incident Declare Incident
</Button> </LinkButton>
)} )}
</> </>
); );

@ -172,7 +172,7 @@ export const RuleDetailsActionButtons: FC<Props> = ({ rule, rulesSource, isViewM
if (isFiringRule) { if (isFiringRule) {
buttons.push( buttons.push(
<Fragment key="declare-incident"> <Fragment key="declare-incident">
<DeclareIncident title={rule.name} /> <DeclareIncident title={rule.name} url={buildShareUrl()} />
</Fragment> </Fragment>
); );
} }

Loading…
Cancel
Save