Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Commands/FilamentTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class FilamentTestsCommand extends Command

protected Collection $resources;

protected bool $tableLoadingGloballyDeferred = false;

use InteractsWithFilesystem;
use InteractsWithUserInput;

Expand All @@ -47,7 +45,6 @@ public function handle(): void
{
$this->panels = $this->askUserToSelectPanels();
$this->resources = $this->askUserToSelectResourcesFromTheSelectedPanels();
$this->tableLoadingGloballyDeferred = $this->askUserIfTableLoadingIsGloballyDeferred();

$this->generateTests();
$this->showGenerationSummary();
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/Commands/InteractsWithFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function renderTestsForResource(string $resource): array
$output = $renderers
->map(fn (string $renderer) =>
/** @var BaseTest $renderer */
$renderer::build($resource)->tableLoadingGloballyDeferred($this->tableLoadingGloballyDeferred)->render())
$renderer::build($resource)->render())
->prepend('<?php')
->implode("\n\n");

Expand Down
10 changes: 0 additions & 10 deletions src/Concerns/Commands/InteractsWithUserInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Filament\Panel;
use Illuminate\Support\Collection;

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\multiselect;

trait InteractsWithUserInput
Expand Down Expand Up @@ -65,13 +64,4 @@ protected function askUserToSelectResourcesFromTheSelectedPanels(): Collection

return $selectedResources;
}

protected function askUserIfTableLoadingIsGloballyDeferred(): bool
{
return confirm(
label: 'Do you globally defer table loading in your Filament app?',
default: false,
hint: 'If you set `deferLoading` individually on your resource tables, you can select "No" here.',
);
}
}
26 changes: 26 additions & 0 deletions src/Concerns/InteractsWithServiceProviders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace CodeWithDennis\FilamentTests\Concerns;

use CodeWithDennis\FilamentTests\Exceptions\GlobalConfiguredUsingCouldNotBeDeterminedException;
use Filament\Forms\Components\Field;
use Filament\Infolists\Components\Entry;
use Filament\Resources\Pages\ListRecords;
use Filament\Support\Concerns\EvaluatesClosures;
use Filament\Tables\Table;

trait InteractsWithServiceProviders
{
use EvaluatesClosures;

public function getGloballyConfiguredUsing(string $class): object
{
return match ($class) {
Table::class => Table::make(app('livewire')->new(ListRecords::class)),
is_subclass_of($class, Entry::class, true),
is_subclass_of($class, Field::class, true) => $class::make('dummy-name'), // some components require a name in their constructor
method_exists($class, 'make') => $class::make(),
default => throw new GlobalConfiguredUsingCouldNotBeDeterminedException($class, 'make() method')
};
}
}
7 changes: 6 additions & 1 deletion src/Concerns/Resources/InteractsWithTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ public function getResourceTableVisibleActions(): array

public function isResourceTableLoadingDeferred(): bool
{
return $this->isTableLoadingGlobalyDeferred() ?: $this->getResourceTable()->isLoadingDeferred();
try {
return $this->getGloballyConfiguredUsing(\Filament\Tables\Table::class)->isLoadingDeferred();
} catch (\Throwable) {
return $this->getResourceTable()->isLoadingDeferred();
}

}

public function isResourceTablePaginationEnabled(): bool
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace CodeWithDennis\FilamentTests\Exceptions;

use Exception;

class GlobalConfiguredUsingCouldNotBeDeterminedException extends Exception
{
public function __construct(string $class, string $method)
{
parent::__construct("Could not determine the globally configured using for {$class}::{$method}().");
}
}
16 changes: 2 additions & 14 deletions src/TestRenderers/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use CodeWithDennis\FilamentTests\Concerns\ExposesPublicMethodsToViews;
use CodeWithDennis\FilamentTests\Concerns\HasFilamentResources;
use CodeWithDennis\FilamentTests\Concerns\InteractsWithResources;
use CodeWithDennis\FilamentTests\Concerns\InteractsWithServiceProviders;
use CodeWithDennis\FilamentTests\Concerns\Renderers\CanRenderViews;
use Filament\Resources\Resource;

Expand All @@ -13,30 +14,17 @@ abstract class BaseTest implements HasFilamentResources
use CanRenderViews;
use ExposesPublicMethodsToViews;
use InteractsWithResources;

public bool $tableLoadingGloballyDeferred = false;
use InteractsWithServiceProviders;

public function __construct(
public ?string $resourceClass = null,
) {}

public function tableLoadingGloballyDeferred(bool $tableLoadingGloballyDeferred): static
{
$this->tableLoadingGloballyDeferred = $tableLoadingGloballyDeferred;

return $this;
}

public static function build(string $resourceClass): static
{
return new static($resourceClass);
}

public function isTableLoadingGlobalyDeferred(): bool
{
return $this->tableLoadingGloballyDeferred;
}

public function getResourceClass(): ?string
{
return $this->resourceClass;
Expand Down