import { useState } from 'react'; import { config, reportInteraction } from '@grafana/runtime'; import { Alert, ConfirmModal, Text, Space } from '@grafana/ui'; import { Trans, t } from 'app/core/internationalization'; import { useGetAffectedItemsQuery } from '../../api/browseDashboardsAPI'; import { DashboardTreeSelection } from '../../types'; import { DescendantCount } from './DescendantCount'; export interface Props { isOpen: boolean; onConfirm: () => Promise; onDismiss: () => void; selectedItems: DashboardTreeSelection; } export const DeleteModal = ({ onConfirm, onDismiss, selectedItems, ...props }: Props) => { const { data } = useGetAffectedItemsQuery(selectedItems); const deleteIsInvalid = Boolean(data && (data.alertRule || data.libraryPanel)); const [isDeleting, setIsDeleting] = useState(false); const onDelete = async () => { reportInteraction('grafana_manage_dashboards_delete_clicked', { item_counts: { dashboard: Object.keys(selectedItems.dashboard).length, folder: Object.keys(selectedItems.folder).length, }, source: 'browse_dashboards', restore_enabled: Boolean(config.featureToggles.dashboardRestore), }); setIsDeleting(true); try { await onConfirm(); setIsDeleting(false); onDismiss(); } catch { setIsDeleting(false); } }; return ( {config.featureToggles.dashboardRestore && ( <> This action will delete the selected folders immediately but the selected dashboards will be marked for deletion in 30 days. Your organization administrator can restore the dashboards anytime before the 30 days expire. Folders cannot be restored. )} This action will delete the following content: } description={ <> {deleteIsInvalid ? ( One or more folders contain library panels or alert rules. Delete these first in order to proceed. ) : null} } confirmationText={t('browse-dashboards.action.confirmation-text', 'Delete')} confirmText={ isDeleting ? t('browse-dashboards.action.deleting', 'Deleting...') : t('browse-dashboards.action.delete-button', 'Delete') } onDismiss={onDismiss} onConfirm={onDelete} title={t('browse-dashboards.action.delete-modal-title', 'Delete')} {...props} disabled={deleteIsInvalid} /> ); };