diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx index a8085f1fc34..d4bc65eeab5 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx @@ -171,6 +171,7 @@ export class PanelEditorUnconnected extends PureComponent { // the user exits the panel editor they aren't prompted to save again this.props.updateSourcePanel(this.props.panel); }, + onDiscard: this.onDiscard, }, }); }; diff --git a/public/app/features/dashboard/components/PanelEditor/state/actions.ts b/public/app/features/dashboard/components/PanelEditor/state/actions.ts index 1dd97d7b05c..1cb8abbbd4b 100644 --- a/public/app/features/dashboard/components/PanelEditor/state/actions.ts +++ b/public/app/features/dashboard/components/PanelEditor/state/actions.ts @@ -8,6 +8,7 @@ import { PanelEditorUIState, setPanelEditorUIState, updateEditorInitState, + setDiscardChanges, } from './reducers'; import { updateLocation } from 'app/core/actions'; import { cleanUpEditPanel, panelModelAndPluginReady } from '../../../state/reducers'; @@ -52,6 +53,11 @@ export function exitPanelEditor(): ThunkResult { }) ); + const onDiscard = () => { + dispatch(setDiscardChanges(true)); + onConfirm(); + }; + const panel = getPanel(); if (shouldDiscardChanges || !panel.libraryPanel) { @@ -71,6 +77,7 @@ export function exitPanelEditor(): ThunkResult { folderId: dashboard!.meta.folderId, isOpen: true, onConfirm, + onDiscard, }, }); }; diff --git a/public/app/features/library-panels/components/SaveLibraryPanelModal/SaveLibraryPanelModal.tsx b/public/app/features/library-panels/components/SaveLibraryPanelModal/SaveLibraryPanelModal.tsx index b2a72bed18e..e09293d08aa 100644 --- a/public/app/features/library-panels/components/SaveLibraryPanelModal/SaveLibraryPanelModal.tsx +++ b/public/app/features/library-panels/components/SaveLibraryPanelModal/SaveLibraryPanelModal.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useCallback, useState } from 'react'; import { Button, HorizontalGroup, Icon, Input, Modal, stylesFactory, useStyles } from '@grafana/ui'; import { GrafanaTheme } from '@grafana/data'; import { css } from 'emotion'; @@ -14,9 +14,17 @@ interface Props { isOpen: boolean; onConfirm: () => void; onDismiss: () => void; + onDiscard: () => void; } -export const SaveLibraryPanelModal: React.FC = ({ panel, folderId, isOpen, onDismiss, onConfirm }: Props) => { +export const SaveLibraryPanelModal: React.FC = ({ + panel, + folderId, + isOpen, + onDismiss, + onConfirm, + onDiscard, +}) => { const [searchString, setSearchString] = useState(''); const connectedDashboardsState = useAsync(async () => { const connectedDashboards = await getLibraryPanelConnectedDashboards(panel.libraryPanel.uid); @@ -50,6 +58,10 @@ export const SaveLibraryPanelModal: React.FC = ({ panel, folderId, isOpen const { saveLibraryPanel } = usePanelSave(); const styles = useStyles(getModalStyles); + const discardAndClose = useCallback(() => { + onDiscard(); + onDismiss(); + }, []); return ( @@ -101,6 +113,9 @@ export const SaveLibraryPanelModal: React.FC = ({ panel, folderId, isOpen +