Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ItemMenu sort issue #631

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions sqladmin/_menu.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)