From 6ffccf825fe4999485058deac7838b4c07bb1bee Mon Sep 17 00:00:00 2001 From: Alex Khomenko Date: Fri, 23 May 2025 12:44:23 +0300 Subject: [PATCH] Provisioning: Fix save form for readOnly repository (#105849) * Provisioning: Fix save form for readOnly repository * betterer --- .betterer.results | 9 ------- .../SaveProvisionedDashboardForm.test.tsx | 19 +++++++++++++-- .../SaveProvisionedDashboardForm.tsx | 24 ++++++++++++------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.betterer.results b/.betterer.results index 9c867b86097..a52202f2626 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1641,15 +1641,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "5"], [0, 0, 0, "Unexpected any. Specify a different type.", "6"] ], - "public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.tsx:5381": [ - [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "0"], - [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "1"], - [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "2"], - [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "3"], - [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "4"], - [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "5"], - [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "6"] - ], "public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], diff --git a/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.test.tsx b/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.test.tsx index 12540d371c9..eec8d44b8d8 100644 --- a/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.test.tsx +++ b/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.test.tsx @@ -390,8 +390,9 @@ describe('SaveProvisionedDashboardForm', () => { expect(screen.getByRole('button', { name: /save/i })).toBeDisabled(); }); - it('should show read-only alert when repository has no workflows', () => { + it('should properly handle read-only state for a repository without workflows', () => { setup({ + isNew: false, repository: { name: 'repo-abc', type: 'github', @@ -401,6 +402,20 @@ describe('SaveProvisionedDashboardForm', () => { }, }); - expect(screen.getByText('This repository is read only')).toBeInTheDocument(); + // Alert is shown + expect(screen.getByRole('alert', { name: 'This repository is read only' })).toBeInTheDocument(); + + // Save button is disabled + const saveButton = screen.getByRole('button', { name: /save/i }); + expect(saveButton).toBeDisabled(); + + // Common options are not shown for existing dashboards + expect(screen.queryByTestId('common-options')).not.toBeInTheDocument(); + + // Workflow options are not shown + expect(screen.queryByRole('radiogroup')).not.toBeInTheDocument(); + + // Branch field is not shown + expect(screen.queryByRole('textbox', { name: /branch/i })).not.toBeInTheDocument(); }); }); diff --git a/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.tsx b/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.tsx index 907a8031ef2..a177964f7e2 100644 --- a/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.tsx +++ b/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboardForm.tsx @@ -159,11 +159,11 @@ export function SaveProvisionedDashboardForm({ }; const workflowOptions = getWorkflowOptions(repository, loadedFromRef); - + const readOnly = !repository?.workflows?.length; return (
- {!repository?.workflows?.length && ( + {readOnly && ( - + )} - {!isNew && } + {!isNew && !readOnly && } - +