F
Filament12mo 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
eazy12mo 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
cheesegrits12mo ago
Give that $this->replaceModalAction('name') a go in your action() closure, see if it works.
eazy
eazy12mo ago
Method App\Livewire\Machines\ViewMachine::replaceModalAction does not exist.
Method App\Livewire\Machines\ViewMachine::replaceModalAction does not exist.
cheesegrits
cheesegrits12mo 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
eazy12mo 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
cheesegrits12mo 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
eazy12mo ago
Hmm okay Thanks for the help anyway
cheesegrits
cheesegrits12mo ago
So my component looks like ...
class DFPCForm extends Component implements HasForms, HasActions
class DFPCForm extends Component implements HasForms, HasActions
eazy
eazy12mo ago
Yeah maybe I'll just create separate actions for it then And place them outside of my infolist
cheesegrits
cheesegrits12mo 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
eazy12mo ago
Yeah it's really useful to me too and I think to a lot of different users too
cheesegrits
cheesegrits12mo 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
eazy12mo 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
cheesegrits12mo ago
Aight. G'nite.
eazy
eazy12mo ago
Good night, thanks for your input!