FilamentF
Filament17mo ago
nowak

Slow action modal opening times on resource table

I have a GroupOrderManagementResource with a table, which has actions that use my GroupOrder model records in it's functions. Opening these actions seems to take too long (3+ secons), and I was wondering if I am doing something inefficiently when it comes to using the Resource model records in the table? So my Resource setup looks like this:
class GroupOrderManagementResource extends Resource
{
  protected static ?string $model = GroupOrder::class;
  protected static ?string $navigationLabel = 'Group Order Manager';
  
  public static ?string $title = 'Group Order Management';
  
  public static ?string $slug = 'group-order-management';


Then I define my table query like this:
public static function table(Table $table): Table
  {
    return $table
      ->query(GroupOrderResource::getEloquentQuery()->with([
        'userOrders.userOrderItems.productSku.product.category' => function ($query) {
          $query->select('id', 'name');
        },
        'userOrders.userOrderItems.productSku.product.type' => function ($query) {
          $query->select('id', 'name');
        },
        'route'
      ])->activeDayGroupOrders())

Where I am wondering if I am using eager loading correctly?

And finally, I have a note TextColumn, that I have added an action to with a form to add/edit the note for a record:
TextColumn::make('note')
  ->placeholder(__('Click to add note!'))
  ->extraAttributes(['class' => 'min-w-36 text-wrap cursor-pointer'])
  ->toggleable()
  ->action(
    Action::make('edit_note')
      ->label(false)
      ->form(fn(GroupOrder $record) => [
        Textarea::make('note')
          ->label(fn (Get $get): string => $get('note') ? __('Edit Note') : __('Add Note'))
          ->default($record->note)
      ])
      ->action(fn(GroupOrder $record, array $data) => $record->update(['note' => $data['note']]))
      ),


Any insight is highly appreciated!
Thanks!
Was this page helpful?