F
Filamentβ€’2mo ago
larsbo

How to refresh the tab component of a relation manager?

I use this example from the docs: https://filamentphp.com/docs/4.x/resources/managing-relationships#customizing-relation-manager-tabs When I create a new record or delete an existing one the badge count does not refresh. I tried to use a closure inside the badge() method and $this->dispatch('$refresh'); inside my action methods but it didn't solve the problem.
Solution:
GitHub
Tab badge count not updating for relationships after creating a new...
Package Other Package Version ^4.0 How can we help you? Tab badge count not updating for relationships after creating a new resource in a modal. Tried to dispatch an event, but that also does not w...
Jump to solution
19 Replies
TDDeveloper
TDDeveloperβ€’2mo ago
@larsbo You can do something like this: https://filamentphp.com/docs/4.x/actions/delete#lifecycle-hooks
DeleteAction::make()
->after(fn (Component $livewire) => $livewire->dispatch('event-name')),
DeleteAction::make()
->after(fn (Component $livewire) => $livewire->dispatch('event-name')),
You only have to find where to put the #[On('event-name')] part. I do not use the getTabComponent() method, but if you do maybe try to put it on that method.
larsbo
larsboOPβ€’2mo ago
@TDDeveloper Tried it on getTabComponent() but no luck.
TDDeveloper
TDDeveloperβ€’2mo ago
I will try to look at it later
larsbo
larsboOPβ€’4w ago
Thank you! I already searched the code for some entry point, but no idea so far 😭 @TDDeveloper Did you find out someting about this?
TDDeveloper
TDDeveloperβ€’4w ago
@larsbo I did not have the time yet to look at it. Will check it today
LeandroFerreira
LeandroFerreiraβ€’4w ago
DeleteAction::make()
->after(fn () => $this->dispatch('refreshPage'))
DeleteAction::make()
->after(fn () => $this->dispatch('refreshPage'))
In your EditPage
#[On('refreshPage')]
public function refreshPage(): void {}
#[On('refreshPage')]
public function refreshPage(): void {}
larsbo
larsboOPβ€’4w ago
Still no update πŸ™ƒ I tryed both with DeleteAction and DeleteBulkAction. A dd() inside the the after() method works, but a dd() inside the refreshPage() method was not executed.
LeandroFerreira
LeandroFerreiraβ€’4w ago
where did you add the refreshPage method?
larsbo
larsboOPβ€’4w ago
First inside my EditPage. Now I put it inside the RelationManager class and now it was triggered when I test it with dd(). #[On('refreshPage')] public function refreshPage(): void { dd('test'); } but without dd() nothing happens
LeandroFerreira
LeandroFerreiraβ€’4w ago
This works on my end. Please create a minimal repo on github to reproduce this issue and I can take a look
TDDeveloper
TDDeveloperβ€’4w ago
it updates the tab count of the relationship or the one in the main navigation bar? Because I can't get it to work either, only updates on the main navigation work
LeandroFerreira
LeandroFerreiraβ€’4w ago
it updates the page, so I think it should update all
TDDeveloper
TDDeveloperβ€’4w ago
I will try to make a project this evening
larsbo
larsboOPβ€’4w ago
I just created a minimal example. And I can confirm calling dispatch('refreshPage') in the after() method of the create or delete action refreshes the tab counter... πŸ˜† πŸ™ƒ That means the issue is somewhere else 😭
TDDeveloper
TDDeveloperβ€’4w ago
Do you use modals in your non-test application? This is where it goes wrong in my example application https://github.com/Merdin/filament-badgecount-bug
larsbo
larsboOPβ€’4w ago
@TDDeveloper yes, I do. Without modal there is a full page refresh after creation, isn't it? btw: we build almost the same minimal example with posts and comments πŸ˜‚
larsbo
larsboOPβ€’4w ago
here is my repo with the refresh solution: https://github.com/kielcoding/filament-issue
GitHub
GitHub - kielcoding/filament-issue
Contribute to kielcoding/filament-issue development by creating an account on GitHub.
Solution
LeandroFerreira
LeandroFerreiraβ€’4w ago
GitHub
Tab badge count not updating for relationships after creating a new...
Package Other Package Version ^4.0 How can we help you? Tab badge count not updating for relationships after creating a new resource in a modal. Tried to dispatch an event, but that also does not w...

Did you find this page helpful?