mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Routing NG: Fix persistent modal after dashboard delete (#32033)
This commit is contained in:
parent
a97637a133
commit
48eb747da0
@ -4,6 +4,7 @@ import sumBy from 'lodash/sumBy';
|
|||||||
import { Modal, ConfirmModal, HorizontalGroup, Button } from '@grafana/ui';
|
import { Modal, ConfirmModal, HorizontalGroup, Button } from '@grafana/ui';
|
||||||
import { DashboardModel, PanelModel } from '../../state';
|
import { DashboardModel, PanelModel } from '../../state';
|
||||||
import { useDashboardDelete } from './useDashboardDelete';
|
import { useDashboardDelete } from './useDashboardDelete';
|
||||||
|
import useAsyncFn from 'react-use/lib/useAsyncFn';
|
||||||
|
|
||||||
type DeleteDashboardModalProps = {
|
type DeleteDashboardModalProps = {
|
||||||
hideModal(): void;
|
hideModal(): void;
|
||||||
@ -12,7 +13,13 @@ type DeleteDashboardModalProps = {
|
|||||||
|
|
||||||
export const DeleteDashboardModal: React.FC<DeleteDashboardModalProps> = ({ hideModal, dashboard }) => {
|
export const DeleteDashboardModal: React.FC<DeleteDashboardModalProps> = ({ hideModal, dashboard }) => {
|
||||||
const isProvisioned = dashboard.meta.provisioned;
|
const isProvisioned = dashboard.meta.provisioned;
|
||||||
const { onRestoreDashboard } = useDashboardDelete(dashboard.uid);
|
const { onDeleteDashboard } = useDashboardDelete(dashboard.uid);
|
||||||
|
|
||||||
|
const [, onConfirm] = useAsyncFn(async () => {
|
||||||
|
await onDeleteDashboard();
|
||||||
|
hideModal();
|
||||||
|
}, [hideModal]);
|
||||||
|
|
||||||
const modalBody = getModalBody(dashboard.panels, dashboard.title);
|
const modalBody = getModalBody(dashboard.panels, dashboard.title);
|
||||||
|
|
||||||
if (isProvisioned) {
|
if (isProvisioned) {
|
||||||
@ -23,7 +30,7 @@ export const DeleteDashboardModal: React.FC<DeleteDashboardModalProps> = ({ hide
|
|||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
isOpen={true}
|
isOpen={true}
|
||||||
body={modalBody}
|
body={modalBody}
|
||||||
onConfirm={onRestoreDashboard}
|
onConfirm={onConfirm}
|
||||||
onDismiss={hideModal}
|
onDismiss={hideModal}
|
||||||
title="Delete"
|
title="Delete"
|
||||||
icon="trash-alt"
|
icon="trash-alt"
|
||||||
|
@ -6,7 +6,7 @@ import { deleteDashboard } from 'app/features/manage-dashboards/state/actions';
|
|||||||
import { locationService } from '@grafana/runtime';
|
import { locationService } from '@grafana/runtime';
|
||||||
|
|
||||||
export const useDashboardDelete = (uid: string) => {
|
export const useDashboardDelete = (uid: string) => {
|
||||||
const [state, onRestoreDashboard] = useAsyncFn(() => deleteDashboard(uid, false), []);
|
const [state, onDeleteDashboard] = useAsyncFn(() => deleteDashboard(uid, false), []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state.value) {
|
if (state.value) {
|
||||||
@ -15,5 +15,5 @@ export const useDashboardDelete = (uid: string) => {
|
|||||||
}
|
}
|
||||||
}, [state]);
|
}, [state]);
|
||||||
|
|
||||||
return { state, onRestoreDashboard };
|
return { state, onDeleteDashboard };
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user