BrowseDashboards: Append orgId to folder URL (#96029)

* BrowseDashboards: Append orgId to folder URL

* Extract folder URL creation logic
This commit is contained in:
Alex Khomenko 2024-11-07 17:12:45 +02:00 committed by GitHub
parent a45deafc96
commit 6bfb24c7b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -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),
}));
}

View File

@ -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;
}