Programmatically open relationManager View/Edit modal

Goal I have linked two relationManagers to a Resource (parent). On the parent I would like to be able to call a function which opens the View/Edit action on a specific record in the relationManager. Motivation It would be great to "deeplink" to a record in a resource. What I mean by this is that I would like to be able to craft links like "/app/example/12#books-34". This link would open the example resource (id 12) and trigger the View/Edit on the book (id 34) record in the BooksRelationManager. Question Is this possible? How could I do this?
Solution:
I figured it out! 🥳
Jump to solution
11 Replies
Proculair B.V.
To communicate between the resource and the relationmanager, I will probably use livewire events/listeners
awcodes
awcodes5d ago
Nested relationship url aren’t totally possible in filament v3. There is a plugin for them and it’s coming to v4, but also using a hashtag isn’t really the way nested resources work in laravels routing out of the box.
Proculair B.V.
Yes, I understand that the routing part is seperate. But how do I programmatically open a edit/view modal in a contactrelation manager?
Proculair B.V.
When clicking on a resource in a relation manager I see (using wirespy) that the following event is fired:
No description
Proculair B.V.
If I fire that event manually, somehow an close event is also fired immediately
No description
Proculair B.V.
I looked some more and saw that, mountTableAction is used.
No description
Proculair B.V.
If I fire that myself using $this->mountTableAction('view', '01jae6rvajt6y1w4twyms7b3wv'); The autoclose happens again but now a blur on the screen does appear.
No description
Proculair B.V.
This is the action I use to test:
->headerActions([
Action::make('test')
->button()
->action(function () {
$this->mountTableAction('view', '01jae6rvajt6y1w4twyms7b3wv');
}),
])
->headerActions([
Action::make('test')
->button()
->action(function () {
$this->mountTableAction('view', '01jae6rvajt6y1w4twyms7b3wv');
}),
])
Why when triggering the mountTableAction manually does the params get set to the action name instead of the value I pass?
No description
Proculair B.V.
I've also tried the following: https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component#programmatically-triggering-actions
->headerActions([
Action::make('test')
->button()
->action(function () {
$contact = $this->getOwnerRecord()->contacts()->first();
$livewire->mountAction('view', [$contact->id]);
}),
])
->actions([
ViewAction::make(),
])
->headerActions([
Action::make('test')
->button()
->action(function () {
$contact = $this->getOwnerRecord()->contacts()->first();
$livewire->mountAction('view', [$contact->id]);
}),
])
->actions([
ViewAction::make(),
])
This just results in nothing happening Okay I've made some progress. This works:
->headerActions([
Action::make('header')
->action(function (Livewire $livewire) {
$record = $this->getOwnerRecord()->contacts()->first();
$this->replaceMountedTableAction('view', $record->id);
}),
])
->actions([
ViewAction::make(),
])
->headerActions([
Action::make('header')
->action(function (Livewire $livewire) {
$record = $this->getOwnerRecord()->contacts()->first();
$this->replaceMountedTableAction('view', $record->id);
}),
])
->actions([
ViewAction::make(),
])
Now I want to figure out how to trigger this behaviour from another place in livewire
Solution
Proculair B.V.
I figured it out! 🥳
Proculair B.V.
Gist
Filament V3 - Deeplink RelationManager
Filament V3 - Deeplink RelationManager. GitHub Gist: instantly share code, notes, and snippets.
Want results from more Discord servers?
Add your server