Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

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

Andras Bacsai4cb806b47241
diff --git a/app/Livewire/Project/Application/Previews.php b/app/Livewire/Project/Application/Previews.php
index 832a0d55cf..acc7dc8608 100644
--- a/app/Livewire/Project/Application/Previews.php
+++ b/app/Livewire/Project/Application/Previews.php
@@ -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 = [];
diff --git a/resources/views/livewire/project/application/previews.blade.php b/resources/views/livewire/project/application/previews.blade.php
index b85d769af3..54c8b9dfd3 100644
--- a/resources/views/livewire/project/application/previews.blade.php
+++ b/resources/views/livewire/project/application/previews.blade.php
@@ -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="[
diff --git a/tests/Feature/ApplicationPreviewSettingsTest.php b/tests/Feature/ApplicationPreviewSettingsTest.php
index 5a938e0d01..e5f69f4ee1 100644
--- a/tests/Feature/ApplicationPreviewSettingsTest.php
+++ b/tests/Feature/ApplicationPreviewSettingsTest.php
@@ -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]);