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

Multiple dashboards leads to unrewriten URL #6603

Closed
Geolim4 opened this issue Nov 28, 2024 · 43 comments · Fixed by #6639 or #6760
Closed

Multiple dashboards leads to unrewriten URL #6603

Geolim4 opened this issue Nov 28, 2024 · 43 comments · Fixed by #6639 or #6760

Comments

@Geolim4
Copy link
Contributor

Geolim4 commented Nov 28, 2024

I have a project with multiples Dasboards:

  • src/Controller/Admin/DashboardController
    image
    image

  • src/Controller/Volunteer/DashboardController
    image
    image

All controllers under Admin/* are successfully rewritten when using MenuItem::linkToCrud()
However, all the similar controllers under Volunteer/* are not rewritten and the url contain all the CRUD queries.

For a reason I ignore, all the controller under src/Controller/Volunteer/ stay unrewritten, unless if I specify the controller CRUD route directly.

@ben29
Copy link

ben29 commented Nov 29, 2024

#6580
same like here

@Geolim4
Copy link
Contributor Author

Geolim4 commented Nov 29, 2024

I'm not exactly facing the same issue: On my side, the generated URL are "good" but aren't well rewritten.

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 1, 2024

@javiereguiluz I'm afraid this issue is a regression from some recents changes related to pretty urls :(

@ben29
Copy link

ben29 commented Dec 5, 2024

I'm not exactly facing the same issue: On my side, the generated URL are "good" but aren't well rewritten.

What happend if you click on the second dashboard?
Do you see the Admin menu?

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 5, 2024

The menu entry links are present, but stay unrewriten as you can see in my latest screenshoot :)

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 7, 2024

@javiereguiluz can you take a look at it ? It is blocking upgrades for now since only the first dashboard found has rewriten URLs.

Please note that if I use MenuItem::linkToUrl with $this->generateUrl(), url is well rewriten, but with MenuItem::linkToCrud the URL is still full of legacy queries.

@ben29
Copy link

ben29 commented Dec 8, 2024

The menu entry links are present, but stay unrewriten as you can see in my latest screenshoot :)

check the version 4.20.1

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 8, 2024 via email

@ben29
Copy link

ben29 commented Dec 8, 2024

Tried it yesterday, bug is still not fixed 😔

On Sun, 8 Dec 2024, 3:14 pm Ben Hakim, @.> wrote: The menu entry links are present, but stay unrewriten as you can see in my latest screenshoot :) check the version 4.20.1 — Reply to this email directly, view it on GitHub <#6603 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKFGZY2AZTXQZQAWPIJUR32ERH45AVCNFSM6AAAAABSV6G262VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRWGAYTQMRRGI . You are receiving this because you authored the thread.Message ID: @.>

So we stuck….

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 9, 2024

I don't know if it can helps, but when I empty the cache, on the first refresh only (that rebuild the cache) I get this error:

An exception has been thrown during the rendering of a template ("EasyCorp\Bundle\EasyAdminBundle\Router\AdminRouteGenerator::findRouteName(): Argument #1 ($dashboardFqcn) must be of type string, null given, called in E:\projets\xxxxxxxx\xxxxxxxxxxxxx\vendor\easycorp\easyadmin-bundle\src\Router\AdminUrlGenerator.php on line 291").

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 10, 2024

Hello @javiereguiluz , by digging a bit more it seems that this line with multiple dashboard controllers:

            $dashboardControllerFqcn = $this->get(EA::DASHBOARD_CONTROLLER_FQCN) ?? $context->getRequest()->attributes->get(EA::DASHBOARD_CONTROLLER_FQCN) ?? $this->dashboardControllerRegistry->getFirstDashboardFqcn();

Is unable to find a dashboard fqcn despite dashboard having the right #AdminDashboard attribute with all my allowed controllers filled in allowedControllers option.

The exception is thrown only when the cache is cold or missing, else no error is thrown but sidebar menu items have unrewriten urls.

@ben29
Copy link

ben29 commented Dec 10, 2024

Hello @javiereguiluz , by digging a bit more it seems that this line with multiple dashboard controllers:

            $dashboardControllerFqcn = $this->get(EA::DASHBOARD_CONTROLLER_FQCN) ?? $context->getRequest()->attributes->get(EA::DASHBOARD_CONTROLLER_FQCN) ?? $this->dashboardControllerRegistry->getFirstDashboardFqcn();

Is unable to find a dashboard fqcn despite dashboard having the right #AdminDashboard attribute with all my allowed controllers filled in allowedControllers option.

The exception is thrown only when the cache is cold or missing, else no error is thrown but sidebar menu items have unrewriten urls.

maybe here it's the issue.
$this->dashboardControllerRegistry->getFirstDashboardFqcn();

@ben29
Copy link

ben29 commented Dec 10, 2024

@javiereguiluz pls take a look, we stuck here with no idea what to do.
thanks!

@ServerExe
Copy link

ServerExe commented Dec 11, 2024

The introduction of the pretty URLs has also caused a similar issue I reported here: #6614

@javiereguiluz
Copy link
Collaborator

@Geolim4 thanks for sharing your application with me 🙏 I could finally reproduce the bug and fix it. See #6639. Please test it and tell me if it fixed the bug for you too. Thanks!

@ben29
Copy link

ben29 commented Dec 11, 2024

@Geolim4 thanks for sharing your application with me 🙏 I could finally reproduce the bug and fix it. See #6639. Please test it and tell me if it fixed the bug for you too. Thanks!

finally it's fixed!!! thanks you lot!

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 11, 2024

@Geolim4 thanks for sharing your application with me 🙏 I could finally reproduce the bug and fix it. See #6639. Please test it and tell me if it fixed the bug for you too. Thanks!

Thanks you @javiereguiluz ! It was hard to reproduce, but you did it !

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 11, 2024

@javiereguiluz thanks for the dashboard setBadge tip, I'll update my code asap !
You rock !

@javiereguiluz
Copy link
Collaborator

This bug fix is now part of the latest stable release: https://github.com/EasyCorp/EasyAdminBundle/releases/tag/v4.20.3 🎉

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 12, 2024

Thank you @javiereguiluz , I was happy to share my app with you and I keep it that way, so you can see a concrete use case of your framework 😺

@ben29
Copy link

ben29 commented Dec 12, 2024

@javiereguiluz there is new bug with it.

If I do on the Admin:

#[AdminDashboard(routes: [
    'index' => ['routeName' => 'index', 'routePath' => '/index'],
    'new' => ['routeName' => 'create', 'routePath' => '/create'],
    'edit' => ['routeName' => 'edit', 'routePath' => '/edit-{entityId}'],
    'delete' => ['routePath' => '/remove/{entityId}', 'routeName' => 'delete'],
    'detail' => ['routeName' => 'detail', 'routePath' => '/view/{entityId}'],
])]

the same thing on the Aff/ Or other Dashboard. the same code.

#[AdminDashboard(routes: [
    'index' => ['routeName' => 'index', 'routePath' => '/index'],
    'new' => ['routeName' => 'create', 'routePath' => '/create'],
    'edit' => ['routeName' => 'edit', 'routePath' => '/edit-{entityId}'],
    'delete' => ['routePath' => '/remove/{entityId}', 'routeName' => 'delete'],
    'detail' => ['routeName' => 'detail', 'routePath' => '/view/{entityId}'],
])]

after clicking to one links of the "Aff". it will return to the admin dashboard.

the Aff has:

#[Route(path: '/aff', name: 'affiliate')]

and admin Has:

#[Route(path: '/admin', name: 'admin')]

when I remove the "#[AdminDashboard]" from the aff, everything is working fine on the Aff.

@Geolim4
Copy link
Contributor Author

Geolim4 commented Dec 12, 2024

I also noticed a strange bug:

When I'm on a CRUD detail/edit/index page of any entity, if I empty the cache and reload the page I get this error:

An exception has been thrown during the rendering of a template ("The given "App\Controller\Admin\DashboardController" class is not a valid Dashboard controller. Make sure it extends from "EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController" or implements "EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface".").

This is not happening if I do the same thing on any dashboard pages.

@ben29
Copy link

ben29 commented Dec 21, 2024

@Geolim4
I found very 2 major problems, and one it's very major.

can you check on your side.

for example I have "admin", "Aff" dashboard.

go the "Aff" or anything other then the Admin. use the filter.
does you see the Admin menu?

@ben29
Copy link

ben29 commented Dec 22, 2024

@javiereguiluz the only issue left, it's with the filters. after filters, it will write Admin Dashboard instead of the current Dashboard.

@ben29
Copy link

ben29 commented Dec 22, 2024

I found that. when I do:

rm -rf var/cache;
php bin/console cache:clear

the issues is gone.
so maybe something with the cache.

@Geolim4
Copy link
Contributor Author

Geolim4 commented Jan 9, 2025

@javiereguiluz I just upgraded to 4.20.8 and the issue is back again :(

@Geolim4
Copy link
Contributor Author

Geolim4 commented Jan 10, 2025

Rolled back to 4.20.3 and the bug is gone, a regression has been introduced @javiereguiluz :(

@ben29
Copy link

ben29 commented Jan 10, 2025

@javiereguiluz I just upgraded to 4.20.8 and the issue is back again :(

same to me. I really give up with this new urls.

@Geolim4
Copy link
Contributor Author

Geolim4 commented Jan 10, 2025

Javier needs to create very aggressive anti-regression tests for pretty URLs, because there's a lot of regressions and side-effect introduced by patches these last weeks :(

@ben29
Copy link

ben29 commented Jan 10, 2025

Javier needs to create very aggressive anti-regression tests for pretty URLs, because there's a lot of regressions and side-effect introduced by patches these last weeks :(

Maybe create new demo
With multiple dashboards.

@javiereguiluz javiereguiluz reopened this Jan 10, 2025
@javiereguiluz
Copy link
Collaborator

Folks, we already have tests with multiple dashboards and they keep passing. I also have one Symfony app with EA and two dashboards and I can't reproduce any issue: all pretty URLs keep working in both dashboards.

So, please create a tiny reproducer application that shows the bug and I'll take a look 🙏 Thanks a lot.

@Geolim4
Copy link
Contributor Author

Geolim4 commented Jan 10, 2025

Hello Javier,

It's simple: Pretty URL are working in 4.20.3 with multiple dashboard and things changed as of 4.20.4.

@Geolim4
Copy link
Contributor Author

Geolim4 commented Jan 10, 2025

(You still have access to my application for reproducing issues)

@Geolim4
Copy link
Contributor Author

Geolim4 commented Jan 10, 2025

I suspect this commit to be the culprit one:
0a025ee
This one may introduced regressions.

@javiereguiluz
Copy link
Collaborator

@Geolim4 please, try to remove these 3 lines in your app and check if the error is gone:

if (null === $crudControllerFqcn) {
unset($routeParameters[EA::DASHBOARD_CONTROLLER_FQCN]);
}

@ben29
Copy link

ben29 commented Jan 11, 2025

@Geolim4 please, try to remove these 3 lines in your app and check if the error is gone:

if (null === $crudControllerFqcn) {
unset($routeParameters[EA::DASHBOARD_CONTROLLER_FQCN]);
}

The

Folks, we already have tests with multiple dashboards and they keep passing. I also have one Symfony app with EA and two dashboards and I can't reproduce any issue: all pretty URLs keep working in both dashboards.

So, please create a tiny reproducer application that shows the bug and I'll take a look 🙏 Thanks a lot.

It’s happened only if you click on the Dashboard,

For example if im in Admin Dashboard, and clicking going to the second dashboard,

or clicking of one of the pages

@MrJuliuss
Copy link

MrJuliuss commented Jan 14, 2025

Hi, same issue as @ben29 on 4.21.1 :/ and works great on 4.20.3

@ben29
Copy link

ben29 commented Jan 16, 2025

any update?

@ben29
Copy link

ben29 commented Jan 16, 2025

@Geolim4 please, try to remove these 3 lines in your app and check if the error is gone:

if (null === $crudControllerFqcn) {
unset($routeParameters[EA::DASHBOARD_CONTROLLER_FQCN]);
}

I try that, I doesn’t help

@Geolim4
Copy link
Contributor Author

Geolim4 commented Jan 16, 2025

@Geolim4 please, try to remove these 3 lines in your app and check if the error is gone:

if (null === $crudControllerFqcn) {
unset($routeParameters[EA::DASHBOARD_CONTROLLER_FQCN]);
}

Not working :(

@evotodi
Copy link

evotodi commented Jan 21, 2025

As I have also been having an issue with multiple dashboards I believe it would be good to also check if the adminContext is not null and get the dashboardControllerFqcn from it before defaulting to dashboardControllerRegistry->getFirstDashboardFqcn().

For me having 3 dashboards (admin = /admin, client = /manage/client, customer = manage/customer) crud links on the client and customer dashboards were always pointing to the routes prefixed with /admin instead of the /manage/xxx routes. This was due to the dashboard index routes not having the default attribute EA::DASHBOARD_CONTROLLER_FQCN set.

Setting the index route up like for all dashboards this fixes the links.

#[Route(path: '/client/manage', name: 'app_manage_client', defaults: [EA::DASHBOARD_CONTROLLER_FQCN => self::class])]
public function index(): Response

However modifying the AdminUrlGenerator removes the need for the route default attribute addition.

Subject: [PATCH] Get dashboard controller from admin context if available
---
Index: src/Router/AdminUrlGenerator.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Router/AdminUrlGenerator.php b/src/Router/AdminUrlGenerator.php
--- a/src/Router/AdminUrlGenerator.php	(revision f0ae222cefa1c73730604fbaa5f297568204bb59)
+++ b/src/Router/AdminUrlGenerator.php	(date 1737487453096)
@@ -293,7 +293,7 @@
         }
 
         if ($usePrettyUrls) {
-            $dashboardControllerFqcn = $this->get(EA::DASHBOARD_CONTROLLER_FQCN) ?? $context?->getRequest()->attributes->get(EA::DASHBOARD_CONTROLLER_FQCN) ?? $this->dashboardControllerRegistry->getFirstDashboardFqcn();
+            $dashboardControllerFqcn = $this->get(EA::DASHBOARD_CONTROLLER_FQCN) ?? $context?->getRequest()->attributes->get(EA::DASHBOARD_CONTROLLER_FQCN) ?? $context?->getDashboardControllerFqcn() ?? $this->dashboardControllerRegistry->getFirstDashboardFqcn();
             $crudControllerFqcn = $this->get(EA::CRUD_CONTROLLER_FQCN) ?? $context?->getRequest()->attributes->get(EA::CRUD_CONTROLLER_FQCN);
             $actionName = $this->get(EA::CRUD_ACTION) ?? $context?->getRequest()->attributes->get(EA::CRUD_ACTION);
 

Easyadmin 4.23.2

@javiereguiluz
Copy link
Collaborator

@evotodi thanks a lot for investigating this bug. I'm going to try your fix as soon as tomorrow.

@evotodi
Copy link

evotodi commented Jan 21, 2025

I can open a PR if you'd like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment