Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alerting: Fixes clone url for instances hosted on sub path #70543

Merged
merged 1 commit into from Jun 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why the state was previously tracking the same value as cloneUrl, it's always computed when the component is rendered and we were always using a boolean check for this value anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me neither 😅 The change looks good!


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