Skip to content

Commit

Permalink
Fixes mounting of arguments on infolist actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MACscr authored Jan 16, 2025
1 parent ca68fd4 commit b50a988
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions packages/infolists/src/Concerns/InteractsWithInfolists.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ trait InteractsWithInfolists

public ?string $mountedInfolistActionsInfolist = null;

public ?array $mountedInfolistActionsArguments = [];

public function getInfolist(string $name): ?Infolist
{
$infolist = $this->getCachedInfolists()[$name] ?? null;
Expand Down Expand Up @@ -165,9 +167,10 @@ public function callMountedInfolistAction(array $arguments = []): mixed
return $result;
}

public function mountInfolistAction(string $name, ?string $component = null, ?string $infolist = null): mixed
public function mountInfolistAction(string $name, ?string $component = null, ?string $infolist = null, array $arguments = []): mixed
{
$this->mountedInfolistActions[] = $name;
$this->mountedInfolistActionsArguments[] = $arguments;
$this->mountedInfolistActionsData[] = [];

if (blank($this->mountedInfolistActionsComponent) && filled($component)) {
Expand Down Expand Up @@ -258,11 +261,13 @@ public function mountedInfolistActionHasForm(?Action $mountedAction = null): boo

public function getMountedInfolistAction(): ?Action
{
$actionNestingIndex ??= array_key_last($this->mountedInfolistActions);

if (! count($this->mountedInfolistActions ?? [])) {
return null;
}

return $this->getMountedInfolistActionComponent()?->getAction($this->mountedInfolistActions);
return $this->getMountedInfolistActionComponent()?->getAction($this->mountedInfolistActions)?->arguments($this->mountedInfolistActionsArguments[$actionNestingIndex] ?? []);
}

public function getMountedInfolistActionComponent(): ?Component
Expand Down Expand Up @@ -301,17 +306,15 @@ public function unmountInfolistAction(bool $shouldCancelParentActions = true, bo
$action = $this->getMountedInfolistAction();

if (! ($shouldCancelParentActions && $action)) {
array_pop($this->mountedInfolistActions);
array_pop($this->mountedInfolistActionsData);
$this->popMountedInfolistAction();
} elseif ($action->shouldCancelAllParentActions()) {
$this->mountedInfolistActions = [];
$this->mountedInfolistActionsData = [];
} else {
$parentActionToCancelTo = $action->getParentActionToCancelTo();

while (true) {
$recentlyClosedParentAction = array_pop($this->mountedInfolistActions);
array_pop($this->mountedInfolistActionsData);
$recentlyClosedParentAction = $this->popMountedInfolistAction();

if (
blank($parentActionToCancelTo) ||
Expand Down Expand Up @@ -343,6 +346,17 @@ public function unmountInfolistAction(bool $shouldCancelParentActions = true, bo
$this->openInfolistActionModal();
}

protected function popMountedInfolistAction(): ?string
{
try {
return array_pop($this->mountedInfolistActions);
} finally {
array_pop($this->mountedInfolistActionsArguments);
array_pop($this->mountedInfolistActions);
array_pop($this->mountedInfolistActionsData);
}
}

protected function makeInfolist(): Infolist
{
return Infolist::make($this);
Expand Down

0 comments on commit b50a988

Please sign in to comment.