avoid frontend hardcoded menu entries types, fix missing discord type#176
Merged
mitch10593 merged 2 commits intomainfrom Mar 12, 2026
Merged
avoid frontend hardcoded menu entries types, fix missing discord type#176mitch10593 merged 2 commits intomainfrom
mitch10593 merged 2 commits intomainfrom
Conversation
Contributor
Reviewer's GuideFrontend menu item types are no longer hardcoded; they are fetched from a new backend admin menu types endpoint and shared across components via provide/inject, fixing missing type coverage (e.g., Discord) and ensuring consistency between backend and UI. Sequence diagram for loading admin menu list types dynamicallysequenceDiagram
actor Admin
participant MenuListView
participant ApiMenu
participant BackendAdminMenu
participant MenuItemModel
Admin->>MenuListView: open admin menu list
MenuListView->>ApiMenu: getAdminMenuTypes()
ApiMenu->>BackendAdminMenu: GET /admin/menu/types
BackendAdminMenu->>MenuItemModel: read TYPES
MenuItemModel-->>BackendAdminMenu: TYPES mapping
BackendAdminMenu-->>ApiMenu: [{value,label}]
ApiMenu-->>MenuListView: types
MenuListView->>MenuListView: update typeOptions and typeLabels
Sequence diagram for loading menu tree and providing type labelssequenceDiagram
actor Admin
participant MenuTreeView
participant MenuTreeNode
participant ApiMenu
participant BackendAdminMenu
participant MenuItemModel
Admin->>MenuTreeView: open admin menu tree view
MenuTreeView->>MenuTreeView: provide menuTypeLabels
MenuTreeView->>ApiMenu: getAdminMenuTree()
ApiMenu->>BackendAdminMenu: GET /admin/menu/tree
BackendAdminMenu-->>ApiMenu: AdminMenuItemTree[]
ApiMenu-->>MenuTreeView: menu tree
MenuTreeView->>ApiMenu: getAdminMenuTypes()
ApiMenu->>BackendAdminMenu: GET /admin/menu/types
BackendAdminMenu->>MenuItemModel: read TYPES
MenuItemModel-->>BackendAdminMenu: TYPES mapping
BackendAdminMenu-->>ApiMenu: [{value,label}]
ApiMenu-->>MenuTreeView: types
MenuTreeView->>MenuTreeView: build typeLabels map
MenuTreeView->>MenuTreeNode: render tree nodes
MenuTreeNode->>MenuTreeView: inject menuTypeLabels
MenuTreeNode->>MenuTreeNode: render typeLabels[item.type]
Updated class diagram for menu types and admin menu componentsclassDiagram
class ApiMenu {
+getAdminMenuItems(params)
+getAdminMenuTypes()
+getAdminMenuTree()
+reorderAdminMenuItems(entries)
}
class AdminMenuRouter {
+get_menu_types(user)
}
class MenuItemModel {
+TYPES: dict
}
class MenuListView {
+typeOptions: Ref
+typeLabels: ComputedRef
+loadReferenceData()
}
class MenuTreeView {
+typeLabels: Ref
+loadTree()
}
class MenuTreeNode {
+typeLabels: Ref
}
MenuListView --> ApiMenu : uses
MenuTreeView --> ApiMenu : uses
ApiMenu --> AdminMenuRouter : calls
AdminMenuRouter --> MenuItemModel : reads_TYPES
MenuTreeView --> MenuTreeNode : renders
MenuTreeView --> MenuTreeNode : provides_menuTypeLabels
MenuTreeNode --> MenuTreeView : injects_menuTypeLabels
MenuListView --> ApiMenu : calls_getAdminMenuTypes
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- MenuTreeView currently couples loading the tree and loading menu types via a single Promise.all in onMounted; consider loading types independently or handling failures separately so a failure to fetch types doesn't prevent the tree from rendering.
- Type loading logic is now duplicated between MenuListView and MenuTreeView (both calling getAdminMenuTypes and building label maps); consider centralizing this in a shared composable or store to avoid multiple requests and keep the mapping logic in one place.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- MenuTreeView currently couples loading the tree and loading menu types via a single Promise.all in onMounted; consider loading types independently or handling failures separately so a failure to fetch types doesn't prevent the tree from rendering.
- Type loading logic is now duplicated between MenuListView and MenuTreeView (both calling getAdminMenuTypes and building label maps); consider centralizing this in a shared composable or store to avoid multiple requests and keep the mapping logic in one place.
## Individual Comments
### Comment 1
<location path="backend/app/api/admin_menu.py" line_range="22-23" />
<code_context>
router = APIRouter(prefix="/admin/menu", tags=["admin-menu"])
+@router.get("/types")
+async def get_menu_types(user: User = Depends(require_admin)):
+ return [{"value": k, "label": v} for k, v in MenuItem.TYPES.items()]
+
</code_context>
<issue_to_address>
**suggestion:** Define a response model for `/admin/menu/types` for stronger typing and validation.
This endpoint returns a `[{value, label}]` list but doesn’t declare a `response_model`. Defining a small Pydantic model (e.g. `MenuTypeOut`) and using `response_model=list[MenuTypeOut]` will enforce validation and produce clearer, typed API docs that match the frontend’s expectations.
Suggested implementation:
```python
class MenuTypeOut(BaseModel):
value: str
label: str
router = APIRouter(prefix="/admin/menu", tags=["admin-menu"])
```
```python
@router.get("/types", response_model=list[MenuTypeOut])
```
To compile successfully, ensure that `BaseModel` is imported at the top of this file, typically with:
`from pydantic import BaseModel`.
If your project uses a shared schema module instead of defining models inside route files, you may want to move `MenuTypeOut` to that shared schemas module and import it here instead, keeping the `response_model=list[MenuTypeOut]` line unchanged.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Load admin menu item types from the backend instead of hardcoding them in the frontend and expose a dedicated API for menu types.
New Features:
Enhancements: