Skip to content

Commit

Permalink
Alerting: Fixes clone url for instances hosted on sub path (#70543)
Browse files Browse the repository at this point in the history
  • Loading branch information
gillesdemey authored and LudoVio committed Jun 26, 2023
1 parent 3dfdd96 commit ee576ae
Showing 1 changed file with 6 additions and 9 deletions.
Expand Up @@ -7,7 +7,6 @@ import { ConfirmModal, LinkButton, useStyles2 } from '@grafana/ui';
import { RuleIdentifier } from 'app/types/unified-alerting';

import * as ruleId from '../../utils/rule-id';
import { createUrl } from '../../utils/url';

interface CloneRuleButtonProps {
ruleIdentifier: RuleIdentifier;
Expand All @@ -20,10 +19,10 @@ export const CloneRuleButton = React.forwardRef<HTMLAnchorElement, CloneRuleButt
({ text, ruleIdentifier, isProvisioned, className }, ref) => {
// For provisioned rules an additional confirmation step is required
// Users have to be aware that the cloned rule will NOT be marked as provisioned
const [provRuleCloneUrl, setProvRuleCloneUrl] = useState<string | undefined>(undefined);
const [showModal, setShowModal] = useState(false);

const styles = useStyles2(getStyles);
const cloneUrl = createUrl('/alerting/new', { copyFrom: ruleId.stringifyIdentifier(ruleIdentifier) });
const cloneUrl = '/alerting/new?copyFrom=' + ruleId.stringifyIdentifier(ruleIdentifier);

return (
<>
Expand All @@ -35,14 +34,14 @@ export const CloneRuleButton = React.forwardRef<HTMLAnchorElement, CloneRuleButt
variant="secondary"
icon="copy"
href={isProvisioned ? undefined : cloneUrl}
onClick={isProvisioned ? () => setProvRuleCloneUrl(cloneUrl) : undefined}
onClick={isProvisioned ? () => setShowModal(true) : undefined}
ref={ref}
>
{text}
</LinkButton>

<ConfirmModal
isOpen={!!provRuleCloneUrl}
isOpen={showModal}
title="Copy provisioned alert rule"
body={
<div>
Expand All @@ -57,11 +56,9 @@ export const CloneRuleButton = React.forwardRef<HTMLAnchorElement, CloneRuleButt
}
confirmText="Copy"
onConfirm={() => {
if (provRuleCloneUrl) {
locationService.push(provRuleCloneUrl);
}
locationService.push(cloneUrl);
}}
onDismiss={() => setProvRuleCloneUrl(undefined)}
onDismiss={() => setShowModal(false)}
/>
</>
);
Expand Down

0 comments on commit ee576ae

Please sign in to comment.