From 092a1813efd0f14f6b70c866068abbbecdbe034b Mon Sep 17 00:00:00 2001 From: Ieva Date: Wed, 30 Oct 2024 10:48:34 +0000 Subject: [PATCH] Folders: Don't show error pop-up if the user can't fetch the root folder (#95569) don't show error pop-up if the user can't read general folder --- .../app/features/browse-dashboards/BrowseDashboardsPage.tsx | 6 ++++-- .../features/browse-dashboards/api/browseDashboardsAPI.ts | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/public/app/features/browse-dashboards/BrowseDashboardsPage.tsx b/public/app/features/browse-dashboards/BrowseDashboardsPage.tsx index cb56a761ab9..6a8b8788798 100644 --- a/public/app/features/browse-dashboards/BrowseDashboardsPage.tsx +++ b/public/app/features/browse-dashboards/BrowseDashboardsPage.tsx @@ -81,8 +81,10 @@ const BrowseDashboardsPage = memo(() => { const hasSelection = useHasSelection(); - const { data: rootFolder } = useGetFolderQuery('general'); - let folder = folderDTO ? folderDTO : rootFolder; + // Fetch the root (aka general) folder if we're not in a specific folder + const { data: rootFolderDTO } = useGetFolderQuery(folderDTO ? skipToken : 'general'); + const folder = folderDTO ?? rootFolderDTO; + const { canEditFolders, canEditDashboards, canCreateDashboards, canCreateFolders } = getFolderPermissions(folder); const hasAdminRights = contextSrv.hasRole('Admin') || contextSrv.isGrafanaAdmin; diff --git a/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts b/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts index 073e7a51946..915c1aa5896 100644 --- a/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts +++ b/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts @@ -66,12 +66,15 @@ interface HardDeleteDashboardArgs { function createBackendSrvBaseQuery({ baseURL }: { baseURL: string }): BaseQueryFn { async function backendSrvBaseQuery(requestOptions: RequestOptions) { + // Suppress error pop-up for root (aka 'general') folder + const isGeneralFolder = requestOptions.url === `/folders/general`; + requestOptions = isGeneralFolder ? { ...requestOptions, showErrorAlert: false } : requestOptions; + try { const { data: responseData, ...meta } = await lastValueFrom( getBackendSrv().fetch({ ...requestOptions, url: baseURL + requestOptions.url, - showErrorAlert: requestOptions.showErrorAlert, }) ); return { data: responseData, meta };