From 991b016d63196b5bbb101ba48219e7c246ebd1e2 Mon Sep 17 00:00:00 2001 From: Alex Khomenko Date: Tue, 1 Apr 2025 17:23:20 +0300 Subject: [PATCH] Provisioning: Clear dashboard editor state (#103190) * Provisioning: Clear dashboard editor state * Clear the changes after save * Revert some changes * Add dep * Fix tests --- .../saving/provisioned/SaveProvisionedDashboardForm.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.tsx b/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.tsx index ff2dfff60ab..9b082028799 100644 --- a/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.tsx +++ b/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.tsx @@ -59,7 +59,7 @@ export function SaveProvisionedDashboardForm({ }: Props) { const navigate = useNavigate(); const appEvents = getAppEvents(); - const { meta, isDirty } = dashboard.useState(); + const { meta, isDirty, editPanel: panelEditor } = dashboard.useState(); const [createOrUpdateFile, request] = useCreateOrUpdateRepositoryFile(isNew ? undefined : defaultValues.path); @@ -71,7 +71,6 @@ export function SaveProvisionedDashboardForm({ control, reset, } = useForm({ defaultValues }); - const [ref, workflow, path] = watch(['ref', 'workflow', 'path']); // Update the form if default values change @@ -82,7 +81,10 @@ export function SaveProvisionedDashboardForm({ useEffect(() => { if (request.isSuccess) { dashboard.setState({ isDirty: false }); + if (workflow === 'branch' && ref !== '' && path !== '') { + dashboard.closeModal(); + panelEditor?.onDiscard(); // Redirect to the provisioning preview pages navigate(`${PROVISIONING_URL}/${defaultValues.repo}/dashboard/preview/${path}?ref=${ref}`); return; @@ -124,7 +126,7 @@ export function SaveProvisionedDashboardForm({ ], }); } - }, [appEvents, dashboard, defaultValues.repo, isNew, navigate, path, ref, request, workflow]); + }, [appEvents, dashboard, defaultValues.repo, drawer, isNew, navigate, panelEditor, path, ref, request, workflow]); // Submit handler for saving the form data const handleFormSubmit = async ({ title, description, repo, path, comment, ref }: FormData) => {