mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
81e955e6b5
* BackendSrv: Observable all the way POC * starting to unify code paths * tests pass * Unified error handling * Single request path and error handling * Fixed ts issue * another ts issu * Added back old requestId cancellation * Slow progress trying to grasp the full picture of cancellation * Updates * refactoring * Remove a bunch of stuff from backendSrv * Removed another function * Do not show error alerts for data queries * Muu * Updated comment * fixed ts issue * unify request options type * Made query inspector subscribe to backendSrv stream instead of legacy app events * Add back support for err.isHandled to limit scope * never show success alerts * Updated tests * Fixing tests * Minor weak * Improved logic for the showErrorAlert and showSuccessAlert boolean flags, now they work more logically * Fix issue
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import React, { FC } from 'react';
|
|
import { css } from 'emotion';
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
import { ConfirmModal, stylesFactory, useTheme } from '@grafana/ui';
|
|
import { getLocationSrv } from '@grafana/runtime';
|
|
import { DashboardSection, OnDeleteItems } from '../types';
|
|
import { getCheckedUids } from '../utils';
|
|
import { deleteFoldersAndDashboards } from 'app/features/manage-dashboards/state/actions';
|
|
|
|
interface Props {
|
|
onDeleteItems: OnDeleteItems;
|
|
results: DashboardSection[];
|
|
isOpen: boolean;
|
|
onDismiss: () => void;
|
|
}
|
|
|
|
export const ConfirmDeleteModal: FC<Props> = ({ results, onDeleteItems, isOpen, onDismiss }) => {
|
|
const theme = useTheme();
|
|
const styles = getStyles(theme);
|
|
|
|
const uids = getCheckedUids(results);
|
|
const { folders, dashboards } = uids;
|
|
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 of the selected folder${folderEnding} will also be deleted`;
|
|
} else if (folderCount > 0) {
|
|
text += `selected folder${folderEnding} and all its dashboards?`;
|
|
} else {
|
|
text += `selected dashboard${dashEnding}?`;
|
|
}
|
|
|
|
const deleteItems = () => {
|
|
deleteFoldersAndDashboards(folders, dashboards).then(() => {
|
|
onDismiss();
|
|
// Redirect to /dashboard in case folder was deleted from f/:folder.uid
|
|
getLocationSrv().update({ path: '/dashboards' });
|
|
onDeleteItems(folders, dashboards);
|
|
});
|
|
};
|
|
|
|
return isOpen ? (
|
|
<ConfirmModal
|
|
isOpen={isOpen}
|
|
title="Delete"
|
|
body={
|
|
<>
|
|
{text} {subtitle && <div className={styles.subtitle}>{subtitle}</div>}
|
|
</>
|
|
}
|
|
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};
|
|
`,
|
|
};
|
|
});
|