From 6bfb24c7b0ff2abbc573a9deefa85b580ae4eec4 Mon Sep 17 00:00:00 2001 From: Alex Khomenko Date: Thu, 7 Nov 2024 17:12:45 +0200 Subject: [PATCH] BrowseDashboards: Append orgId to folder URL (#96029) * BrowseDashboards: Append orgId to folder URL * Extract folder URL creation logic --- .../app/features/browse-dashboards/api/services.ts | 5 ++--- .../features/browse-dashboards/components/utils.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/public/app/features/browse-dashboards/api/services.ts b/public/app/features/browse-dashboards/api/services.ts index 3892593ac79..867e33a1129 100644 --- a/public/app/features/browse-dashboards/api/services.ts +++ b/public/app/features/browse-dashboards/api/services.ts @@ -6,7 +6,7 @@ import { DashboardViewItem } from 'app/features/search/types'; import { contextSrv } from '../../../core/core'; import { AccessControlAction } from '../../../types'; -import { isSharedWithMe } from '../components/utils'; +import { getFolderURL, isSharedWithMe } from '../components/utils'; export const PAGE_SIZE = 50; @@ -30,7 +30,6 @@ export async function listFolders( limit: pageSize, }); } - const subUrlPrefix = config.appSubUrl ?? ''; return folders.map((item) => ({ kind: 'folder', @@ -40,7 +39,7 @@ export async function listFolders( parentUID, // URLs from the backend come with subUrlPrefix already included, so match that behaviour here - url: isSharedWithMe(item.uid) ? undefined : `${subUrlPrefix}/dashboards/f/${item.uid}/`, + url: isSharedWithMe(item.uid) ? undefined : getFolderURL(item.uid), })); } diff --git a/public/app/features/browse-dashboards/components/utils.ts b/public/app/features/browse-dashboards/components/utils.ts index cc4485b06b8..af40b5e2f0f 100644 --- a/public/app/features/browse-dashboards/components/utils.ts +++ b/public/app/features/browse-dashboards/components/utils.ts @@ -1,4 +1,5 @@ import { config } from '@grafana/runtime'; +import { contextSrv } from 'app/core/core'; import { DashboardViewItemWithUIItems } from '../types'; @@ -9,3 +10,15 @@ export function makeRowID(baseId: string, item: DashboardViewItemWithUIItems) { export function isSharedWithMe(uid: string) { return uid === config.sharedWithMeFolderUID; } + +// Construct folder URL and append orgId to it +export function getFolderURL(uid: string) { + const { orgId } = contextSrv.user; + const subUrlPrefix = config.appSubUrl ?? ''; + const url = `${subUrlPrefix}/dashboards/f/${uid}/`; + + if (orgId) { + return `${url}?orgId=${orgId}`; + } + return url; +}