JibayMcs / filament-tour

Let's embed the power of DriverJS to your filament admin panel, and guide peoples through your app
MIT License
94 stars 27 forks source link

[Bug]: route is always null on tour #5

Closed demobiel closed 2 months ago

demobiel commented 1 year ago

What happened?

At the moment I am not able to make a tour show up, unless I specificaly set the "ignoreRoutes()" to true on the tour itself.

this is the code I have on my resourceEditPage:

public function tours(): array
    {
        return [
            //this will show
            Tour::make('edit-order')
                ->steps(
                    Step::make()
                        ->title("Showing !"),
                )->alwaysShow(true)
                ->ignoreRoutes(true),

            //this will not show
            Tour::make('ddd')
                ->steps(
                    Step::make()
                        ->title("Not showing !"),
                ),
        ];
    }

I investigated the issue (a bit) and what I can see in the index.js file is:

 if (
                (conditionAlwaysShow && conditionRoutesIgnored) ||
                (conditionAlwaysShow && !conditionRoutesIgnored && conditionRouteMatches) ||
                (conditionRoutesIgnored && conditionVisibleOnce) ||
                (conditionRouteMatches && conditionVisibleOnce)
            ) {
                openTour(tour);
                break;
            }

I guess the default behaviour should be the last statement: the route matches and it has never been shown. However as my tour.route is always null, this condition is always false.

            let conditionRouteMatches = tour.route === window.location.pathname;

not sure what I am doing wrong. Do I have to register my routes where it should be visual manually (in the example given this is not done however). I don't find in the code where the routes are "automagically" set, so I guess I have to do it manually.

How to reproduce the bug

I am not sure how to reproduce this, as I am not sure that I am actually using it right...

Package Version

v3.1.0.2

PHP Version

8.1.6

Laravel Version

10.20.0

Filament Version

v3.0.31

Which operating systems does with happen with?

macOS

Notes

No response

demobiel commented 1 year ago

Investigating further I see that there is the Concern CanConstructRoute that expects a slug on the tenant, but even when I implement that I always get $tenant->slug => null. But getting further with this :)

demobiel commented 1 year ago

ok, I think I found out you expect a "slug" attribute on the tenant model. I will see if I can rework this and do a pull request so you can use the id, or defined slug attribute.

JibayMcs commented 1 year ago

I'm a bit struggling with all the requirements to calculate the correct route, because there are tenants, multiples panels, custom pages routes...

That's a functionnality that I need to rewrite, with a clear head.

demobiel commented 1 year ago

I completely understand.

I wanted to propose a PR, but I got stuck in the getURL method, I have the feeling there might be a bug on Filament's well when calculating the routes for Resourcepages (edit, list and create)

On 21 Sep 2023, at 18:17, Jibay Mcs @.***> wrote:

I'm a bit struggling with all the requirements to calculate the correct route, because there are tenants, multiples panels, custom pages routes...

That's a functionnality that I need to rewrite, with a clear head.

— Reply to this email directly, view it on GitHub https://github.com/JibayMcs/filament-tour/issues/5#issuecomment-1729897132, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC7LAWFGA7MCFUNVNUQC23X3RSA5ANCNFSM6AAAAAA475MMRI. You are receiving this because you authored the thread.

dassudip2001 commented 1 year ago

I am interested in fixing

ingmontoya commented 11 months ago

Is working fine to me, the only bug that I have so far is when I'm in the login route, it shows a

-> Error: Call to a member function getTenants() on null in file /var/www/html/vendor/jibaymcs/filament-tour/src/Tour/Traits/CanConstructRoute.php on line 21

ingmontoya commented 11 months ago

digging into it, you are trying to get the tenant from the authenticated user Filament::auth()->user() but at this stage (login) there's no auth user yet. That's why I'm getting this error: Call to a member function getTenants() on null

$tenants = Filament::getCurrentPanel()->getTenantModel()::find(Filament::auth()->user()->getTenants(Filament::getCurrentPanel()));

dcemal commented 9 months ago

digging into it, you are trying to get the tenant from the authenticated user Filament::auth()->user() but at this stage (login) there's no auth user yet. That's why I'm getting this error: Call to a member function getTenants() on null

$tenants = Filament::getCurrentPanel()->getTenantModel()::find(Filament::auth()->user()->getTenants(Filament::getCurrentPanel()));

did you manage to fix this? I keep getting "Call to a member function getTenants() on null"

ingmontoya commented 9 months ago

digging into it, you are trying to get the tenant from the authenticated user Filament::auth()->user() but at this stage (login) there's no auth user yet. That's why I'm getting this error: Call to a member function getTenants() on null $tenants = Filament::getCurrentPanel()->getTenantModel()::find(Filament::auth()->user()->getTenants(Filament::getCurrentPanel()));

did you manage to fix this? I keep getting "Call to a member function getTenants() on null"

No sir, I couldn't... just waiting to see if there's a solution from the author.

jamessessford commented 6 months ago

Hi all,

I encountered this error today and got around it by adding a check in the tours function to return an empty array if a user isn't logged in:

class ListDocuments extends ListRecords
{
    use HasTour;
    ...

    public function tours(): array
    {
        if (! request()->user()) {
            return [];
        }

        return [
            Tour::make('list_documents')
                ->steps(
                    Step::make('.fi-ta')
                        ->title('Your documents')
                        ->description('This table contains all of your and your teams documents. From here you can edit or delete them'),
                    Step::make('[data-id=new_document]')
                        ->title('New document')
                        ->description('Clicking here will allow you to create a new document')
                        ->icon('heroicon-o-document')
                        ->iconColor('primary'),
                ),
        ];
    }
}

With this change I can use all of the authentication pages without an error and the tours work on the pages I have defined them

JibayMcs commented 2 months ago

Hi ! This bug will be fixed in the next release :)

JibayMcs commented 2 months ago

Fixed here (I hope so): https://github.com/JibayMcs/filament-tour/releases/tag/v3.1.0.6