Provisioning: Fix save form for readOnly repository (#105849)
* Provisioning: Fix save form for readOnly repository * betterer
This commit is contained in:
@@ -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"]
|
||||
],
|
||||
|
||||
+17
-2
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
+16
-8
@@ -159,11 +159,11 @@ export function SaveProvisionedDashboardForm({
|
||||
};
|
||||
|
||||
const workflowOptions = getWorkflowOptions(repository, loadedFromRef);
|
||||
|
||||
const readOnly = !repository?.workflows?.length;
|
||||
return (
|
||||
<form onSubmit={handleSubmit(handleFormSubmit)} name="save-provisioned-form">
|
||||
<Stack direction="column" gap={2}>
|
||||
{!repository?.workflows?.length && (
|
||||
{readOnly && (
|
||||
<Alert
|
||||
title={t(
|
||||
'dashboard-scene.save-provisioned-dashboard-form.title-this-repository-is-read-only',
|
||||
@@ -179,6 +179,7 @@ export function SaveProvisionedDashboardForm({
|
||||
{isNew && (
|
||||
<>
|
||||
<Field
|
||||
noMargin
|
||||
label={t('dashboard-scene.save-provisioned-dashboard-form.label-title', 'Title')}
|
||||
invalid={!!errors.title}
|
||||
error={errors.title?.message}
|
||||
@@ -195,6 +196,7 @@ export function SaveProvisionedDashboardForm({
|
||||
/>
|
||||
</Field>
|
||||
<Field
|
||||
noMargin
|
||||
label={t('dashboard-scene.save-provisioned-dashboard-form.label-description', 'Description')}
|
||||
invalid={!!errors.description}
|
||||
error={errors.description?.message}
|
||||
@@ -202,7 +204,10 @@ export function SaveProvisionedDashboardForm({
|
||||
<TextArea id="dashboard-description" {...register('description')} />
|
||||
</Field>
|
||||
|
||||
<Field label={t('dashboard-scene.save-provisioned-dashboard-form.label-target-folder', 'Target folder')}>
|
||||
<Field
|
||||
noMargin
|
||||
label={t('dashboard-scene.save-provisioned-dashboard-form.label-target-folder', 'Target folder')}
|
||||
>
|
||||
<Controller
|
||||
control={control}
|
||||
name={'folder'}
|
||||
@@ -232,9 +237,10 @@ export function SaveProvisionedDashboardForm({
|
||||
</>
|
||||
)}
|
||||
|
||||
{!isNew && <SaveDashboardFormCommonOptions drawer={drawer} changeInfo={changeInfo} />}
|
||||
{!isNew && !readOnly && <SaveDashboardFormCommonOptions drawer={drawer} changeInfo={changeInfo} />}
|
||||
|
||||
<Field
|
||||
noMargin
|
||||
label={t('dashboard-scene.save-provisioned-dashboard-form.label-path', 'Path')}
|
||||
description={t(
|
||||
'dashboard-scene.save-provisioned-dashboard-form.description-inside-repository',
|
||||
@@ -244,10 +250,11 @@ export function SaveProvisionedDashboardForm({
|
||||
<Input id="dashboard-path" {...register('path')} readOnly={!isNew} />
|
||||
</Field>
|
||||
|
||||
<Field label={t('dashboard-scene.save-provisioned-dashboard-form.label-comment', 'Comment')}>
|
||||
<Field noMargin label={t('dashboard-scene.save-provisioned-dashboard-form.label-comment', 'Comment')}>
|
||||
<TextArea
|
||||
id="dashboard-comment"
|
||||
{...register('comment')}
|
||||
disabled={readOnly}
|
||||
placeholder={t(
|
||||
'dashboard-scene.save-provisioned-dashboard-form.dashboard-comment-placeholder-describe-changes-optional',
|
||||
'Add a note to describe your changes (optional)'
|
||||
@@ -256,9 +263,9 @@ export function SaveProvisionedDashboardForm({
|
||||
/>
|
||||
</Field>
|
||||
|
||||
{isGitHub && (
|
||||
{isGitHub && !readOnly && (
|
||||
<>
|
||||
<Field label={t('dashboard-scene.save-provisioned-dashboard-form.label-workflow', 'Workflow')}>
|
||||
<Field noMargin label={t('dashboard-scene.save-provisioned-dashboard-form.label-workflow', 'Workflow')}>
|
||||
<Controller
|
||||
control={control}
|
||||
name="workflow"
|
||||
@@ -269,6 +276,7 @@ export function SaveProvisionedDashboardForm({
|
||||
</Field>
|
||||
{workflow === 'branch' && (
|
||||
<Field
|
||||
noMargin
|
||||
label={t('dashboard-scene.save-provisioned-dashboard-form.label-branch', 'Branch')}
|
||||
description={t(
|
||||
'dashboard-scene.save-provisioned-dashboard-form.description-branch-name-in-git-hub',
|
||||
@@ -284,7 +292,7 @@ export function SaveProvisionedDashboardForm({
|
||||
)}
|
||||
|
||||
<Stack gap={2}>
|
||||
<Button variant="primary" type="submit" disabled={request.isLoading || !isDirty}>
|
||||
<Button variant="primary" type="submit" disabled={request.isLoading || !isDirty || readOnly}>
|
||||
{request.isLoading
|
||||
? t('dashboard-scene.save-provisioned-dashboard-form.saving', 'Saving...')
|
||||
: t('dashboard-scene.save-provisioned-dashboard-form.save', 'Save')}
|
||||
|
||||
Reference in New Issue
Block a user