Travis
Travis
FFilament
Created by Mook on 10/22/2024 in #❓┊help
Bulk actions which is only visible when 2 rows are selected
Let me know if you have any questions.
12 replies
FFilament
Created by Mook on 10/22/2024 in #❓┊help
Bulk actions which is only visible when 2 rows are selected
It gets the table's filter state for a filter named, "state", which may be confusing at first. 😅 Then, it looks to see if it has "values". If you have a normal select filter, then this would be "value", I believe. Then, for my logic, I want to check to see if only the "pending" state is selected. If so, then this is when I want to make the "approve" bulk action visible. You may have different logic. For the bulk "revert" action, for example, I want it to be visible if the user has selected either the "approved" state or the "rejected" state.
12 replies
FFilament
Created by Mook on 10/22/2024 in #❓┊help
Bulk actions which is only visible when 2 rows are selected
Sure. Keep in mind that this is using a multi-select filter, where the user can choose any combination of three states: pending, approved, and rejected. I changed a few names and added some comments to try to help.
<?php

namespace App\Filament\Resources\MyResource\TableActions;

use App\Enums\MyResourceState;
use Filament\Tables\Actions\BulkAction;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class ApproveBulkAction extends BulkAction
{
public static function getDefaultName(): ?string
{
return 'approve-bulk-resource';
}

protected function setUp(): void
{
parent::setUp();

$this->label('Approve')
->icon('heroicon-o-hand-thumb-up')
->visible($this->determineVisibility(...))
->action($this->approveAction(...));
}

private function determineVisibility(HasTable $livewire): bool
{
// get the state of the state filter
$stateFilterState = $livewire->getTableFilterState('state') ?? [];

// if the 'values' array key does not exist, return false (invisible)
if (! array_key_exists('values', $stateFilterState)) {
return false;
}

// get the state filter state values
$values = $stateFilterState['values'];

// if more/less than one are selected, return false (invisible)
if (count($values) !== 1) {
return false;
}

// return true (visible) if the 'pending' state filter is selected/enabled, false otherwise (invisible)
return Arr::first($values) === MyResourceState::PENDING->value;
}

private function approveAction(Collection $records): void
{
$records->each->approve();
}
}
<?php

namespace App\Filament\Resources\MyResource\TableActions;

use App\Enums\MyResourceState;
use Filament\Tables\Actions\BulkAction;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class ApproveBulkAction extends BulkAction
{
public static function getDefaultName(): ?string
{
return 'approve-bulk-resource';
}

protected function setUp(): void
{
parent::setUp();

$this->label('Approve')
->icon('heroicon-o-hand-thumb-up')
->visible($this->determineVisibility(...))
->action($this->approveAction(...));
}

private function determineVisibility(HasTable $livewire): bool
{
// get the state of the state filter
$stateFilterState = $livewire->getTableFilterState('state') ?? [];

// if the 'values' array key does not exist, return false (invisible)
if (! array_key_exists('values', $stateFilterState)) {
return false;
}

// get the state filter state values
$values = $stateFilterState['values'];

// if more/less than one are selected, return false (invisible)
if (count($values) !== 1) {
return false;
}

// return true (visible) if the 'pending' state filter is selected/enabled, false otherwise (invisible)
return Arr::first($values) === MyResourceState::PENDING->value;
}

private function approveAction(Collection $records): void
{
$records->each->approve();
}
}
12 replies
FFilament
Created by Mook on 10/22/2024 in #❓┊help
Bulk actions which is only visible when 2 rows are selected
I found a solution, but not the one I was looking for. I basically did the same thing as the built-in force delete and restore actions do, which relies on the presence of a filter. So, in my case, I have a multi-select filter with different states: pending, approved, and rejected. I examine the filter and only allow the various actions, depending. It's only when the pending filter is present that the approve/reject actions are enabled, for example. Ideally, I would get all of the selected items and examine them to decide what should be allowed, but I haven't figured out how to do that yet, if it's even possible. 🤷‍♂️
12 replies
FFilament
Created by Mook on 10/22/2024 in #❓┊help
Bulk actions which is only visible when 2 rows are selected
I'm looking for a solution to this, too. It seems difficult to get the selected records upon a change in row selections. I'm going to take a close(r) look at the built-in bulk actions to see if they offer anything like this (like restoring/trashing deleted resources).
12 replies
FFilament
Created by rule030 on 10/26/2023 in #❓┊help
Max excution timeouts
I'm getting a similar exception when dispatching a job on a resource create. It's meant to be a long-running task that's dispatched, but I'm working locally and using sync at the moment. I will try to use a different queue to see if that helps. In the meantime, if anyone can tell me what this 30 second timeout is or where one can change it, I would appreciate it.
25 replies
FFilament
Created by Bloom on 2/7/2024 in #❓┊help
Maximum execution time of 30 seconds exceeded Error
Did you ever figure this out? I'm also having the same problem and can't pin down which timeout is set to 30 seconds and where it can be changed. 😕
4 replies
FFilament
Created by SLINZEN on 2/26/2024 in #❓┊help
"Maximum execution time of 30 seconds exceeded" in hasEvenNumberOfParentheses Function
Did you ever figure this out? I'm also having the same problem and can't pin down which timeout is set to 30 seconds and where it can be changed. As for where it's happening for you, I would suggest you re-run things. For me, it's failing at different places in the code, depending on where, exactly it is, when the timeout occurs. I am guessing that yours is "random" just like it is for me.
3 replies
FFilament
Created by Travis on 3/5/2024 in #❓┊help
Can I use import options to allow the user to define the CSV delimiter?
I would rather do that than to override getCsvDelimiter(), which I also see as an option.
4 replies
FFilament
Created by Travis on 3/5/2024 in #❓┊help
Can I use import options to allow the user to define the CSV delimiter?
Well, I don't know how I missed it, but I can see that ImportAction has both the options and the CSV delimiter, which can be a closure, but can it accept options? If not, wouldn't that be helpful to submit a PR that updates the evaluate() call to pass along the options?
4 replies
FFilament
Created by Travis on 2/19/2024 in #❓┊help
Can I use Import/Export functionality outside of filament?
Thx. I figured/guessed as much, but I wanted to hear from someone who knew...or who knew better, anyway. 😜
4 replies
FFilament
Created by F alko on 10/18/2023 in #❓┊help
Reusing actions
Good point. Annoying, but good point. 😅
15 replies
FFilament
Created by F alko on 10/18/2023 in #❓┊help
Reusing actions
Maybe I change public $ratable to public $record and then refer to $this->record in the trait rather than have filament inject/pass it...? 🤔
15 replies
FFilament
Created by F alko on 10/18/2023 in #❓┊help
Reusing actions
Thx. I've considered that. I have a Table Action action that uses the setup to get everything working nicely for a table record that I want to be able to rate. It works great. But, many of the "handlers" take a "record", which is the record in question. I am not sure how I can have a non-table action work without this being provided. (Hopefully that makes sense. I haven't yet tried it. I've just got my single Table Action action working. I need to try to extract the setup functionality to a trait and then try it with the livewire component action, which uses Filament\Actions\Action and instead of taking $record, it uses the livewire component's public $ratable attribute/property.)
15 replies
FFilament
Created by F alko on 10/18/2023 in #❓┊help
Reusing actions
What about an action that can be used as a table action or a "standalone" action on a livewire component? I have the same functionality, rating a ratable resource, that displays a modal dialog box, and allows a user to enter/clear a rating. It seems I need to extend a Table Action to use as a table row action, which makes sense, but then it's not something that can be used on the standalone livewire component. I'm thinking I need multiple action classes, each extending the appropriate filament action class, but then it's not quite clear which way is the best way to reuse all of the basic/shared functionality.
15 replies
FFilament
Created by Travis on 12/9/2023 in #❓┊help
Bug in extraModalFooterActions arguments
Well, I'm not sure what's happened, but this problem seems to have gone away. Not sure if it was due to an update in the last several days. I'm not going to worry about it, though. 😅
2 replies
FFilament
Created by blink on 7/15/2023 in #❓┊help
Compact table
Thx, gentlemen. I'll give this a try when I have some time and try to return with an update on how it went. 🤓
17 replies
FFilament
Created by blink on 7/15/2023 in #❓┊help
Compact table
Thx. So this will overwrite any previous rules...?
17 replies
FFilament
Created by blink on 7/15/2023 in #❓┊help
Compact table
No description
17 replies
FFilament
Created by Travis on 11/3/2023 in #❓┊help
Is there an error in `Filament\Table\Table::defaultSort()`...?🤔
Feedback welcome/appreciated... 🤓
28 replies