Skip to content

Display only top-level assets per default - #2523

Open
Ahmad-Wahid wants to merge 4 commits into
mainfrom
feature/2518-top-level-assets-only
Open

Display only top-level assets per default#2523
Ahmad-Wahid wants to merge 4 commits into
mainfrom
feature/2518-top-level-assets-only

Conversation

@Ahmad-Wahid

@Ahmad-Wahid Ahmad-Wahid commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Description

  • Add a "Top-level only" checkbox, checked per default, to the asset listing on the account page and on /assets. When checked, the listing asks the API for depth=0, so only assets without a parent asset are returned; unchecking it restores the full listing.
  • On the account page the checkbox sits left of the one for public assets, as the issue asks.
  • GET /api/v3_0/assets now applies the root/depth subtree constraint to num-records as well, not just to the paginated query. Without this, a listing scoped to a subtree reports every asset outside it as filtered from N total entries in the table footer.
  • Added changelog item in documentation/changelog.rst (plus a v3.0-36 entry in documentation/api/change_log.rst)

No new API parameter was needed: the existing depth parameter already means "how many generations of descendants to include", and depth=0 (without a root) selects exactly the assets that have no parent asset.

Look & Feel

image

How to test

  • flexmeasures/api/v3_0/tests/test_assets_api.py::test_get_assets_top_level_onlydepth=0 drops the descendants, and the same listing without it includes them (so the assertion is not vacuous).
  • flexmeasures/api/v3_0/tests/test_assets_api.py::test_get_assets_top_level_only_record_countsnum-records then counts the top-level assets only.
  • flexmeasures/ui/tests/test_asset_crud.py::test_assets_page_defaults_to_top_level_assets and flexmeasures/ui/tests/test_account_crud.py::test_account_page_defaults_to_top_level_assets — both listings render the checkbox checked.

To prove the new tests can fail: passing max_depth=None into filter_assets_under_root in the index endpoint turns both API tests red; reverting only the num-records part turns just the record-counts test red; dropping the checked attribute from the two templates turns both UI tests red.

Test runs: flexmeasures/ui passes in full (133 passed). flexmeasures/api passes (461 passed) with test_jobs_api.py, test_asset_jobs_api_fresh_db.py, test_asset_schedules_fresh_db.py, test_sensor_schedules*.py excluded — those segfault inside HiGHS on this machine, on main as well as on this branch, so it is a local environment problem rather than a regression. CI covers them.

Further Improvements

  • assetsTableTitle on the account page is referenced by the public-assets handler but no element with that id exists, so that title update is dead code today. Left alone here.
  • The search box still searches within the selected scope, so searching while "Top-level only" is checked will not surface a matching sub-asset. Worth revisiting if it trips people up.

Related Items

Closes #2518


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

🤖 Generated with Claude Code

Ahmad-Wahid and others added 4 commits September 11, 2026 01:45
Context:
- Issue #2518 wants the asset listings to show only top-level assets per default, which the UI does by passing depth=0.
- num-records was counted from the account/type filter alone, so a listing scoped to a subtree reported every other asset as filtered out by the search.

Change:
- Apply filter_assets_under_root to the num-records count as well, whenever root or depth is given.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Context:
- Issue #2518: an organisation's asset list is hard to scan when every sub-asset is listed alongside the sites they belong to, and you cannot narrow it down without knowing what to search for.

Change:
- Add a "Top-level only" checkbox, checked per default, to the asset listing on the account page and on /assets.
- When checked, the listing requests depth=0, so the API returns only assets without a parent asset.
- On the account page, the checkbox sits left of the one for public assets, as the issue asks.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Context:
- Issue #2518 adds a "Top-level only" default to the asset listings, backed by the API's depth parameter.

Change:
- Assert that depth=0 drops the descendants from GET /assets, and that the same listing would include them without it.
- Assert that num-records then counts the top-level assets only, so nothing reads as filtered out by the search.
- Assert that both asset listings render the checkbox checked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Context:
- Issue #2518, PR #2523.

Change:
- Main changelog, under New features: the asset lists now default to top-level assets.
- API change log, as v3.0-36: num-records now respects the root/depth subtree constraint.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 flexmeasures | 🛠️ Build #34500961 | 📁 Comparing 37b7f9d against latest (819b836)

  🔍 Preview build  

3 files changed
± changelog.html
± api/change_log.html
± api/v3_0.html

@Ahmad-Wahid
Ahmad-Wahid marked this pull request as ready for review September 11, 2026 10:01

@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.

Works nicely!

I only have two small wishes:

  • Keep the two checkboxes next to each other, so we use less vertical space
  • Please add the checkbox for public asset also to the general assets view (asset.html), so the two are more alike. (also off per default)

@nhoening nhoening added this to the 1.1.0 milestone Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display only top-level assets per default

2 participants