Skip to content

Commit f7416fe

Browse files
committed
Fix view source
1 parent 67a00a4 commit f7416fe

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

public/app/features/alerting/unified/components/alert-groups/AlertDetails.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css } from '@emotion/css';
2-
import React from 'react';
2+
import React, {useMemo} from 'react';
33

44
import { GrafanaTheme2 } from '@grafana/data';
55
import { LinkButton, useStyles2 } from '@grafana/ui';
@@ -27,6 +27,15 @@ export const AlertDetails = ({ alert, alertManagerSourceName }: AmNotificationsA
2727
const isSeeSourceButtonEnabled = isGrafanaSource
2828
? contextSrv.hasPermission(AccessControlAction.AlertingRuleRead)
2929
: true;
30+
// LOGZ.IO CHANGE :: DEV-46517 - fix "see source button"
31+
const generatorURL = useMemo(() => {
32+
if (alert.generatorURL) {
33+
const url = new URL(alert.generatorURL);
34+
return url.hash.replace(/^#.dashboard.metrics/, '/grafana-app');
35+
}
36+
return '';
37+
}, [alert.generatorURL]);
38+
// LOGZ.IO CHANGE :: DEV-46517 - fix "see source button" end
3039

3140
return (
3241
<>
@@ -58,8 +67,8 @@ export const AlertDetails = ({ alert, alertManagerSourceName }: AmNotificationsA
5867
</LinkButton>
5968
</Authorize>
6069
)}
61-
{isSeeSourceButtonEnabled && alert.generatorURL && (
62-
<LinkButton className={styles.button} href={alert.generatorURL} icon={'chart-line'} size={'sm'}>
70+
{isSeeSourceButtonEnabled && generatorURL && ( /* LOGZ.IO CHANGE :: DEV-46517 - fix "see source button" */
71+
<LinkButton className={styles.button} href={generatorURL} icon={'chart-line'} size={'sm'}>
6372
See source
6473
</LinkButton>
6574
)}

public/app/plugins/panel/alertGroups/AlertGroup.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ export const AlertGroup = ({ alertManagerSourceName, group, expandAll }: Props)
4242
start: new Date(alert.startsAt),
4343
end: Date.now(),
4444
});
45-
45+
4646
// LOGZ.IO CHANGE :: DEV-46517 - fix "see source button"
47-
if (alert.generatorURL) {
47+
const generatorURL = alert.generatorURL ? (() => {
4848
const url = new URL(alert.generatorURL);
49-
alert.generatorURL = url.hash.replace(/^#/, '/grafana-app');
50-
}
49+
return url.hash.replace(/^#.dashboard.metrics/, '/grafana-app');
50+
})() : null;
5151
// LOGZ.IO CHANGE :: DEV-46517 - fix "see source button" end
52-
52+
5353
return (
5454
<div data-testid={'alert-group-alert'} className={styles.alert} key={`${alert.fingerprint}-${index}`}>
5555
<div>
@@ -82,9 +82,9 @@ export const AlertGroup = ({ alertManagerSourceName, group, expandAll }: Props)
8282
Silence
8383
</LinkButton>
8484
)}
85-
{ /* LOGZ.IO CHANGE :: DEV-46517 - add link target to _top */ }
86-
{alert.generatorURL && (
87-
<LinkButton target="_top" className={styles.button} href={alert.generatorURL} icon={'chart-line'} size={'sm'}>
85+
{ /* LOGZ.IO CHANGE :: DEV-46517 - patch the link url to work inside iframe */ }
86+
{generatorURL && (
87+
<LinkButton className={styles.button} href={generatorURL} icon={'chart-line'} size={'sm'}>
8888
See source
8989
</LinkButton>
9090
)}

0 commit comments

Comments
 (0)