import { css } from '@emotion/css'; import { sumBy } from 'lodash'; import React from 'react'; import { connect, ConnectedProps } from 'react-redux'; import useAsyncFn from 'react-use/lib/useAsyncFn'; 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'; type DeleteDashboardModalProps = { hideModal(): void; dashboard: DashboardModel; }; const mapDispatchToProps = { cleanUpDashboardAndVariables, }; const connector = connect(null, mapDispatchToProps); type Props = DeleteDashboardModalProps & ConnectedProps; const DeleteDashboardModalUnconnected: React.FC = ({ hideModal, cleanUpDashboardAndVariables, dashboard }) => { const isProvisioned = dashboard.meta.provisioned; const { onDeleteDashboard } = useDashboardDelete(dashboard.uid, cleanUpDashboardAndVariables); const [, onConfirm] = useAsyncFn(async () => { await onDeleteDashboard(); hideModal(); }, [hideModal]); const modalBody = getModalBody(dashboard.panels, dashboard.title); if (isProvisioned) { return ; } return ( ); }; const getModalBody = (panels: PanelModel[], title: string) => { const totalAlerts = sumBy(panels, (panel) => (panel.alert ? 1 : 0)); return totalAlerts > 0 && !config.unifiedAlertingEnabled ? ( <>

Do you want to delete this dashboard?

This dashboard contains {totalAlerts} alert{totalAlerts > 1 ? 's' : ''}. Deleting this dashboard also deletes those alerts.

) : ( <>

Do you want to delete this dashboard?

{title}

); }; const ProvisionedDeleteModal = ({ hideModal, provisionedId }: { hideModal(): void; provisionedId: string }) => (

This dashboard is managed by Grafana provisioning and cannot be deleted. Remove the dashboard from the config file to delete it.

See{' '} documentation {' '} for more information about provisioning.
File path: {provisionedId}

); export const DeleteDashboardModal = connector(DeleteDashboardModalUnconnected);