import { css } from '@emotion/css'; import React, { FC } from 'react'; import { GrafanaTheme } from '@grafana/data'; import { ConfirmModal, stylesFactory, useTheme } from '@grafana/ui'; import { deleteFoldersAndDashboards } from 'app/features/manage-dashboards/state/actions'; import { OnMoveOrDeleleSelectedItems } from '../../types'; interface Props { onDeleteItems: OnMoveOrDeleleSelectedItems; results: Map>; isOpen: boolean; onDismiss: () => void; } export const ConfirmDeleteModal: FC = ({ results, onDeleteItems, isOpen, onDismiss }) => { const theme = useTheme(); const styles = getStyles(theme); const dashboards = Array.from(results.get('dashboard') ?? []); const folders = Array.from(results.get('folder') ?? []); const folderCount = folders.length; const dashCount = dashboards.length; let text = 'Do you want to delete the '; let subtitle; const dashEnding = dashCount === 1 ? '' : 's'; const folderEnding = folderCount === 1 ? '' : 's'; if (folderCount > 0 && dashCount > 0) { text += `selected folder${folderEnding} and dashboard${dashEnding}?\n`; subtitle = `All dashboards and alerts of the selected folder${folderEnding} will also be deleted`; } else if (folderCount > 0) { text += `selected folder${folderEnding} and all ${folderCount === 1 ? 'its' : 'their'} dashboards and alerts?`; } else { text += `${dashCount} selected dashboard${dashEnding}?`; } const deleteItems = () => { deleteFoldersAndDashboards(folders, dashboards).then(() => { onDeleteItems(); onDismiss(); }); }; return isOpen ? ( {text} {subtitle &&
{subtitle}
} } confirmText="Delete" onConfirm={deleteItems} onDismiss={onDismiss} /> ) : null; }; const getStyles = stylesFactory((theme: GrafanaTheme) => { return { subtitle: css` font-size: ${theme.typography.size.base}; padding-top: ${theme.spacing.md}; `, }; });