mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
101 lines
2.7 KiB
TypeScript
101 lines
2.7 KiB
TypeScript
import { css } from '@emotion/css';
|
|
import { sumBy } from 'lodash';
|
|
import React from 'react';
|
|
import useAsyncFn from 'react-use/lib/useAsyncFn';
|
|
|
|
import { Modal, ConfirmModal, Button } from '@grafana/ui';
|
|
import { config } from 'app/core/config';
|
|
|
|
import { DashboardModel, PanelModel } from '../../state';
|
|
|
|
import { useDashboardDelete } from './useDashboardDelete';
|
|
|
|
type DeleteDashboardModalProps = {
|
|
hideModal(): void;
|
|
dashboard: DashboardModel;
|
|
};
|
|
|
|
export const DeleteDashboardModal: React.FC<DeleteDashboardModalProps> = ({ hideModal, dashboard }) => {
|
|
const isProvisioned = dashboard.meta.provisioned;
|
|
const { onDeleteDashboard } = useDashboardDelete(dashboard.uid);
|
|
|
|
const [, onConfirm] = useAsyncFn(async () => {
|
|
await onDeleteDashboard();
|
|
hideModal();
|
|
}, [hideModal]);
|
|
|
|
const modalBody = getModalBody(dashboard.panels, dashboard.title);
|
|
|
|
if (isProvisioned) {
|
|
return <ProvisionedDeleteModal hideModal={hideModal} provisionedId={dashboard.meta.provisionedExternalId!} />;
|
|
}
|
|
|
|
return (
|
|
<ConfirmModal
|
|
isOpen={true}
|
|
body={modalBody}
|
|
onConfirm={onConfirm}
|
|
onDismiss={hideModal}
|
|
title="Delete"
|
|
icon="trash-alt"
|
|
confirmText="Delete"
|
|
/>
|
|
);
|
|
};
|
|
|
|
const getModalBody = (panels: PanelModel[], title: string) => {
|
|
const totalAlerts = sumBy(panels, (panel) => (panel.alert ? 1 : 0));
|
|
return totalAlerts > 0 && !config.unifiedAlertingEnabled ? (
|
|
<>
|
|
<p>Do you want to delete this dashboard?</p>
|
|
<p>
|
|
This dashboard contains {totalAlerts} alert{totalAlerts > 1 ? 's' : ''}. Deleting this dashboard also deletes
|
|
those alerts.
|
|
</p>
|
|
</>
|
|
) : (
|
|
<>
|
|
<p>Do you want to delete this dashboard?</p>
|
|
<p>{title}</p>
|
|
</>
|
|
);
|
|
};
|
|
|
|
const ProvisionedDeleteModal = ({ hideModal, provisionedId }: { hideModal(): void; provisionedId: string }) => (
|
|
<Modal
|
|
isOpen={true}
|
|
title="Cannot delete provisioned dashboard"
|
|
icon="trash-alt"
|
|
onDismiss={hideModal}
|
|
className={css`
|
|
width: 500px;
|
|
`}
|
|
>
|
|
<p>
|
|
This dashboard is managed by Grafana provisioning and cannot be deleted. Remove the dashboard from the config file
|
|
to delete it.
|
|
</p>
|
|
<p>
|
|
<i>
|
|
See{' '}
|
|
<a
|
|
className="external-link"
|
|
href="https://grafana.com/docs/grafana/latest/administration/provisioning/#dashboards"
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
>
|
|
documentation
|
|
</a>{' '}
|
|
for more information about provisioning.
|
|
</i>
|
|
<br />
|
|
File path: {provisionedId}
|
|
</p>
|
|
<Modal.ButtonRow>
|
|
<Button variant="primary" onClick={hideModal}>
|
|
OK
|
|
</Button>
|
|
</Modal.ButtonRow>
|
|
</Modal>
|
|
);
|