Repository navigation
Feat: automation tab counts - #2937
Merged
Merged
Conversation
A tab reads "Forecasts (2)" or "Schedules (0)", so what an asset has shows without opening each tab. The view counts the first listing, so the numbers do not pop in once the listing arrives. After that, the count follows the scope and the monitoring filter, as it counts the rows the table holds. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
An asset whose only automations are of a plugin type no longer opens on an empty Forecasts tab. An asset without automations still opens on the first tab, and the choice is made on page load only. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
📖 14 files modified
Preview · build overview · flexmeasures · built Dec. 4, 2026, 12:21 a.m. UTC |
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
nhoening
reviewed
Dec 3, 2026
nhoening
left a comment
Member
There was a problem hiding this comment.
Review
I reviewed the server-side view, the template/JS, the tests and the changelog entry, and cross-checked the counting logic against the API listing (get_automations in flexmeasures/api/v3_0/assets.py).
Correctness — looks good:
- The server-side first counts use the same scope as the first AJAX listing (
[asset] + get_readable_offspringvs.assets_it_can_list, both governed by theautomations_page_include_child_assetssession key), and both walkasset.automations, so the rendered counts match the first listing exactly — no popping in or off-by-one. Counter's zero default makesautomation_counts_at_first[type_id] > 0and the template's.get(type_id, 0)both safe for types with no automations.- Types whose plugin is gone ("plugin unavailable") are counted too, and their tabs are shown at first, consistent with #2903.
- Client-side,
showTabCountsis called fromrenderAutomationsTables, which runs on every load, on the monitoring-filter change and on the include-child-assets toggle, so the counts track the tables in all paths (including the periodic idle refresh). showTabsInUsealready self-heals the case where the active tab gets hidden, so the newautomation_type_open_at_firstinteracts safely with hidden plugin tabs.
Minor observations (non-blocking):
- The fallback of
automation_type_open_at_first(views.py:324-333) picksnext(iter(automation_types), None)— the first registered type, which is a plugin type if one registers before the built-ins. On an asset with no automations at all, the page would then open on a hidden plugin tab and jump to the first shown one once the listing arrives. In practice the built-ins register first, so this is theoretical; picking fromalways_shown_automation_typesfirst would make the "opens on Forecasts" claim unconditional. - The counts inside the tab button are re-read via
textContenton the button (tests use.trim()on the whole button label). Since the count span is the last child, no markup issues, but if the label ever grows a trailing element the JS-side trimming inlabel()style helpers would include it. Fine as-is. - PR body: "Added changelog entry" is unticked, but commit c942064 does add it to
documentation/changelog.rst(amending the #2903 bullet). Consider ticking the box. - Sandbox verification note:
flexmeasures/ui/tests/js/test_automation_actions.py::test_a_tab_arrives_with_the_count_of_the_first_listingpasses locally; the Selenium-based JS tests and the fresh-DB render test need Chrome/PostgreSQL, which this environment lacks — CI covers both (all checks green).
All CI checks pass. Nice, well-scoped change; the tests cover the empty-asset case, plugin-type counts, the sub-assets scope and the monitoring filter. From my side this is ready to merge once the nit above is considered.
…in type registered first Signed-off-by: Mohamed Belhsan Hmida
Contributor
Author
|
Done for 1: an asset without automations now falls back to the first built-in tab. |
Open
1 task done
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.
Description
The automations page has one tab per automation type, but you have to open each tab to see whether it lists anything.
This PR puts the count on each tab, so an asset with two forecasting automations and no schedules reads "Forecasts (2)", "Schedules (0)".
An asset without automations still opens on Forecasts, and after loading the tab stays where the user puts it.
Look & Feel
How to test
pytest flexmeasures/ui/tests/js/test_automation_actions.py -k count pytest flexmeasures/cli/tests/test_plugin_automations.py -k "count or tab"Or by hand: open an asset's Automations page and check each tab's count against its table, then switch "Show" to "Unmonitored automations" and toggle "Include automations of sub-assets" off; the counts follow.
Open an asset whose only automations are of a plugin type: the page opens on that tab.
Related issues
closes #2938
Sign-off