mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-25 17:01:49 -04:00
fix(deployments): preserve and display pull request filters
Include configured previews in pull request options and show the active filter.
This commit is contained in:
@@ -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([
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'],
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user