From 37fde2eec6a3d3289ab2dccec369f3e129617055 Mon Sep 17 00:00:00 2001 From: Vadim Beskrovnov Date: Fri, 26 Aug 2022 11:25:40 +0100 Subject: [PATCH] Dashboard save: Persist details message when navigating through dashboard save drawer's tabs. (#54084) * Dashboard: Fix `changes note` textarea to save draft when going to other tabs * Do not show Changes tab if there are no changes * Fix comments Co-authored-by: Dominik Prokop --- .../SaveDashboard/SaveDashboardDrawer.tsx | 4 +- .../forms/SaveDashboardForm.test.tsx | 29 +++++ .../SaveDashboard/forms/SaveDashboardForm.tsx | 100 ++++++++++-------- 3 files changed, 90 insertions(+), 43 deletions(-) diff --git a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDrawer.tsx b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDrawer.tsx index 102fb08b394..6addf5d65a8 100644 --- a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDrawer.tsx +++ b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDrawer.tsx @@ -153,7 +153,9 @@ export const SaveDashboardDrawer = ({ dashboard, onDismiss, onSaveSuccess, isCop tabs={ setShowDiff(false)} /> - setShowDiff(true)} counter={data.diffCount} /> + {data.hasChanges && ( + setShowDiff(true)} counter={data.diffCount} /> + )} } expandable diff --git a/public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardForm.test.tsx b/public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardForm.test.tsx index 78e2dbfe462..538b91de9d4 100644 --- a/public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardForm.test.tsx +++ b/public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardForm.test.tsx @@ -119,4 +119,33 @@ describe('SaveDashboardAsForm', () => { }); }); }); + describe('saved message draft rendered', () => { + it('renders saved message draft if it was filled before', () => { + render( + {}} + onSuccess={() => {}} + onSubmit={async () => { + return {}; + }} + saveModel={{ + clone: new DashboardModel({}), + diff: {}, + diffCount: 0, + hasChanges: true, + }} + options={{ message: 'Saved draft' }} + onOptionsChange={(opts: SaveDashboardOptions) => { + return; + }} + /> + ); + + const messageTextArea = screen.getByLabelText('message'); + + expect(messageTextArea).toBeInTheDocument(); + expect(messageTextArea).toHaveTextContent('Saved draft'); + }); + }); }); diff --git a/public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardForm.tsx b/public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardForm.tsx index 177da94a803..1912aec84d9 100644 --- a/public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardForm.tsx +++ b/public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardForm.tsx @@ -56,53 +56,69 @@ export const SaveDashboardForm = ({ } }} > - {({ register, errors }) => ( - - {hasTimeChanged && ( - + {({ register, errors }) => { + const messageProps = register('message'); + return ( + + {hasTimeChanged && ( + + onOptionsChange({ + ...options, + saveTimerange: !options.saveTimerange, + }) + } + label="Save current time range as dashboard default" + aria-label={selectors.pages.SaveDashboardModal.saveTimerange} + /> + )} + {hasVariableChanged && ( + + onOptionsChange({ + ...options, + saveVariables: !options.saveVariables, + }) + } + label="Save current variable values as dashboard default" + aria-label={selectors.pages.SaveDashboardModal.saveVariables} + /> + )} +