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
This commit is contained in:
Laura Benz
2024-08-27 14:06:23 +03:00
committed by GitHub
parent a99e32947a
commit 6950093911
2 changed files with 11 additions and 6 deletions
@@ -29,11 +29,11 @@ export function RecentlyDeletedActions() {
.map(([uid]) => uid);
}, [selectedItemsState.dashboard]);
const dashboardOrigin: Record<string, string> = {};
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,
},
@@ -11,7 +11,7 @@ export interface RestoreModalProps {
onConfirm: (restoreTarget: string) => Promise<void>;
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]);