feat(menu): let menu files start nested groups collapsed
Why
A menu file with deep nesting opens every nested group expanded. With a large schema, for example an SD-WAN menu with Features > System features > 15 items, the menu panel is several screens long and the user scrolls to find the group they want. The menu author has no way to choose which groups start collapsed.
This PR adds a collapsed key to menu items in the menu file. The default stays as today: every group is expanded.
Not part of this PR:
- a depth rule such as "collapse the deepest level"
- remembering the user's expand and collapse choices between opens
- the namespace list in the schema view
- collapse or expand all (IFC-191)
Request: internal Slack thread
What changed
- A menu author sets
collapsed: trueon a nested group in a menu file. When the user opens the top-level menu item, that group shows only its label and chevron, and its children stay hidden until the user selects the chevron. - A group with
collapsed: truestill opens when the current page is under the path of one of its items. This covers list pages, detail pages (/objects/<Kind>/<id>) and menu paths with a query string, a fragment or a trailing slash. For an item with a generickind, a node's detail page does not open the group, because its URL uses the node's own kind. - Each time the menu panel opens, it starts again from the menu file setting.
- On a leaf item, a top-level item or an item in the internal section, the key has no effect and the file still loads.
GET /api/menureturnscollapsedon every item.
Implementation notes:
collapsedis a new Boolean attribute with defaultfalseon theCoreMenugeneric. Existing menu items getfalsethrough the normal core schema update. There is no hand-written migration and no graph version bump.- On a branch whose schema still predates the attribute, the menu API reads
collapsedasfalseinstead of failing. - The frontend computes the initially expanded groups from
collapsedand the current path. There is no new frontend state.
What stayed the same: the built-in menu does not set the key, so it looks the same as before.
How to review
backend/infrahub/core/schema/definitions/core/menu.pyandbackend/infrahub/menu/models.pyfrontend/app/src/entities/navigation/ui/sidebar/sidebar-menu-section-object.tsx(getDefaultExpandedKeys,isCurrentPage)- the tests in
backend/tests/unit/menu/,backend/tests/component/menu/,backend/tests/component/cli/test_core_schema_diff.pyandsidebar-menu-section-object.test.tsx - the docs in
docs/docs/reference/menu.mdxanddocs/docs/menu/nested-menus.mdx
Generated files, no need to read them closely: backend/infrahub/core/protocols.py, backend/tests/protocols.py, schema/openapi.json, schema/schema.graphql, frontend/app/src/shared/api/rest/types.generated.ts, frontend/app/src/shared/api/graphql/generated/*.
The spec, plan and implement report are in dev/specs/008-menu-collapsed-default/.
Please look closely at:
- Removing
collapsed: truefrom a menu file and loading it again keeps the stored value, because a menu load only sends the keys that are in the file. The docs tell authors to setcollapsed: falseinstead. A component test confirms the behavior. - Two known limitations that I did not fix:
- a menu entry that points to a generic kind does not open its group on an object's detail page, because the detail URL uses the concrete kind
- the built-in menu sync resets
collapsedon built-in groups at startup, the same way it does for labels and icons
How to test
uv run pytest backend/tests/unit/menu backend/tests/component/menu backend/tests/component/cli/test_core_schema_diff.py
cd frontend/app && pnpm vitest run src/entities/navigation/ui/sidebar
Manual check: load a menu file with collapsed: true on a nested group and open its top-level item. The group is collapsed. Then go to a page inside that group and open the item again. The group is expanded.
Impact & rollout
- Backward compatibility: additive. Menu files without the key behave as before. A menu file that uses
collapsedfails to load on Infrahub 1.12.4 and earlier, and the reference docs name 1.12.5 as the first release with the key. - Deployment notes: depends on opsmill/infrahub-sdk-python#1560. The
python_sdkpointer here references that commit, so this PR stays in draft until the SDK PR merges. - Core schema change: AGENTS.md lists this as "ask first". It is not confirmed with the frontend team yet.
Checklist
- Tests added/updated
- Changelog entry added
- External docs updated
- Internal .md docs updated
- I have reviewed AI generated content