diff --git a/sqladmin/_menu.py b/sqladmin/_menu.py index f85a5a5b..7af2a85c 100644 --- a/sqladmin/_menu.py +++ b/sqladmin/_menu.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, Set, Union +from typing import TYPE_CHECKING, List, Optional, Union from starlette.datastructures import URL from starlette.requests import Request @@ -12,11 +12,11 @@ def __init__(self, name: str, icon: Optional[str] = None) -> None: self.name = name self.icon = icon self.parent: Optional["ItemMenu"] = None - self.children: Set["ItemMenu"] = set() + self.children: List["ItemMenu"] = [] def add_child(self, item: "ItemMenu") -> None: item.parent = self - self.children.add(item) + self.children.append(item) def is_visible(self, request: Request) -> bool: return True @@ -85,11 +85,12 @@ def type_(self) -> str: class Menu: def __init__(self) -> None: - self.items: Set[ItemMenu] = set() + self.items: List[ItemMenu] = [] def add(self, item: ItemMenu) -> None: + # Only works for one-level menu for root in self.items: if root.name == item.name: - root.children.update(item.children) + root.children.append(*item.children) return - self.items.add(item) + self.items.append(item)