From 4690d88c52f18f0a1a666f8a59e061bd0a36a421 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:55:20 +0100 Subject: [PATCH] [v11.1.x] BrowseDashboards: Prepend subpath to New Browse Dashboard actions (#89131) BrowseDashboards: Prepend subpath to New Browse Dashboard actions (#89109) (cherry picked from commit c58d09fd81dc9d5e25b6170ed89ee829242514c8) Co-authored-by: Josh Hunt --- .../components/CreateNewButton.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/public/app/features/browse-dashboards/components/CreateNewButton.tsx b/public/app/features/browse-dashboards/components/CreateNewButton.tsx index c4d20755a72..97af7819b7b 100644 --- a/public/app/features/browse-dashboards/components/CreateNewButton.tsx +++ b/public/app/features/browse-dashboards/components/CreateNewButton.tsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import { useLocation } from 'react-router-dom'; -import { reportInteraction } from '@grafana/runtime'; +import { config, reportInteraction } from '@grafana/runtime'; import { Button, Drawer, Dropdown, Icon, Menu, MenuItem } from '@grafana/ui'; import { getNewDashboardPhrase, @@ -50,11 +50,11 @@ export default function CreateNewButton({ parentFolder, canCreateDashboard, canC label={getNewDashboardPhrase()} onClick={() => reportInteraction('grafana_menu_item_clicked', { - url: addFolderUidToUrl('/dashboard/new', parentFolder?.uid), + url: buildUrl('/dashboard/new', parentFolder?.uid), from: location.pathname, }) } - url={addFolderUidToUrl('/dashboard/new', parentFolder?.uid)} + url={buildUrl('/dashboard/new', parentFolder?.uid)} /> )} {canCreateFolder && setShowNewFolderDrawer(true)} label={getNewFolderPhrase()} />} @@ -63,11 +63,11 @@ export default function CreateNewButton({ parentFolder, canCreateDashboard, canC label={getImportPhrase()} onClick={() => reportInteraction('grafana_menu_item_clicked', { - url: addFolderUidToUrl('/dashboard/import', parentFolder?.uid), + url: buildUrl('/dashboard/import', parentFolder?.uid), from: location.pathname, }) } - url={addFolderUidToUrl('/dashboard/import', parentFolder?.uid)} + url={buildUrl('/dashboard/import', parentFolder?.uid)} /> )} @@ -101,6 +101,7 @@ export default function CreateNewButton({ parentFolder, canCreateDashboard, canC * @param folderUid folder id * @returns url with paramter if folder is present */ -function addFolderUidToUrl(url: string, folderUid: string | undefined) { - return folderUid ? url + '?folderUid=' + folderUid : url; +function buildUrl(url: string, folderUid: string | undefined) { + const baseUrl = folderUid ? url + '?folderUid=' + folderUid : url; + return config.appSubUrl ? config.appSubUrl + baseUrl : baseUrl; }