F
Filament2y ago
eazy

Open an action from another action

I have the following InfoListAction:
Actions::make([
Action::make('close_configuration')
->extraModalFooterActions(fn(Action $action): array => [
$action
->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label(__('machine-configurations.close and create new'))
->color('success'),
])
->requiresConfirmation()
->action(function (Machine $record, array $arguments, CloseMachineConfiguration $closeMachineConfiguration, Action $action) {
if ($record->activeMachineConfiguration === null) {
return false;
}

$closed = $closeMachineConfiguration($record->activeMachineConfiguration);

if (!$closed) {
$action->sendFailureNotification();
}

if ($closed) {
$action->sendSuccessNotification();
}

if (isset($arguments['another']) && $arguments['another']) {

}

return $closed;
})
])->fullWidth()
Actions::make([
Action::make('close_configuration')
->extraModalFooterActions(fn(Action $action): array => [
$action
->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label(__('machine-configurations.close and create new'))
->color('success'),
])
->requiresConfirmation()
->action(function (Machine $record, array $arguments, CloseMachineConfiguration $closeMachineConfiguration, Action $action) {
if ($record->activeMachineConfiguration === null) {
return false;
}

$closed = $closeMachineConfiguration($record->activeMachineConfiguration);

if (!$closed) {
$action->sendFailureNotification();
}

if ($closed) {
$action->sendSuccessNotification();
}

if (isset($arguments['another']) && $arguments['another']) {

}

return $closed;
})
])->fullWidth()
Now when the another argument is set I want to open another action that is declared down later on
15 Replies
eazy
eazyOP2y ago
$this->getAction('email')->visible(true);
$this->replaceMountedAction('email');
$this->getAction('email')->visible(true);
$this->replaceMountedAction('email');
I'm not sure where I should call these functions on in the infolistaction
cheesegrits
cheesegrits2y ago
Give that $this->replaceModalAction('name') a go in your action() closure, see if it works.
eazy
eazyOP2y ago
Method App\Livewire\Machines\ViewMachine::replaceModalAction does not exist.
Method App\Livewire\Machines\ViewMachine::replaceModalAction does not exist.
cheesegrits
cheesegrits2y ago
At the end of your action() closure. I don't think that return you have there does anything, don't think ->action() expects a return.
eazy
eazyOP2y ago
Aight I don't think my component has those action methods since I'm not using the traits And I'm using the actions inside the infolist component
cheesegrits
cheesegrits2y ago
Hmm, yeah, may not work there. I have to crash, I'll do some source diving tomorrow, see what I can see. I think the component has to implement the HasActions contract.
eazy
eazyOP2y ago
Hmm okay Thanks for the help anyway
cheesegrits
cheesegrits2y ago
So my component looks like ...
class DFPCForm extends Component implements HasForms, HasActions
class DFPCForm extends Component implements HasForms, HasActions
eazy
eazyOP2y ago
Yeah maybe I'll just create separate actions for it then And place them outside of my infolist
cheesegrits
cheesegrits2y ago
As I said in chat, Dan did this for me in a kind of quick and dirty way, so it may not work everywhere. But chaining actions is something I find really useful, so I'll be pursuing it as v3 matures.
eazy
eazyOP2y ago
Yeah it's really useful to me too and I think to a lot of different users too
cheesegrits
cheesegrits2y ago
Dan is kinda swamped right now, so I don't want to bug him about it. But once things calm down a bit, I'm going to be trying to convince him to make this a more solid feature.
eazy
eazyOP2y ago
Aight, I'm gonna dive into the source to see if I can somehow acces those methods on the InfoListAction or if there are other methods for it
cheesegrits
cheesegrits2y ago
Aight. G'nite.
eazy
eazyOP2y ago
Good night, thanks for your input!

Did you find this page helpful?