mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fixes clone url for instances hosted on sub path (#70543)
This commit is contained in:
@@ -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;
|
||||
@@ -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 (
|
||||
<>
|
||||
@@ -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>
|
||||
@@ -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)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user