Files
Torkel Ödegaard e6f2b10a36 ChangeTracker: Unified unsaved changes handling with library panels (#34989)
* UnsavedChanges: Move Change tracker to use Prompt

* Fix a lot of race conditions and stacking of changes in onConfirm and onDismiss

* Listen to save event

* add missing delay argument

* migrated the change tracker unit tests

* Updated snapshot

* Removed unessary action

* removed updateSourcePanel

* Fix hiding save library panel modal prompt when clicking discard

* change saved libray panel title and buttons so they are a bit different as Prompt and when used from save button

* Fixed issue with saving new dashboard

* Now all scenarios work

* increase wait time

* Fixed one more race condition
2021-06-02 12:24:19 +02:00

43 lines
1.1 KiB
TypeScript

import React from 'react';
import { Button, Modal } from '@grafana/ui';
import { SaveDashboardButton } from './SaveDashboardButton';
import { DashboardModel } from '../../state';
import { css } from '@emotion/css';
interface UnsavedChangesModalProps {
dashboard: DashboardModel;
onDiscard: () => void;
onDismiss: () => void;
onSaveSuccess?: () => void;
}
export const UnsavedChangesModal: React.FC<UnsavedChangesModalProps> = ({
dashboard,
onSaveSuccess,
onDiscard,
onDismiss,
}) => {
return (
<Modal
isOpen={true}
title="Unsaved changes"
onDismiss={onDismiss}
icon="exclamation-triangle"
className={css`
width: 500px;
`}
>
<h5>Do you want to save your changes?</h5>
<Modal.ButtonRow>
<Button variant="secondary" onClick={onDismiss} fill="outline">
Cancel
</Button>
<Button variant="destructive" onClick={onDiscard}>
Discard
</Button>
<SaveDashboardButton dashboard={dashboard} onSaveSuccess={onSaveSuccess} />
</Modal.ButtonRow>
</Modal>
);
};