mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: Clean up state after deletion (#50316)
* Dashboard: Clean up after deletion * cleanup * rename cleanUp function
This commit is contained in:
parent
32d4f6ac60
commit
a832b92988
@ -1,12 +1,13 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { sumBy } from 'lodash';
|
import { sumBy } from 'lodash';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { connect, ConnectedProps } from 'react-redux';
|
||||||
import useAsyncFn from 'react-use/lib/useAsyncFn';
|
import useAsyncFn from 'react-use/lib/useAsyncFn';
|
||||||
|
|
||||||
import { Modal, ConfirmModal, Button } from '@grafana/ui';
|
import { Modal, ConfirmModal, Button } from '@grafana/ui';
|
||||||
import { config } from 'app/core/config';
|
import { config } from 'app/core/config';
|
||||||
|
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
||||||
import { DashboardModel, PanelModel } from '../../state';
|
import { cleanUpDashboardAndVariables } from 'app/features/dashboard/state/actions';
|
||||||
|
|
||||||
import { useDashboardDelete } from './useDashboardDelete';
|
import { useDashboardDelete } from './useDashboardDelete';
|
||||||
|
|
||||||
@ -15,9 +16,17 @@ type DeleteDashboardModalProps = {
|
|||||||
dashboard: DashboardModel;
|
dashboard: DashboardModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DeleteDashboardModal: React.FC<DeleteDashboardModalProps> = ({ hideModal, dashboard }) => {
|
const mapDispatchToProps = {
|
||||||
|
cleanUpDashboardAndVariables,
|
||||||
|
};
|
||||||
|
|
||||||
|
const connector = connect(null, mapDispatchToProps);
|
||||||
|
|
||||||
|
type Props = DeleteDashboardModalProps & ConnectedProps<typeof connector>;
|
||||||
|
|
||||||
|
const DeleteDashboardModalUnconnected: React.FC<Props> = ({ hideModal, cleanUpDashboardAndVariables, dashboard }) => {
|
||||||
const isProvisioned = dashboard.meta.provisioned;
|
const isProvisioned = dashboard.meta.provisioned;
|
||||||
const { onDeleteDashboard } = useDashboardDelete(dashboard.uid);
|
const { onDeleteDashboard } = useDashboardDelete(dashboard.uid, cleanUpDashboardAndVariables);
|
||||||
|
|
||||||
const [, onConfirm] = useAsyncFn(async () => {
|
const [, onConfirm] = useAsyncFn(async () => {
|
||||||
await onDeleteDashboard();
|
await onDeleteDashboard();
|
||||||
@ -98,3 +107,5 @@ const ProvisionedDeleteModal = ({ hideModal, provisionedId }: { hideModal(): voi
|
|||||||
</Modal.ButtonRow>
|
</Modal.ButtonRow>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const DeleteDashboardModal = connector(DeleteDashboardModalUnconnected);
|
||||||
|
@ -5,16 +5,17 @@ import { locationService } from '@grafana/runtime';
|
|||||||
import { useAppNotification } from 'app/core/copy/appNotification';
|
import { useAppNotification } from 'app/core/copy/appNotification';
|
||||||
import { deleteDashboard } from 'app/features/manage-dashboards/state/actions';
|
import { deleteDashboard } from 'app/features/manage-dashboards/state/actions';
|
||||||
|
|
||||||
export const useDashboardDelete = (uid: string) => {
|
export const useDashboardDelete = (uid: string, cleanUpDashboardAndVariables: () => void) => {
|
||||||
const [state, onDeleteDashboard] = useAsyncFn(() => deleteDashboard(uid, false), []);
|
const [state, onDeleteDashboard] = useAsyncFn(() => deleteDashboard(uid, false), []);
|
||||||
const notifyApp = useAppNotification();
|
const notifyApp = useAppNotification();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state.value) {
|
if (state.value) {
|
||||||
|
cleanUpDashboardAndVariables();
|
||||||
locationService.replace('/');
|
locationService.replace('/');
|
||||||
notifyApp.success('Dashboard Deleted', `${state.value.title} has been deleted`);
|
notifyApp.success('Dashboard Deleted', `${state.value.title} has been deleted`);
|
||||||
}
|
}
|
||||||
}, [state, notifyApp]);
|
}, [state, notifyApp, cleanUpDashboardAndVariables]);
|
||||||
|
|
||||||
return { state, onDeleteDashboard };
|
return { state, onDeleteDashboard };
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user