Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with $arguments in visible closure on Filament\Actions\Action: Empty Arguments and Disabled Actions #14391

Open
Kane-R-G opened this issue Sep 30, 2024 · 2 comments
Labels

Comments

@Kane-R-G
Copy link

Kane-R-G commented Sep 30, 2024

Package

filament/actions

Package Version

v3.2.115

Laravel Version

v11.25.0

Livewire Version

v3.5.6

PHP Version

PHP 8.3

Problem description

There are 2 main bugs in the provided repo:

  1. $arguments is empty inside the visible closure on an Action (Filament\Actions\Action) when provided through a blade file. The arguments work fine in other closures (see modalDescription)
@if($this->testVisibleAction->isVisible())
        {{ ($this->testVisibleAction)(['message' => 'HELLO']) }}
@endif
public function testVisibleAction(): Action
{
        return Action::make('testVisible')
            ->visible(fn(array $arguments) => dd($arguments))
            ->requiresConfirmation()
            ->modalDescription(fn(array $arguments) => 'Message from arguments:' . $arguments['message'])
            ->action(fn() => Notification::make()->success()->title('testVisible Success')->send());
}

Result:

[] // app/Livewire/SubscriptionManagement.php:134
  1. Using $arguments inside the closure causes the button to become disabled even when the result returns true from that closure. If you have other actions on the page and then activate one, the actions that use $arguments within the closure disappear from the page while the new modal is open, and reappear when its closed.

===================

The repo can be spun up using Laravel sail for ease.

composer install && npm install
./vendor/bin/sail up
./vendor/bin/sail npm run dev

Same login credentials as the example for test panel:

'email' => '[email protected]',
'password' => 'password',

Showing 2 buttons disabled when they should be enabled.
Screenshot 2024-09-30 162912

After clicking on an enabled action, those actions using $arguments inside the closure are hidden.
Screenshot 2024-09-30 162933

NOTE: If the result of the closure is false, then it hides the button correctly.

Expected behavior

  1. $arguments inside the visible closure should be populated if arguments are present.

  2. Using $arguements inside the visible closure should show an enabled action if the result of that closure is true.

Steps to reproduce

Since I used sail in the repo, I'll use it in these steps as well.

  1. Create a custom page - sail artisan make:filament-page TestAction
  2. Add required traits and interfaces to new page -
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;

class TestAction extends Page implements HasActions
{
    use InteractsWithActions;
  1. Create 2 actions - this will allow you to test the disappearing and reappearing bug.
public function testVisibleAction(): Action
{
    return Action::make('testVisible')
        ->visible(fn(array $arguments): bool => count($arguments) == 0)
        ->requiresConfirmation()
        ->modalDescription(fn(array $arguments) => 'Message from arguments:' . $arguments['message'])
        ->action(fn() => Notification::make()->success()->title('testVisible Success')->send());
}

public function testVisibleHardCodedAction(): Action
{
    return Action::make('testVisibleHardCoded')
        ->visible(true)
        ->requiresConfirmation()
        ->modalDescription(fn(array $arguments) => 'Message from arguments:' . $arguments['message'])
        ->action(fn() => Notification::make()->success()->title('testVisibleHardCoded Success')->send());
}
  1. Add action and visibility check into blade file (along with action modals blade).
<x-filament-panels::page>
    @php
        $arguments = ['message' => 'HELLO'];
    @endphp

    @if($this->testVisibleAction->isVisible())
        {{ ($this->testVisibleAction)($arguments) }}
    @endif

    @if($this->testVisibleHardCodedAction->isVisible())
        {{ ($this->testVisibleHardCodedAction)($arguments) }}
    @endif

    <x-filament-actions::modals />
</x-filament-panels::page>
  1. Test action on page.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/Kane-R-G/filament-action-bug

Relevant log output

No response

Donate 💰 to fund this issue

  • You can donate funding to this issue. We receive the money once the issue is completed & confirmed by you.
  • 100% of the funding will be distributed between the Filament core team to run all aspects of the project.
  • Thank you in advance for helping us make maintenance sustainable!
Fund with Polar
@Kane-R-G Kane-R-G added bug Something isn't working medium priority unconfirmed labels Sep 30, 2024
@howdu
Copy link
Contributor

howdu commented Sep 30, 2024

Does it work if you create the action with arguments first?

@php
$testVisibleAction = ($this->testVisibleAction)(['message' => 'HELLO']);
@endphp

@if($testVisibleAction->isVisible())
        {{ $testVisibleAction }}
@endif

@Kane-R-G
Copy link
Author

Kane-R-G commented Sep 30, 2024

Thanks for the response. Weirdly, that example allows everything to work as expected.

The below code still causes the same issue though.

@if($this->testVisibleAction->isVisible())
        {{ ($this->testVisibleAction)(['message' => 'HELLO']) }}
@endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

2 participants