feat(ui): move preview deployment toggle into section actions

Replace the preview deployments listbox with an Enable/Disable action
button that calls togglePreviewDeployments and persists the setting.
This commit is contained in:
Andras Bacsai
2026-09-08 10:21:34 +02:00
parent 22ce20a045
commit 4cb806b472
3 changed files with 35 additions and 7 deletions
@@ -68,6 +68,14 @@ class Previews extends Component
$this->dispatch('configurationChanged');
}
public function togglePreviewDeployments(): void
{
$this->authorize('update', $this->application);
$this->isPreviewDeploymentsEnabled = ! $this->isPreviewDeploymentsEnabled;
$this->savePreviewSettings();
}
private function syncDockerTags(): void
{
$this->previewDockerTags = [];
@@ -5,13 +5,22 @@
@endphp
<x-application.settings-section id="preview-settings-section" title="Preview settings"
helper="Automatic pull request deployments and who can trigger them.">
<div class="grid w-full gap-4 sm:grid-cols-2">
<x-forms.listbox id="isPreviewDeploymentsEnabled" label="Preview deployments" onChange="savePreviewSettings"
helper="Automatically deploy Preview Deployments for all opened PRs.<br><br>Closing a PR deletes its Preview Deployment."
:options="[
['value' => false, 'label' => 'Disabled'],
['value' => true, 'label' => 'Deploy opened pull requests'],
]" :disabled="! $canUpdate" />
<x-slot:actions>
@can('update', $application)
@if ($isPreviewDeploymentsEnabled)
<x-forms.button wire:click="togglePreviewDeployments" wire:target="togglePreviewDeployments">
Disable preview deployments
</x-forms.button>
@else
<x-forms.button wire:click="togglePreviewDeployments" wire:target="togglePreviewDeployments"
isHighlighted>
Enable preview deployments
</x-forms.button>
@endif
@endcan
</x-slot:actions>
<div class="w-full">
<x-forms.listbox id="isPrDeploymentsPublicEnabled" label="PR deployment access" onChange="savePreviewSettings"
helper="When public, anyone can trigger PR deployments. Otherwise fork PRs are blocked and only repository owners, members, and collaborators can trigger them."
:options="[
@@ -106,6 +106,17 @@ it('shows preview settings and persists changes independently of preview inputs'
expect($this->application->fresh()->settings->is_preview_deployments_enabled)->toBeFalse();
});
it('renders preview deployment enablement as a section action', function () {
Livewire::test(Previews::class, ['application' => $this->application])
->assertSee('Enable preview deployments')
->assertDontSeeHtml('id="isPreviewDeploymentsEnabled"')
->call('togglePreviewDeployments')
->assertSee('Disable preview deployments')
->assertSet('isPreviewDeploymentsEnabled', true);
expect($this->application->fresh()->settings->is_preview_deployments_enabled)->toBeTrue();
});
it('does not show git preview settings for non-git applications', function (string $buildPack, ?string $dockerfile) {
$this->application->update(['build_pack' => $buildPack, 'dockerfile' => $dockerfile]);