Skip to content
This repository was archived by the owner on Feb 14, 2026. It is now read-only.

Commit 6b310f6

Browse files
Merge pull request #324 from CodeWithDennis/add-global-configure-using-handler
Add InteractsWithServiceProviders trait and refactor table loading logic
2 parents 3d53825 + 913a753 commit 6b310f6

File tree

7 files changed

+48
-29
lines changed

7 files changed

+48
-29
lines changed

src/Commands/FilamentTestsCommand.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class FilamentTestsCommand extends Command
3232

3333
protected Collection $resources;
3434

35-
protected bool $tableLoadingGloballyDeferred = false;
36-
3735
use InteractsWithFilesystem;
3836
use InteractsWithUserInput;
3937

@@ -47,7 +45,6 @@ public function handle(): void
4745
{
4846
$this->panels = $this->askUserToSelectPanels();
4947
$this->resources = $this->askUserToSelectResourcesFromTheSelectedPanels();
50-
$this->tableLoadingGloballyDeferred = $this->askUserIfTableLoadingIsGloballyDeferred();
5148

5249
$this->generateTests();
5350
$this->showGenerationSummary();

src/Concerns/Commands/InteractsWithFilesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function renderTestsForResource(string $resource): array
8484
$output = $renderers
8585
->map(fn (string $renderer) =>
8686
/** @var BaseTest $renderer */
87-
$renderer::build($resource)->tableLoadingGloballyDeferred($this->tableLoadingGloballyDeferred)->render())
87+
$renderer::build($resource)->render())
8888
->prepend('<?php')
8989
->implode("\n\n");
9090

src/Concerns/Commands/InteractsWithUserInput.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Filament\Panel;
77
use Illuminate\Support\Collection;
88

9-
use function Laravel\Prompts\confirm;
109
use function Laravel\Prompts\multiselect;
1110

1211
trait InteractsWithUserInput
@@ -65,13 +64,4 @@ protected function askUserToSelectResourcesFromTheSelectedPanels(): Collection
6564

6665
return $selectedResources;
6766
}
68-
69-
protected function askUserIfTableLoadingIsGloballyDeferred(): bool
70-
{
71-
return confirm(
72-
label: 'Do you globally defer table loading in your Filament app?',
73-
default: false,
74-
hint: 'If you set `deferLoading` individually on your resource tables, you can select "No" here.',
75-
);
76-
}
7767
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace CodeWithDennis\FilamentTests\Concerns;
4+
5+
use CodeWithDennis\FilamentTests\Exceptions\GlobalConfiguredUsingCouldNotBeDeterminedException;
6+
use Filament\Forms\Components\Field;
7+
use Filament\Infolists\Components\Entry;
8+
use Filament\Resources\Pages\ListRecords;
9+
use Filament\Support\Concerns\EvaluatesClosures;
10+
use Filament\Tables\Table;
11+
12+
trait InteractsWithGlobalConfiguration
13+
{
14+
use EvaluatesClosures;
15+
16+
public function getGloballyConfiguredUsing(string $class): object
17+
{
18+
return match ($class) {
19+
Table::class => Table::make(app('livewire')->new(ListRecords::class)),
20+
is_subclass_of($class, Entry::class, true),
21+
is_subclass_of($class, Field::class, true) => $class::make('dummy-name'), // some components require a name in their constructor
22+
method_exists($class, 'make') => $class::make(),
23+
default => throw new GlobalConfiguredUsingCouldNotBeDeterminedException($class, 'make() method')
24+
};
25+
}
26+
}

src/Concerns/Resources/InteractsWithTables.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CodeWithDennis\FilamentTests\Concerns\Resources;
44

5+
use CodeWithDennis\FilamentTests\Exceptions\GlobalConfiguredUsingCouldNotBeDeterminedException;
56
use Filament\Actions\Action;
67
use Filament\Resources\Pages\ListRecords;
78
use Filament\Tables\Columns\Column;
@@ -126,7 +127,11 @@ public function getResourceTableVisibleActions(): array
126127

127128
public function isResourceTableLoadingDeferred(): bool
128129
{
129-
return $this->isTableLoadingGlobalyDeferred() ?: $this->getResourceTable()->isLoadingDeferred();
130+
try {
131+
return $this->getGloballyConfiguredUsing(\Filament\Tables\Table::class)->isLoadingDeferred();
132+
} catch (GlobalConfiguredUsingCouldNotBeDeterminedException) {
133+
return $this->getResourceTable()->isLoadingDeferred();
134+
}
130135
}
131136

132137
public function isResourceTablePaginationEnabled(): bool
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace CodeWithDennis\FilamentTests\Exceptions;
4+
5+
use Exception;
6+
7+
class GlobalConfiguredUsingCouldNotBeDeterminedException extends Exception
8+
{
9+
public function __construct(string $class, string $method)
10+
{
11+
parent::__construct("Could not determine the globally configured using for {$class}::{$method}().");
12+
}
13+
}

src/TestRenderers/BaseTest.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CodeWithDennis\FilamentTests\Concerns\ExposesPublicMethodsToViews;
66
use CodeWithDennis\FilamentTests\Concerns\HasFilamentResources;
7+
use CodeWithDennis\FilamentTests\Concerns\InteractsWithGlobalConfiguration;
78
use CodeWithDennis\FilamentTests\Concerns\InteractsWithResources;
89
use CodeWithDennis\FilamentTests\Concerns\Renderers\CanRenderViews;
910
use Filament\Resources\Resource;
@@ -12,31 +13,18 @@ abstract class BaseTest implements HasFilamentResources
1213
{
1314
use CanRenderViews;
1415
use ExposesPublicMethodsToViews;
16+
use InteractsWithGlobalConfiguration;
1517
use InteractsWithResources;
1618

17-
public bool $tableLoadingGloballyDeferred = false;
18-
1919
public function __construct(
2020
public ?string $resourceClass = null,
2121
) {}
2222

23-
public function tableLoadingGloballyDeferred(bool $tableLoadingGloballyDeferred): static
24-
{
25-
$this->tableLoadingGloballyDeferred = $tableLoadingGloballyDeferred;
26-
27-
return $this;
28-
}
29-
3023
public static function build(string $resourceClass): static
3124
{
3225
return new static($resourceClass);
3326
}
3427

35-
public function isTableLoadingGlobalyDeferred(): bool
36-
{
37-
return $this->tableLoadingGloballyDeferred;
38-
}
39-
4028
public function getResourceClass(): ?string
4129
{
4230
return $this->resourceClass;

0 commit comments

Comments
 (0)