Enable/Disable button dynamically (based on Job Status)
I have created an Action inside my ListPage Header (headerActions). This action is firing a Batch Job. What I really would like is some way to disable the button (and show a loading indicator icon) during the time this job runs. When it is finished, it should be enabled again.
Not sure how to achieve this. I can of course check if the job runs and prevent users from starting another one, but it would be nice to make it visible.
I tried something with the
Any ideas?
->disabled(fn () => $this->checkIfJobIsRunning)
, but how can I make this dynamic?
Any ideas?
30 Replies
maybe this can help you https://packagist.org/?query=laravel%20job%20status
Packagist
The PHP Package Repository
Thanks! I indeed looked into Job Status repo's.
For me the issue is that I'm wondering how to update the button itself? Is that
disabled
the right way?
Would it be possible to dispatch a classic Laravel Event, like e.g.:
event(new JobFinishedEvent());
And then listen to that on my ListPage, somewhere? Not sure if that is the right approach...Would only work when you have Laravel Echo set up with Webhooks
Hi Dennis. Thanks. Is there any other way to achieve such behavior?
I saw this behavior also in Filapanel, but not sure how it is done
@Dennis if you could help me with this? 🙂
Ah yes
You mean disabling actions inside a table?
For these simple things, listening on sockets and stuff is really overengineered IMHO
sorry, doing 100 things at the same time here
Do you want to know how I update the table?
I mean, I don't know what happens in the background, but if I can disable a button, show an indicator and then re-enable a button?
Or how I disable it?
Yes. And how you monitor the status of that project build.
The status of a project is just being updated in the jobs
in the final job
It's set to "finished"
Then, on the $table property:
I just check if I need to poll
If I do, it updates every 5s
The disabling, is just a disabled() methdo on the action:
So I could
poll
e.g. my batch table re-enable the button/action, once it is done?And that updates automatically because of polling
If you use job batches, you need to update a status column in the finally() method
For a project (or what ever entity)
Hmm... I'm going to investigate a bit more :). And is that status badge column a custom animated gif?
Ah yes
Rather easy though
Sec
I would aim for a Filapanel private fork 😉
Just so much stuff to learn... 🫣
I just set the icon if it's building, but that needs an animation, I've done that in CSS:
Pretty easy 😄
Cool. Tnx!
Haha it's closed I'm afraid, but you'll learn quickly enough, just keep building
And I don't mind sharing a few bits
Fair enough. Thanks Dennis.
... and @Dennis Koch
Quick question: where did you put this CSS?
I don't have a custom theme, so I created a custom css file and used the
FilamentAsset::register
command, but it generates the css file without transpiling I think?Yes. There is no "we do the Tailwind for you" magic 😅 Either create a theme or don't use
@apply
in that fileAh ok 🙂. But I do need to register that file?
A theme? Yes
No, I mean can I use this method to load in custom css:
Without a theme?
Sure. You just did, didn't you?
Yes 😉
Did you work it out @Daniel Plomp ?
I think I have it almost ready! Works great. I had to use the transpiled css, since I do not have a custom theme.
When using enums you don't need
->color()
can define them in enum file 😉
Also this one with poll is really coolI know, I like this better
Filament Daily
YouTube
Filament: Enum Classes to Re-Use and Auto-Style
If you have a set of key-value options in the forms and tables, you may use PHP Enum classes to avoid repeating those options.
Official docs: https://filamentphp.com/docs/3.x/support/enums