reporting: health: persist category/subject/granularity selection in the URL - #10490
Open
issmirnov wants to merge 1 commit into
Open
reporting: health: persist category/subject/granularity selection in the URL#10490issmirnov wants to merge 1 commit into
issmirnov wants to merge 1 commit into
Conversation
…the URL
Reloading the Reporting > Health page always resets the Category,
Subject, and Granularity selectors back to their defaults, discarding
whatever the user was looking at and making it impossible to bookmark
or share a specific view.
Read the three selections from the URL query string on load, falling
back to today's defaults when a value is absent or no longer valid
(e.g. a removed interface), and keep the query string in sync via
history.replaceState() as the user changes any of them.
Restoring a saved detail level needs to seed HealthGraph's
currentDetailLevel directly, since setting the select's value alone
doesn't fire its change handler. Restoring a saved category/subject
needs an explicit selectpicker('refresh') call, since bootstrap-select
only redraws its button label on that, not on a re-triggered
changed.bs.select event; this was invisible before because the only
value ever selected here was whatever the widget already displayed.
2 tasks
Author
Member
|
The more common pattern for persistence in core is to use localStorage. This doesn't cover the link-sharing use case, but then again that particular use case has rarely/never popped up over the years. I'm not sure we should go for URL params, but if we do, better to sync it with localStorage persistence |
swhite2
reviewed
Jul 8, 2026
Comment on lines
+145
to
+150
| if (savedGranularity !== null && ['0', '1', '2', '3'].includes(savedGranularity)) { | ||
| $('#detail-select').val(savedGranularity); | ||
| // .val() alone doesn't fire the change handler, so seed the graph's | ||
| // state directly or the first fetch below would use the old default | ||
| healthGraph.currentDetailLevel = savedGranularity; | ||
| } |
Member
There was a problem hiding this comment.
This block of logic is the only thing that executes on page load in tandem with the code below:
// trigger event for first category, restoring a saved selection when still valid
const categoryToSelect = (savedCategory && rrdOptions.data.hasOwnProperty(savedCategory))
? savedCategory
: Object.keys(rrdOptions.data)[0];
$('#health-category-select').val(categoryToSelect);
$('#health-category-select').selectpicker('refresh');
$('#health-category-select').trigger('changed.bs.select');
Therefore, and since touching the healthGraph internals bypassing the API is a big no-no, why not combine the two blocks and call
$('#detail-select').val(savedGranularity).trigger('change');
so the proper update() is used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Important notices
Before you submit a pull request, we ask you kindly to acknowledge the following:
If AI was used, please disclose:
Describe the problem
Reloading the Reporting > Health page always resets the Category, Subject, and Granularity selectors back to their defaults, discarding whatever the user was looking at and making it impossible to bookmark or share a specific view.
Describe the proposed solution
Read the three selections from the URL query string on load, falling back to today's defaults when a value is absent or no longer valid (e.g. a removed interface), and keep the query string in sync via
history.replaceState()as the user changes any of them.Two implementation details worth flagging for review:
HealthGraph.currentDetailLeveldirectly, since setting the select's value alone doesn't fire its change handler.selectpicker('refresh')call, since bootstrap-select only redraws its button label on that, not on a re-triggeredchanged.bs.selectevent. This was invisible before because the only value ever selected here programmatically was whatever the widget already displayed by default.Verified on a throwaway OPNsense 26.1.6 VM: set a non-default selection, confirmed the URL updates, then hard-refreshed and confirmed both the visual dropdown state and the actual data fetch (network request) use the restored values, including a graceful fallback when a saved subject is no longer valid.
Screenshots/recording to follow in a comment.
Related issue
Ref: #10489