From fdbf0fad6859ce67dad83202292bd9537b1009d6 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Wed, 30 Oct 2024 17:21:09 +0100 Subject: [PATCH] Create a sub menu for all elements of the schema that are placed at the top level --- backend/infrahub/menu/generator.py | 4 ++++ backend/tests/unit/menu/test_generator.py | 1 + 2 files changed, 5 insertions(+) diff --git a/backend/infrahub/menu/generator.py b/backend/infrahub/menu/generator.py index a9bd8f1868..49459797fc 100644 --- a/backend/infrahub/menu/generator.py +++ b/backend/infrahub/menu/generator.py @@ -109,6 +109,10 @@ async def generate_menu(db: InfrahubDatabase, branch: Branch, menu_items: list[C continue if not schema.menu_placement: + first_element = MenuItemDict.from_schema(model=schema) + first_element.identifier = f"{first_element.identifier}Sub" + first_element.order_weight = 1 + menu_item.children[first_element.identifier] = first_element structure.data[menu_item.identifier] = menu_item items_to_add[item_name] = True elif menu_placement := structure.find_item(name=schema.menu_placement): diff --git a/backend/tests/unit/menu/test_generator.py b/backend/tests/unit/menu/test_generator.py index 29e8baadbe..f9d8b597a3 100644 --- a/backend/tests/unit/menu/test_generator.py +++ b/backend/tests/unit/menu/test_generator.py @@ -86,6 +86,7 @@ async def test_generate_menu_top_level( assert menu assert "TestMenu0" in menu.data.keys() assert "TestCar" in menu.data.keys() + assert "TestCarSub" in menu.data["TestCar"].children.keys() async def test_generate_menu_default(