From 34b33186391f77b1e7732ee20c956254f6c42df5 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Wed, 16 Sep 2026 14:02:31 +0200 Subject: [PATCH] fix(deployments): preserve and display pull request filters Include configured previews in pull request options and show the active filter. --- .../Project/Application/Deployment/Index.php | 6 ++- .../views/components/table/filter.blade.php | 2 +- .../application/deployment/index.blade.php | 1 + .../Feature/DeploymentHistoryFiltersTest.php | 53 +++++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) 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])> - Filter + {{ $activeText ?: 'Filter' }} @if ($activeCount > 0) {{ $activeCount }} @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" /> @if (count($statusFilterOptions) > 0) 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' + + Filter options + + BLADE); + + expect($view)->toContain(":active-text=\"filled(\$pull_request_id) ? 'Pull request #'.\$pull_request_id : null\"") + ->and($filter)->toContain('Pull request #41'); +}); + +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'], + ]); +});