Skip to content

menu: add Favorites section#10033

Open
Greelan wants to merge 6 commits intoopnsense:masterfrom
Greelan:favorites-refactor
Open

menu: add Favorites section#10033
Greelan wants to merge 6 commits intoopnsense:masterfrom
Greelan:favorites-refactor

Conversation

@Greelan
Copy link
Copy Markdown
Contributor

@Greelan Greelan commented Mar 25, 2026

Implements a Favorites section:

  • The section only appears if the user has at least one favorite selected. If all favorites are removed, the Favorites section disappears
  • Favorites are added/removed simply by clicking on a star icon at the right hand side of the page heading on leaf menu item pages (the star will always appear furthest right, for consistency of appearance, even if other buttons are in the heading). The star icon changes appearance if the item is in the Favorites list
  • The Favorites list is stored per-user, and is subject to their permissions
  • If a favorited menu item is removed (eg an interface is removed or a plugin uninstalled), the Favorites entry is also removed
  • Favorites entries appear in the same order as the corresponding menu items
  • The PR caters for both MVC and legacy pages

Some sample screenshots attached.

Screenshot 5 Screenshot 6

Supersedes #10028

Depends on 1c2405e

@AdSchellevis AdSchellevis self-assigned this Mar 25, 2026
@Greelan Greelan force-pushed the favorites-refactor branch from 35e4431 to c50a78a Compare March 26, 2026 05:54

if (!empty($username)) {
try {
$cfg = Config::getInstance();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to avoid direct config access, I noticed the dashboard had a similar issue, so I just refactored that in 3c3f2c4

When we build the dashboard, the User model didn't exist yet, but is backwards compatible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've refactored to mirror


// per-user favorites - generating requires getItems() call
$favorites = new \OPNsense\Core\Favorites($_SESSION['Username'] ?? '');
$this->view->menuFavorites = $favorites->buildFavoritesEntries($this->view->menuSystem);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to inject entries in a similar way as Interfaces are being injected, but it might be better to refactor some code first there as we also have the issue of menu items being conditionally being registered for isc-dhcp.

@AdSchellevis
Copy link
Copy Markdown
Member

@Greelan don't mind my comments too much, I'm reviewing your PR a bit and leaving some pointers of things we should look at, no direct action is required.

@Greelan
Copy link
Copy Markdown
Contributor Author

Greelan commented Mar 29, 2026

@Greelan don't mind my comments too much, I'm reviewing your PR a bit and leaving some pointers of things we should look at, no direct action is required.

No problem, I've made some conforming changes to address the first comment, so hopefully that helps

@AdSchellevis
Copy link
Copy Markdown
Member

@Greelan it will take some time to ingest this as I'm mostly working on this in my free time and it does need some changes in our code to ease the proces as well, but I do like your idea, the code just needs some work on both ends (the feature and hooks to inject this)

@Greelan
Copy link
Copy Markdown
Contributor Author

Greelan commented Mar 30, 2026

Absolutely fine, I was already conscious that this is lower priority given it is not on the roadmap, and you and others have plenty of other things to do. My commits and comments aren't intended to be pushy xD

@swhite2 swhite2 mentioned this pull request Mar 31, 2026
2 tasks
@Greelan
Copy link
Copy Markdown
Contributor Author

Greelan commented Apr 7, 2026

@AdSchellevis no doubt this was your intent in part, but I assume that I could use the new opnsense_menusystem.js wrapper to refactor this PR as well?

@AdSchellevis
Copy link
Copy Markdown
Member

@Greelan I'm afraid we can't do this in the frontend as we need to modify the menu as well, let me think on this for a while, it's still on the radar, just busy :)

@Greelan
Copy link
Copy Markdown
Contributor Author

Greelan commented Apr 7, 2026

All good, my thinking was just around rendering of the favorites entries and the star icons

AdSchellevis added a commit that referenced this pull request Apr 9, 2026
…ing parts out of the MenuSystem class

In most cases we use static menu registartions, but there are exceptions which depend on interfaces for example.
While looking at #10033, a longer standing wish came up again, which is the reason to add this support right now. It also helps in removing some legacy components for good via plugins.

To register new menu items, the following pattern may be used:

* In your model, derive a Menu class from MenuContainer
* implement a method collect() which should add new menu items via the appendItem() {bound to appendItem in MenuSystem}

Always try to minimize the amount of code inside these plugins as this code will be executed on each page load.
AdSchellevis added a commit that referenced this pull request Apr 9, 2026
…ing parts out of the MenuSystem class

In most cases we use static menu registartions, but there are exceptions which depend on interfaces for example.
While looking at #10033, a longer standing wish came up again, which is the reason to add this support right now. It also helps in removing some legacy components for good via plugins.

To register new menu items, the following pattern may be used:

* In your model, derive a Menu class from MenuContainer
* implement a method collect() which should add new menu items via the appendItem() {bound to appendItem in MenuSystem}

Always try to minimize the amount of code inside these plugins as this code will be executed on each page load.
AdSchellevis added a commit that referenced this pull request Apr 9, 2026
@Greelan Greelan force-pushed the favorites-refactor branch from 6580299 to 055dff6 Compare April 11, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants