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

Redirecting to a download in an Action within a modal causes the modal to reopen on next close #15141

Open
ahamilton9 opened this issue Dec 19, 2024 · 6 comments
Labels

Comments

@ahamilton9
Copy link

Package

filament/filament

Package Version

v3.2.131

Laravel Version

v11.36.1

Livewire Version

v3.5.12

PHP Version

PHP 8.3.14

Problem description

After clicking on an Action that is set to redirect to a download attachment URL (that will open the download dialog) inside a modal, then closing the modal, the modal reopens one time.

Expected behavior

That the modal does not reopen at all.

Steps to reproduce

In the reproduction repository:

  • composer install, php artisan key:generate, php artisan migrate --seed
  • Head to /admin
  • Login as [email protected] password test
  • Click on the "Test" page
  • Click on the "Actions" header action in the top right
  • Click on the "Download" Action (will try to download Github Desktop)
  • Cancel or Accept
  • Click "Close"
  • Note the modal reopens. Close again
  • Modal closes properly

The related code is in app/Filament/Pages/Test.php:

Action::make('actions')
    ->modal()
    ->extraModalFooterActions([
        Action::make('download')
            ->action(function() {
                // This works, but causes the containing modal to reopen when it is next closed.
                // I cannot use url() instead of action() because I also need to run other logic.
                $this->redirect('https://central.github.com/deployments/desktop/desktop/latest/win32');
            })
        ])

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

https://github.com/ahamilton9/filament-issue

Relevant log output

No response

@tonypartridge
Copy link
Contributor

tonypartridge commented Dec 23, 2024

You should be able to use URL with a closure?

->extraModalFooterActions([
    Action::make('download')
        ->url(fn($record) => 'https://central.github.com/deployments/desktop/desktop/latest/win32')
        ->openUrlInNewTab(),
])

@ahamilton9
Copy link
Author

The problem is the url method runs on page load so the link tracking I'm trying to implement is triggered on page load as well, which makes the data unusable. Additionally, using the url method seems to ignore the action method. That makes sense since it's probably an action underneath but means I have no hook for the code I need to run.

@tonypartridge
Copy link
Contributor

But the url isn't accessed on page load....

@ahamilton9
Copy link
Author

Tested locally in my project, and the url method is being triggered when the modal is opened. So not page load, but still before I need it to trigger.

@tonypartridge
Copy link
Contributor

Tested locally in my project, and the url method is being triggered when the modal is opened. So not page load, but still before I need it to trigger.

the url should be loaded but not opened, tracking should only work on a page load. Unless you are tracking for where the url is loaded in the DOM

@ahamilton9
Copy link
Author

I need to track when the url is accessed. This is a Download button, and we want to know how many people have downloaded the content item. By putting the tracking code in the url method, it gets run when the modal is opened which does not mean they have actually accessed the button yet. When using the url method, the action method is ignored, which is where I would put the tracking code if it was still run. Where can I place my tracking code so that it is run when the button is actually pressed?

// This runs the tracking code when the modal is loaded, assuming to prep the URL
->url(function() {myTrackingCode(); return 'https://url.com';})

// This doesn't run the action()
->url('https://url.com')->action(function() {myTrackingCode();})

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