Skip to content

Feat: automation tab counts - #2937

Merged
nhoening merged 4 commits into
mainfrom
feat/automation-tab-counts
Dec 4, 2026
Merged

nhoening merged 4 commits into
mainfrom
feat/automation-tab-counts

Conversation

@BelhsanHmida

@BelhsanHmida BelhsanHmida commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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)".

  • Each tab says how many automations its table lists.
  • The count is rendered server-side for the first listing, so it is there from the start rather than popping in.
  • After that, the count follows the "Include automations of sub-assets" toggle and the monitoring filter, as it counts the rows the table holds.
  • The page opens on the first tab with automations in it, rather than on an empty Forecasts tab next to it.
    An asset without automations still opens on Forecasts, and after loading the tab stays where the user puts it.
  • Added changelog entry

Look & Feel

pr-riverside

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

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

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>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida
BelhsanHmida requested a review from nhoening December 3, 2026 08:49

@nhoening nhoening left a comment

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.

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_offspring vs. assets_it_can_list, both governed by the automations_page_include_child_assets session key), and both walk asset.automations, so the rendered counts match the first listing exactly — no popping in or off-by-one.
  • Counter's zero default makes automation_counts_at_first[type_id] > 0 and 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, showTabCounts is called from renderAutomationsTables, 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).
  • showTabsInUse already self-heals the case where the active tab gets hidden, so the new automation_type_open_at_first interacts safely with hidden plugin tabs.

Minor observations (non-blocking):

  1. The fallback of automation_type_open_at_first (views.py:324-333) picks next(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 from always_shown_automation_types first would make the "opens on Forecasts" claim unconditional.
  2. The counts inside the tab button are re-read via textContent on 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 in label() style helpers would include it. Fine as-is.
  3. 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.
  4. Sandbox verification note: flexmeasures/ui/tests/js/test_automation_actions.py::test_a_tab_arrives_with_the_count_of_the_first_listing passes 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
@BelhsanHmida

Copy link
Copy Markdown
Contributor Author

Done for 1: an asset without automations now falls back to the first built-in tab.
Ticked the changelog box as well.

@BelhsanHmida
BelhsanHmida requested a review from nhoening December 4, 2026 00:33

@nhoening nhoening left a comment

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.

Thanks!

@nhoening
nhoening merged commit f6684ea into main Dec 4, 2026
11 checks passed
@nhoening
nhoening deleted the feat/automation-tab-counts branch December 4, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automations page tabs don't say how many automations they hold

2 participants