Skip to content

Commit c7b0c31

Browse files
simonhampclaude
andauthored
Fix Filament Select validation error on grantToUser action (#330)
Add missing getOptionLabelUsing() to the user_id Select field in the PluginBundleResource grantToUser action. Filament v5 requires this method alongside getSearchResultsUsing() to validate selected options. Closes #54 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a1b9260 commit c7b0c31

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

app/Filament/Resources/PluginBundleResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public static function table(Table $table): Table
187187
->mapWithKeys(fn (User $user) => [$user->id => "{$user->name} ({$user->email})"])
188188
->toArray();
189189
})
190+
->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->name)
190191
->required(),
191192
])
192193
->action(function (PluginBundle $record, array $data): void {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Tests\Feature\Filament;
4+
5+
use App\Filament\Resources\PluginBundleResource\Pages\ListPluginBundles;
6+
use App\Models\Plugin;
7+
use App\Models\PluginBundle;
8+
use App\Models\User;
9+
use Filament\Actions\Testing\TestAction;
10+
use Illuminate\Foundation\Testing\RefreshDatabase;
11+
use Livewire\Livewire;
12+
use Tests\TestCase;
13+
14+
class GrantBundleToUserActionTest extends TestCase
15+
{
16+
use RefreshDatabase;
17+
18+
private User $admin;
19+
20+
private PluginBundle $bundle;
21+
22+
protected function setUp(): void
23+
{
24+
parent::setUp();
25+
26+
$this->admin = User::factory()->create(['email' => 'admin@test.com']);
27+
config(['filament.users' => ['admin@test.com']]);
28+
29+
$this->bundle = PluginBundle::factory()->active()->create();
30+
}
31+
32+
public function test_grant_to_user_action_can_be_called_with_user_id(): void
33+
{
34+
$recipient = User::factory()->create();
35+
$plugins = Plugin::factory()->count(2)->approved()->create();
36+
$this->bundle->plugins()->attach($plugins->pluck('id'));
37+
38+
Livewire::actingAs($this->admin)
39+
->test(ListPluginBundles::class)
40+
->callAction(
41+
TestAction::make('grantToUser')->table($this->bundle),
42+
data: ['user_id' => $recipient->id],
43+
)
44+
->assertHasNoFormErrors();
45+
46+
foreach ($plugins as $plugin) {
47+
$this->assertDatabaseHas('plugin_licenses', [
48+
'user_id' => $recipient->id,
49+
'plugin_id' => $plugin->id,
50+
'plugin_bundle_id' => $this->bundle->id,
51+
]);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)