SaveProvisionedDashboardForm: When comment is edited, enable save button (#113686)

SaveProvisionedDashboardForm: When comment is edit, enable save button
This commit is contained in:
Yunwen Zheng
2025-11-11 13:02:42 -05:00
committed by GitHub
parent 559dab8b1b
commit d8363bdfcf
2 changed files with 43 additions and 2 deletions
@@ -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();
});
});
});
@@ -55,7 +55,16 @@ export function SaveProvisionedDashboardForm({
const [createOrUpdateFile, request] = useCreateOrUpdateRepositoryFile(isNew ? undefined : defaultValues.path);
const methods = useForm<ProvisionedDashboardFormData>({ 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({
<Button variant="secondary" onClick={drawer.onClose} fill="outline">
<Trans i18nKey="dashboard-scene.save-provisioned-dashboard-form.cancel">Cancel</Trans>
</Button>
<Button variant="primary" type="submit" disabled={request.isLoading || !isDirty || readOnly}>
<Button variant="primary" type="submit" disabled={request.isLoading || readOnly || !isDirtyState}>
{request.isLoading
? t('dashboard-scene.save-provisioned-dashboard-form.saving', 'Saving...')
: t('dashboard-scene.save-provisioned-dashboard-form.save', 'Save')}