From 8d7314bb9a296fb9f8bf1e4f9a21cf478bb5945d Mon Sep 17 00:00:00 2001 From: Ivan Ortega Alba Date: Fri, 1 Dec 2023 10:15:41 +0100 Subject: [PATCH] DeleteDashboard: Redirect to home after deleting a dashboard (#78918) --- .../DeleteDashboard/DeleteDashboardModal.tsx | 9 ++++---- .../DeleteDashboard/useDashboardDelete.tsx | 21 ------------------- 2 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 public/app/features/dashboard/components/DeleteDashboard/useDashboardDelete.tsx diff --git a/public/app/features/dashboard/components/DeleteDashboard/DeleteDashboardModal.tsx b/public/app/features/dashboard/components/DeleteDashboard/DeleteDashboardModal.tsx index 389518dc204..82ae09f6c11 100644 --- a/public/app/features/dashboard/components/DeleteDashboard/DeleteDashboardModal.tsx +++ b/public/app/features/dashboard/components/DeleteDashboard/DeleteDashboardModal.tsx @@ -4,12 +4,12 @@ import React from 'react'; import { connect, ConnectedProps } from 'react-redux'; import useAsyncFn from 'react-use/lib/useAsyncFn'; +import { locationService } from '@grafana/runtime'; import { Modal, ConfirmModal, Button } from '@grafana/ui'; import { config } from 'app/core/config'; import { DashboardModel, PanelModel } from 'app/features/dashboard/state'; import { cleanUpDashboardAndVariables } from 'app/features/dashboard/state/actions'; - -import { useDashboardDelete } from './useDashboardDelete'; +import { deleteDashboard } from 'app/features/manage-dashboards/state/actions'; type DeleteDashboardModalProps = { hideModal(): void; @@ -26,11 +26,12 @@ type Props = DeleteDashboardModalProps & ConnectedProps; const DeleteDashboardModalUnconnected = ({ hideModal, cleanUpDashboardAndVariables, dashboard }: Props) => { const isProvisioned = dashboard.meta.provisioned; - const { onDeleteDashboard } = useDashboardDelete(dashboard.uid, cleanUpDashboardAndVariables); const [, onConfirm] = useAsyncFn(async () => { - await onDeleteDashboard(); + await deleteDashboard(dashboard.uid, true); + cleanUpDashboardAndVariables(); hideModal(); + locationService.replace('/'); }, [hideModal]); const modalBody = getModalBody(dashboard.panels, dashboard.title); diff --git a/public/app/features/dashboard/components/DeleteDashboard/useDashboardDelete.tsx b/public/app/features/dashboard/components/DeleteDashboard/useDashboardDelete.tsx deleted file mode 100644 index 630ae39be28..00000000000 --- a/public/app/features/dashboard/components/DeleteDashboard/useDashboardDelete.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { useEffect } from 'react'; -import { useAsyncFn } from 'react-use'; - -import { locationService } from '@grafana/runtime'; -import { useAppNotification } from 'app/core/copy/appNotification'; -import { deleteDashboard } from 'app/features/manage-dashboards/state/actions'; - -export const useDashboardDelete = (uid: string, cleanUpDashboardAndVariables: () => void) => { - const [state, onDeleteDashboard] = useAsyncFn(() => deleteDashboard(uid, false), []); - const notifyApp = useAppNotification(); - - useEffect(() => { - if (state.value) { - cleanUpDashboardAndVariables(); - locationService.replace('/'); - notifyApp.success('Dashboard Deleted', `${state.value.title} has been deleted`); - } - }, [state, notifyApp, cleanUpDashboardAndVariables]); - - return { state, onDeleteDashboard }; -};