mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DeleteDashboard: Redirect to home after deleting a dashboard (#78918)
This commit is contained in:
parent
303c3ddc24
commit
8d7314bb9a
@ -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<typeof connector>;
|
||||
|
||||
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);
|
||||
|
@ -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 };
|
||||
};
|
Loading…
Reference in New Issue
Block a user