From d8363bdfcf02190ed2ba490b85caa7453db827aa Mon Sep 17 00:00:00 2001 From: Yunwen Zheng Date: Tue, 11 Nov 2025 13:02:42 -0500 Subject: [PATCH] SaveProvisionedDashboardForm: When comment is edited, enable save button (#113686) SaveProvisionedDashboardForm: When comment is edit, enable save button --- .../SaveProvisionedDashboardForm.test.tsx | 32 +++++++++++++++++++ .../SaveProvisionedDashboardForm.tsx | 13 ++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.test.tsx b/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.test.tsx index f74f7ddd949..bca9ca1939c 100644 --- a/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.test.tsx +++ b/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.test.tsx @@ -413,4 +413,36 @@ describe('SaveProvisionedDashboardForm', () => { // Branch field is not shown expect(screen.queryByRole('textbox', { name: /branch/i })).not.toBeInTheDocument(); }); + + it('enables save button when only the comment changes', async () => { + const { user } = setup({ + dashboard: { + useState: () => ({ + meta: { + folderUid: 'folder-uid', + slug: 'test-dashboard', + k8s: { name: 'test-dashboard' }, + }, + title: 'Test Dashboard', + description: 'Test Description', + isDirty: false, + }), + setState: jest.fn(), + closeModal: jest.fn(), + getSaveAsModel: jest.fn().mockReturnValue({}), + setManager: jest.fn(), + } as unknown as DashboardScene, + }); + + const commentInput = screen.getByRole('textbox', { name: /comment/i }); + const saveButton = screen.getByRole('button', { name: /save/i }); + + expect(saveButton).toBeDisabled(); + + await user.type(commentInput, 'Comment-only change'); + + await waitFor(() => { + expect(saveButton).toBeEnabled(); + }); + }); }); diff --git a/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.tsx b/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.tsx index a807ada4911..effa2e5c0e7 100644 --- a/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.tsx +++ b/public/app/features/provisioning/components/Dashboards/SaveProvisionedDashboardForm.tsx @@ -55,7 +55,16 @@ export function SaveProvisionedDashboardForm({ const [createOrUpdateFile, request] = useCreateOrUpdateRepositoryFile(isNew ? undefined : defaultValues.path); const methods = useForm({ defaultValues }); - const { handleSubmit, watch, control, reset, register } = methods; + const { + handleSubmit, + watch, + control, + reset, + register, + formState: { dirtyFields }, + } = methods; + // button enabled if form comment is dirty or dashboard state is dirty + const isDirtyState = Boolean(dirtyFields.comment) || isDirty; const [workflow, ref, path] = watch(['workflow', 'ref', 'path']); // Update the form if default values change @@ -282,7 +291,7 @@ export function SaveProvisionedDashboardForm({ -