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 { RuleIdentifier } from 'app/types/unified-alerting';
|
||||||
|
|
||||||
import * as ruleId from '../../utils/rule-id';
|
import * as ruleId from '../../utils/rule-id';
|
||||||
import { createUrl } from '../../utils/url';
|
|
||||||
|
|
||||||
interface CloneRuleButtonProps {
|
interface CloneRuleButtonProps {
|
||||||
ruleIdentifier: RuleIdentifier;
|
ruleIdentifier: RuleIdentifier;
|
||||||
@@ -20,10 +19,10 @@ export const CloneRuleButton = React.forwardRef<HTMLAnchorElement, CloneRuleButt
|
|||||||
({ text, ruleIdentifier, isProvisioned, className }, ref) => {
|
({ text, ruleIdentifier, isProvisioned, className }, ref) => {
|
||||||
// For provisioned rules an additional confirmation step is required
|
// For provisioned rules an additional confirmation step is required
|
||||||
// Users have to be aware that the cloned rule will NOT be marked as provisioned
|
// 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 styles = useStyles2(getStyles);
|
||||||
const cloneUrl = createUrl('/alerting/new', { copyFrom: ruleId.stringifyIdentifier(ruleIdentifier) });
|
const cloneUrl = '/alerting/new?copyFrom=' + ruleId.stringifyIdentifier(ruleIdentifier);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -35,14 +34,14 @@ export const CloneRuleButton = React.forwardRef<HTMLAnchorElement, CloneRuleButt
|
|||||||
variant="secondary"
|
variant="secondary"
|
||||||
icon="copy"
|
icon="copy"
|
||||||
href={isProvisioned ? undefined : cloneUrl}
|
href={isProvisioned ? undefined : cloneUrl}
|
||||||
onClick={isProvisioned ? () => setProvRuleCloneUrl(cloneUrl) : undefined}
|
onClick={isProvisioned ? () => setShowModal(true) : undefined}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
>
|
>
|
||||||
{text}
|
{text}
|
||||||
</LinkButton>
|
</LinkButton>
|
||||||
|
|
||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
isOpen={!!provRuleCloneUrl}
|
isOpen={showModal}
|
||||||
title="Copy provisioned alert rule"
|
title="Copy provisioned alert rule"
|
||||||
body={
|
body={
|
||||||
<div>
|
<div>
|
||||||
@@ -57,11 +56,9 @@ export const CloneRuleButton = React.forwardRef<HTMLAnchorElement, CloneRuleButt
|
|||||||
}
|
}
|
||||||
confirmText="Copy"
|
confirmText="Copy"
|
||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
if (provRuleCloneUrl) {
|
locationService.push(cloneUrl);
|
||||||
locationService.push(provRuleCloneUrl);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
onDismiss={() => setProvRuleCloneUrl(undefined)}
|
onDismiss={() => setShowModal(false)}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user