Skip to content

Commit 7bd264d

Browse files
authored
Add menu item in builtin menu for templates (#5881)
1 parent 84f1c09 commit 7bd264d

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

backend/infrahub/menu/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ class MenuSection(InfrahubStringEnum):
88

99
DEFAULT_MENU = "Other"
1010
FULL_DEFAULT_MENU = "BuiltinOther"
11-
TEMPLATE_MENU = "Object templates"

backend/infrahub/menu/generator.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
from typing import TYPE_CHECKING
44

55
from infrahub.core import registry
6-
from infrahub.core.constants import InfrahubKind
76
from infrahub.core.protocols import CoreMenuItem
87
from infrahub.log import get_logger
98

10-
from .constants import FULL_DEFAULT_MENU, TEMPLATE_MENU
9+
from .constants import FULL_DEFAULT_MENU
1110
from .models import MenuDict, MenuItemDict
1211

1312
if TYPE_CHECKING:
@@ -82,11 +81,6 @@ async def generate_menu(db: InfrahubDatabase, branch: Branch, menu_items: list[C
8281

8382
items_to_add = {schema.kind: False for schema in full_schema.values() if schema.include_in_menu is True}
8483

85-
# Object templates should go into a dedicated menu item
86-
object_templates_menu = MenuItemDict(
87-
identifier=InfrahubKind.OBJECTTEMPLATE, label=TEMPLATE_MENU.title(), icon="mdi:pencil-ruler", order_weight=20000
88-
)
89-
9084
nbr_remaining_items_last_round = len(items_to_add.values())
9185
nbr_remaining_items = len([value for value in items_to_add.values() if value is False])
9286
while not all(items_to_add.values()):
@@ -101,10 +95,7 @@ async def generate_menu(db: InfrahubDatabase, branch: Branch, menu_items: list[C
10195
items_to_add[item_name] = True
10296
continue
10397

104-
if schema.namespace == "Template":
105-
object_templates_menu.children[menu_item.identifier] = menu_item
106-
items_to_add[item_name] = True
107-
elif not schema.menu_placement:
98+
if not schema.menu_placement:
10899
first_element = MenuItemDict.from_schema(model=schema)
109100
first_element.identifier = f"{first_element.identifier}Sub"
110101
first_element.order_weight = 1
@@ -121,9 +112,6 @@ async def generate_menu(db: InfrahubDatabase, branch: Branch, menu_items: list[C
121112
break
122113
nbr_remaining_items_last_round = nbr_remaining_items
123114

124-
if object_templates_menu.children:
125-
structure.data[object_templates_menu.identifier] = object_templates_menu
126-
127115
# ----------------------------------------------------------------------------
128116
# Assign the remaining items for which we couldn't find the menu_placement to the default menu
129117
# ----------------------------------------------------------------------------

backend/infrahub/menu/menu.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ def _extract_node_icon(model: MainSchemaTypes) -> str:
135135
section=MenuSection.INTERNAL,
136136
order_weight=1500,
137137
),
138+
MenuItemDefinition(
139+
namespace="Builtin",
140+
name="Templates",
141+
label="Templates",
142+
kind=InfrahubKind.OBJECTTEMPLATE,
143+
icon=_extract_node_icon(infrahub_schema.get(InfrahubKind.OBJECTTEMPLATE)),
144+
protected=True,
145+
section=MenuSection.INTERNAL,
146+
order_weight=2000,
147+
),
138148
MenuItemDefinition(
139149
namespace="Builtin",
140150
name="ResourceManager",
@@ -143,7 +153,7 @@ def _extract_node_icon(model: MainSchemaTypes) -> str:
143153
icon=_extract_node_icon(infrahub_schema.get(InfrahubKind.RESOURCEPOOL)),
144154
protected=True,
145155
section=MenuSection.INTERNAL,
146-
order_weight=2000,
156+
order_weight=2500,
147157
),
148158
MenuItemDefinition(
149159
namespace="Builtin",
@@ -153,7 +163,7 @@ def _extract_node_icon(model: MainSchemaTypes) -> str:
153163
icon=_extract_node_icon(infrahub_schema.get(InfrahubKind.ARTIFACT)),
154164
protected=True,
155165
section=MenuSection.INTERNAL,
156-
order_weight=2500,
166+
order_weight=3000,
157167
),
158168
MenuItemDefinition(
159169
namespace="Builtin",

0 commit comments

Comments
 (0)