Skip to content

avoid frontend hardcoded menu entries types, fix missing discord type#176

Merged
mitch10593 merged 2 commits intomainfrom
feature/175-discord-menu-entry-is-missing
Mar 12, 2026
Merged

avoid frontend hardcoded menu entries types, fix missing discord type#176
mitch10593 merged 2 commits intomainfrom
feature/175-discord-menu-entry-is-missing

Conversation

@mitch10593
Copy link
Copy Markdown
Contributor

@mitch10593 mitch10593 commented Mar 12, 2026

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:

  • Expose an admin API endpoint to retrieve menu item types with their labels.
  • Add a frontend API helper to fetch admin menu types.

Enhancements:

  • Make admin menu views load type options dynamically from the backend and share type labels across components via provide/inject to keep labels in sync with backend definitions.

@mitch10593 mitch10593 added this to the 2.1 milestone Mar 12, 2026
@mitch10593 mitch10593 self-assigned this Mar 12, 2026
@mitch10593 mitch10593 linked an issue Mar 12, 2026 that may be closed by this pull request
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Mar 12, 2026

Reviewer's Guide

Frontend 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 dynamically

sequenceDiagram
  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
Loading

Sequence diagram for loading menu tree and providing type labels

sequenceDiagram
  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]
Loading

Updated class diagram for menu types and admin menu components

classDiagram
  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
Loading

File-Level Changes

Change Details Files
Load menu type options dynamically in the admin menu list instead of using hardcoded constants.
  • Replaced hardcoded typeOptions array with a ref-based list populated from the backend.
  • Introduced getAdminMenuTypes into the reference data loading routine alongside existing menu, URL, and page fetches.
  • Converted typeLabels to a computed map derived from the dynamic typeOptions ref.
frontend/src/components/admin/MenuListView.vue
Share dynamic type labels with menu tree nodes via provide/inject to remove duplicated hardcoded mappings.
  • Injected a reactive typeLabels ref into MenuTreeNode instead of maintaining a local static mapping.
  • Provided a typeLabels ref in MenuTreeView using Vue's provide API so child nodes can consume consistent labels.
  • Populated the provided typeLabels in MenuTreeView by fetching menu types from the backend on mount and mapping them to an id-to-label lookup.
frontend/src/components/admin/MenuTreeNode.vue
frontend/src/components/admin/MenuTreeView.vue
Expose menu item types from the backend and add a frontend API client helper.
  • Added a new /admin/menu/types endpoint in the backend that returns MenuItem.TYPES as value/label pairs, gated by admin auth.
  • Implemented getAdminMenuTypes in the frontend API layer to call the new endpoint and return typed value/label results.
backend/app/api/admin_menu.py
frontend/src/api/menu.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#175 Make the menu entry types (including the new Discord type) come from the backend instead of being hardcoded in the frontend.
#175 Expose an API endpoint on the backend to return the list of available menu types used by the admin UI.

Possibly linked issues

  • #discord menu entry is missing: PR adds /admin/menu/types endpoint and loads types in frontend, removing hardcoding and restoring Discord menu option.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@mitch10593 mitch10593 merged commit 8ce3893 into main Mar 12, 2026
3 checks passed
@mitch10593 mitch10593 deleted the feature/175-discord-menu-entry-is-missing branch March 12, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

discord menu entry is missing

1 participant