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.

fix(deployments): preserve and display pull request filters

Andras Bacsai34b33186391f
diff --git a/app/Livewire/Project/Application/Deployment/Index.php b/app/Livewire/Project/Application/Deployment/Index.php
index fb24414cdd..e94f37544f 100644
--- a/app/Livewire/Project/Application/Deployment/Index.php
+++ b/app/Livewire/Project/Application/Deployment/Index.php
@@ -261,13 +261,15 @@ class Index extends Component
->where('application_id', $this->application->id)
->where('pull_request_id', '>', 0)
->distinct()
- ->orderByDesc('pull_request_id')
->pluck('pull_request_id')
+ ->merge($this->application->previews()->pluck('pull_request_id'))
->map(fn ($pullRequestId) => (string) $pullRequestId)
+ ->unique()
+ ->sortByDesc(fn (string $pullRequestId) => (int) $pullRequestId)
->values();
if ($this->pull_request_id && ! $pullRequestIds->contains($this->pull_request_id)) {
- $this->pull_request_id = null;
+ $pullRequestIds->prepend($this->pull_request_id);
}
$this->pullRequestOptions = collect([
diff --git a/resources/views/components/table/filter.blade.php b/resources/views/components/table/filter.blade.php
index 25c6639b07..b610e2080c 100644
--- a/resources/views/components/table/filter.blade.php
+++ b/resources/views/components/table/filter.blade.php
@@ -7,7 +7,7 @@
@if ($activeText) title="{{ $activeText }}" @endif
@class(['button max-w-80 min-w-0', 'button-highlighted' => $activeCount > 0])>
<x-reicon name="filter" class="size-3.5 shrink-0" />
- <span class="truncate">Filter</span>
+ <span class="truncate">{{ $activeText ?: 'Filter' }}</span>
@if ($activeCount > 0)
<span class="shrink-0 rounded-full bg-neutral-100 px-1.5 py-0.5 text-[10px] font-medium text-neutral-500 dark:bg-white/[0.07] dark:text-fg-dim">{{ $activeCount }}</span>
@endif
diff --git a/resources/views/livewire/project/application/deployment/index.blade.php b/resources/views/livewire/project/application/deployment/index.blade.php
index b2c2be9081..bfee536891 100644
--- a/resources/views/livewire/project/application/deployment/index.blade.php
+++ b/resources/views/livewire/project/application/deployment/index.blade.php
@@ -36,6 +36,7 @@
wire:model.live.debounce.300ms="search" />
</x-slot:search>
<x-table.filter :active-count="count($deploymentFilters) + (filled($pull_request_id) ? 1 : 0)"
+ :active-text="filled($pull_request_id) ? 'Pull request #'.$pull_request_id : null"
reset-action="clearFilter">
@if (count($statusFilterOptions) > 0)
<span
diff --git a/tests/Feature/DeploymentHistoryFiltersTest.php b/tests/Feature/DeploymentHistoryFiltersTest.php
index 05c929661e..a003102020 100644
--- a/tests/Feature/DeploymentHistoryFiltersTest.php
+++ b/tests/Feature/DeploymentHistoryFiltersTest.php
@@ -4,12 +4,14 @@ use App\Enums\ApplicationDeploymentStatus;
use App\Livewire\Project\Application\Deployment\Index;
use App\Models\Application;
use App\Models\ApplicationDeploymentQueue;
+use App\Models\ApplicationPreview;
use App\Models\Environment;
use App\Models\Project;
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\Team;
use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Support\Facades\Blade;
uses(RefreshDatabase::class);
@@ -88,3 +90,54 @@ it('always shows source filters and includes server filters', function () {
->and($loadingComponent)
->toContain('wire:loading.flex');
});
+
+it('shows the active pull request id on the deployment filter control', function () {
+ $view = file_get_contents(resource_path('views/livewire/project/application/deployment/index.blade.php'));
+ $filter = Blade::render(<<<'BLADE'
+ <x-table.filter :active-count="1" active-text="Pull request #41" reset-action="clearFilter">
+ Filter options
+ </x-table.filter>
+ BLADE);
+
+ expect($view)->toContain(":active-text=\"filled(\$pull_request_id) ? 'Pull request #'.\$pull_request_id : null\"")
+ ->and($filter)->toContain('<span class="truncate">Pull request #41</span>');
+});
+
+it('keeps a pull request filter from the URL when it has no deployment records yet', function () {
+ $application = Application::factory()->create();
+ $component = new Index;
+ $component->application = $application;
+ $component->pull_request_id = '41';
+
+ $method = new ReflectionMethod(Index::class, 'loadPullRequestOptions');
+ $method->invoke($component);
+
+ expect($component->pull_request_id)->toBe('41')
+ ->and($component->pullRequestOptions)->toContain([
+ 'value' => '41',
+ 'label' => 'Pull request #41',
+ ]);
+});
+
+it('includes every configured preview in the pull request filter options', function () {
+ $application = Application::factory()->create();
+ foreach ([41, 72] as $pullRequestId) {
+ ApplicationPreview::query()->create([
+ 'application_id' => $application->id,
+ 'pull_request_id' => $pullRequestId,
+ 'pull_request_html_url' => "https://github.com/example/repository/pull/{$pullRequestId}",
+ ]);
+ }
+
+ $component = new Index;
+ $component->application = $application;
+
+ $method = new ReflectionMethod(Index::class, 'loadPullRequestOptions');
+ $method->invoke($component);
+
+ expect($component->pullRequestOptions)->toBe([
+ ['value' => '', 'label' => 'All deployments'],
+ ['value' => '72', 'label' => 'Pull request #72'],
+ ['value' => '41', 'label' => 'Pull request #41'],
+ ]);
+});