jeroennoten / Laravel-AdminLTE

Easy AdminLTE integration with Laravel
MIT License
3.78k stars 1.08k forks source link

Improve the menu builder class #1277

Closed dfsmania closed 2 months ago

dfsmania commented 2 months ago
Question Answer
Pull request type ENHANCEMENT
License MIT

What's in this PR?

Improve the menu builder internal logic. Previously, the menu was recompiled completely each time a call to the methods addAfter(), addBefore() and addIn() was performed, and the recompilation was done against an already compiled version of the menu, this was not so good at performance. Also, there were some bugs when removing an active item from a nested submenu, since the menu was not recompiled and the root submenu containing that item remainded active.

We can solve all these issues by keeping a raw (uncompiled) version of the menu internally, and with a flag to indicate that the menu needs a recompilation after issuing one or multiple calls to the methods that changes the menu. This way the compiled version of the menu may be generated only when the client tries to access it, or when the client tries to access an old compiled version of the menu.

In this PR we apply the previous ideas to the menu builder, and we cover the bugs mentioned with some additional tests. Also we add a better documentation to the code.

Checklist