diff --git a/public/app/features/browse-dashboards/components/RecentlyDeletedActions.tsx b/public/app/features/browse-dashboards/components/RecentlyDeletedActions.tsx index 6e065e98220..0dddedf7c39 100644 --- a/public/app/features/browse-dashboards/components/RecentlyDeletedActions.tsx +++ b/public/app/features/browse-dashboards/components/RecentlyDeletedActions.tsx @@ -33,7 +33,13 @@ export function RecentlyDeletedActions() { if (searchState.result) { for (const selectedDashboard of selectedDashboards) { const index = searchState.result.view.fields.uid.values.findIndex((e) => e === selectedDashboard); - selectedDashboardOrigin.push(searchState.result.view.fields.location.values[index]); + + // SQLSearcher changes the location from empty string to 'general' for items with no parent + // but the restore API doesn't work with 'general' folder UID, so we need to convert it back + // to an empty string + const location = searchState.result.view.fields.location.values[index]; + const fixedLocation = location === GENERAL_FOLDER_UID ? '' : location; + selectedDashboardOrigin.push(fixedLocation); } } diff --git a/public/app/features/browse-dashboards/components/RestoreModal.tsx b/public/app/features/browse-dashboards/components/RestoreModal.tsx index d0e05e0dde7..77561bdd24d 100644 --- a/public/app/features/browse-dashboards/components/RestoreModal.tsx +++ b/public/app/features/browse-dashboards/components/RestoreModal.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react'; +import { useState } from 'react'; import { reportInteraction } from '@grafana/runtime'; import { ConfirmModal, Space, Text } from '@grafana/ui'; @@ -23,19 +23,14 @@ export const RestoreModal = ({ isLoading, ...props }: RestoreModalProps) => { - const [restoreTarget, setRestoreTarget] = useState(); - const numberOfDashboards = selectedDashboards.length; - - useEffect(() => { - // restoreTarget is used by the folder picker to preselect a folder and therefore enable the confirm button - // if there is only one dashboard selected or all selected dashboards come from the same folder - if ( - dashboardOrigin.length > 0 && + const [restoreTarget, setRestoreTarget] = useState(() => { + // Preselect the restore target and therefore enable the confirm button if all selected dashboards come from the same folder + return dashboardOrigin.length > 0 && dashboardOrigin.every((originalLocation) => originalLocation === dashboardOrigin[0]) - ) { - setRestoreTarget(dashboardOrigin[0]); - } - }, [dashboardOrigin, selectedDashboards]); + ? dashboardOrigin[0] + : undefined; + }); + const numberOfDashboards = selectedDashboards.length; const onRestore = async () => { reportInteraction('grafana_restore_confirm_clicked', { diff --git a/public/app/features/search/service/sql.ts b/public/app/features/search/service/sql.ts index d3999434813..3a25678746e 100644 --- a/public/app/features/search/service/sql.ts +++ b/public/app/features/search/service/sql.ts @@ -4,7 +4,7 @@ import { TermCount } from 'app/core/components/TagFilter/TagFilter'; import { backendSrv } from 'app/core/services/backend_srv'; import { PermissionLevelString } from 'app/types'; -import { DEFAULT_MAX_VALUES, TYPE_KIND_MAP } from '../constants'; +import { DEFAULT_MAX_VALUES, GENERAL_FOLDER_UID, TYPE_KIND_MAP } from '../constants'; import { DashboardSearchHit, DashboardSearchItemType } from '../types'; import { LocationInfo } from './types'; @@ -175,7 +175,7 @@ export class SQLSearcher implements GrafanaSearcher { let v = hit.folderUid; if (!v && k === 'dashboard') { - v = 'general'; + v = GENERAL_FOLDER_UID; } location.push(v!);