From 6950093911cdfe5a12b3a479a1ff15e1c796096e Mon Sep 17 00:00:00 2001 From: Laura Benz <48948963+L-M-K-B@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:06:23 +0200 Subject: [PATCH] RestoreDashboards: Set preselected folder in folder picker for restoring several dashboards from the same folder (#92403) * feat: add condition for several dashboards * refactor: clean up * refactor: clean up and comment * refactor: clean up * refactor: clean up --- .../components/RecentlyDeletedActions.tsx | 6 +++--- .../browse-dashboards/components/RestoreModal.tsx | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/public/app/features/browse-dashboards/components/RecentlyDeletedActions.tsx b/public/app/features/browse-dashboards/components/RecentlyDeletedActions.tsx index 8df52a18f84..6e065e98220 100644 --- a/public/app/features/browse-dashboards/components/RecentlyDeletedActions.tsx +++ b/public/app/features/browse-dashboards/components/RecentlyDeletedActions.tsx @@ -29,11 +29,11 @@ export function RecentlyDeletedActions() { .map(([uid]) => uid); }, [selectedItemsState.dashboard]); - const dashboardOrigin: Record = {}; + const selectedDashboardOrigin: string[] = []; if (searchState.result) { for (const selectedDashboard of selectedDashboards) { const index = searchState.result.view.fields.uid.values.findIndex((e) => e === selectedDashboard); - dashboardOrigin[selectedDashboard] = searchState.result.view.fields.location.values[index]; + selectedDashboardOrigin.push(searchState.result.view.fields.location.values[index]); } } @@ -90,7 +90,7 @@ export function RecentlyDeletedActions() { component: RestoreModal, props: { selectedDashboards, - dashboardOrigin, + dashboardOrigin: selectedDashboardOrigin, onConfirm: onRestore, isLoading: isRestoreLoading, }, diff --git a/public/app/features/browse-dashboards/components/RestoreModal.tsx b/public/app/features/browse-dashboards/components/RestoreModal.tsx index e582370a773..d0e05e0dde7 100644 --- a/public/app/features/browse-dashboards/components/RestoreModal.tsx +++ b/public/app/features/browse-dashboards/components/RestoreModal.tsx @@ -11,7 +11,7 @@ export interface RestoreModalProps { onConfirm: (restoreTarget: string) => Promise; onDismiss: () => void; selectedDashboards: string[]; - dashboardOrigin: { [key: string]: string }; + dashboardOrigin: string[]; isLoading: boolean; } @@ -27,8 +27,13 @@ export const RestoreModal = ({ const numberOfDashboards = selectedDashboards.length; useEffect(() => { - if (Object.entries(dashboardOrigin).length === 1 && dashboardOrigin[selectedDashboards[0]] !== 'general') { - setRestoreTarget(dashboardOrigin[selectedDashboards[0]]); + // 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 && + dashboardOrigin.every((originalLocation) => originalLocation === dashboardOrigin[0]) + ) { + setRestoreTarget(dashboardOrigin[0]); } }, [dashboardOrigin, selectedDashboards]);