From d37ba44f0a71285d133463e078c057d7cba97f38 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Mon, 25 Sep 2023 10:05:38 +0200 Subject: [PATCH 1/2] Fix ItemMenu sort issue --- sqladmin/_menu.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sqladmin/_menu.py b/sqladmin/_menu.py index f85a5a5b..869b6b9a 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, Optional, List, 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) From 3736bd01bb60357c00352fbcf04aa03779b4af24 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Mon, 25 Sep 2023 10:27:51 +0200 Subject: [PATCH 2/2] fix imports --- sqladmin/_menu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqladmin/_menu.py b/sqladmin/_menu.py index 869b6b9a..7af2a85c 100644 --- a/sqladmin/_menu.py +++ b/sqladmin/_menu.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, List, Optional, Union from starlette.datastructures import URL from starlette.requests import Request