tanakei
tanakei
FFilament
Created by tanakei on 8/9/2023 in #❓┊help
When using the Select component with multiple() options, a large number of requests are being sent.
Components\FileUpload::make('image')->label('Image')->image()->required()
->disk(config('filesystems.default'))
->directory(config('filesystems.disks.'.config('filesystems.default').'.root'))
->afterStateHydrated(static function (\Filament\Forms\Components\BaseFileUpload $component, string | array | null $state): void {
if (blank($state)) {
$component->state([]);

return;
}

$state = \Arr::last(explode('/', $state));

$files = collect(\Arr::wrap($state))
->filter(static function (string $file) use ($component): bool {
try {
return blank($file) || $component->getDisk()->exists($file);
} catch (\League\Flysystem\UnableToCheckFileExistence $exception) {
return false;
}
})
->mapWithKeys(static fn (string $file): array => [((string) \Str::uuid()) => $file])
->all();

$component->state($files);
})
Components\FileUpload::make('image')->label('Image')->image()->required()
->disk(config('filesystems.default'))
->directory(config('filesystems.disks.'.config('filesystems.default').'.root'))
->afterStateHydrated(static function (\Filament\Forms\Components\BaseFileUpload $component, string | array | null $state): void {
if (blank($state)) {
$component->state([]);

return;
}

$state = \Arr::last(explode('/', $state));

$files = collect(\Arr::wrap($state))
->filter(static function (string $file) use ($component): bool {
try {
return blank($file) || $component->getDisk()->exists($file);
} catch (\League\Flysystem\UnableToCheckFileExistence $exception) {
return false;
}
})
->mapWithKeys(static fn (string $file): array => [((string) \Str::uuid()) => $file])
->all();

$component->state($files);
})
Self resolved. It seems that afterStateHydrated() was not implemented well. I fixed it with reference to the original implementation. thanks.
7 replies
FFilament
Created by tanakei on 8/9/2023 in #❓┊help
When using the Select component with multiple() options, a large number of requests are being sent.
I found a few causes. The following components seem to be affected
Components\FileUpload::make('image')->label('Image')->image()->required()
->disk(config('filesystems.default'))
->directory(config('filesystems.'.config('filesystems.default').'.root'))
->afterStateHydrated(function($component, $record) {
if ($record) {
$filename = \Arr::last(explode('/', $record->image));
$component->state([$filename => $filename]);
}
})
Components\FileUpload::make('image')->label('Image')->image()->required()
->disk(config('filesystems.default'))
->directory(config('filesystems.'.config('filesystems.default').'.root'))
->afterStateHydrated(function($component, $record) {
if ($record) {
$filename = \Arr::last(explode('/', $record->image));
$component->state([$filename => $filename]);
}
})
When I remove afterStateHydrated(), the requests stop.
7 replies
FFilament
Created by tanakei on 8/9/2023 in #❓┊help
When using the Select component with multiple() options, a large number of requests are being sent.
No, widgets are not used on this page.
7 replies
FFilament
Created by tanakei on 8/9/2023 in #❓┊help
When using the Select component with multiple() options, a large number of requests are being sent.
Components\Select::make('categories')->label('category')
->multiple()
->options(function(callable $get) {
return ['0' => 'all'];
}),
Components\Select::make('categories')->label('category')
->multiple()
->options(function(callable $get) {
return ['0' => 'all'];
}),
Even with the above implementation, multiple requests are still occurring 😢
7 replies