From d86fc082fbfc087e0b7ae9ea15df2b0ce9f618dc Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Tue, 27 Sep 2022 16:46:49 -0400 Subject: [PATCH] Links: Fix opening links from different orgs on the same tab (#55837) (#55869) * Skip intercepting links of different orgs * Check if orgId is present on query params * Use locationSearchToObject instead of parseKeyValue * Revert locationSearchToObject to parseKeyValue (cherry picked from commit 2a126447789ce5e2110c1acd011695a654e11ff7) Co-authored-by: Guilherme Caulada --- public/app/core/navigation/patch/interceptLinkClicks.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/public/app/core/navigation/patch/interceptLinkClicks.ts b/public/app/core/navigation/patch/interceptLinkClicks.ts index 377a3413ab0..95cefccc6a4 100644 --- a/public/app/core/navigation/patch/interceptLinkClicks.ts +++ b/public/app/core/navigation/patch/interceptLinkClicks.ts @@ -1,5 +1,6 @@ -import { locationUtil } from '@grafana/data'; +import { locationUtil, urlUtil } from '@grafana/data'; import { locationService, navigationLogger } from '@grafana/runtime'; +import { config } from 'app/core/config'; export function interceptLinkClicks(e: MouseEvent) { const anchor = getParentAnchor(e.target as HTMLElement); @@ -14,6 +15,8 @@ export function interceptLinkClicks(e: MouseEvent) { const target = anchor.getAttribute('target'); if (href && !target) { + const params = urlUtil.parseKeyValue(href.split('?')[1]); + const orgIdChange = params.orgId && Number(params.orgId) !== config.bootData.user.orgId; navigationLogger('utils', false, 'intercepting link click', e); e.preventDefault(); @@ -22,9 +25,9 @@ export function interceptLinkClicks(e: MouseEvent) { // Ensure old angular urls with no starting '/' are handled the same as before // Make sure external links are handled correctly // That is they where seen as being absolute from app root - if (href[0] !== '/') { + if (href[0] !== '/' || orgIdChange) { // if still contains protocol or is a mailto link, it's an absolute link to another domain or web application - if (href.indexOf('://') > 0 || href.indexOf('mailto:') === 0) { + if (href.indexOf('://') > 0 || href.indexOf('mailto:') === 0 || orgIdChange) { window.location.href = href; return; } else if (href.indexOf('#') === 0) {