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 menu item deletion #15500

Merged
merged 7 commits into from
Mar 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,18 @@ public async Task<IActionResult> Delete(string menuContentItemId, string menuIte
return NotFound();
}

var menuContentAsJson = (JsonObject)menu.Content;
Copy link
Contributor

@hyzx86 hyzx86 Mar 14, 2024

Choose a reason for hiding this comment

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

ContentElement.Content maybe is a instance of JsonDynamicObject

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, it is
image

// Look for the target menu item in the hierarchy.
var menuItem = FindMenuItem((JsonObject)menu.Content, menuItemId);
var menuItem = FindMenuItem(menuContentAsJson, menuItemId);

// Couldn't find targeted menu item.
if (menuItem == null)
{
return NotFound();
}

menu.Content.Remove(menuItemId);
var menuItems = menuContentAsJson[nameof(MenuItemsListPart)]?[nameof(MenuItemsListPart.MenuItems)] as JsonArray;
menuItems?.Remove(menuItem);

await _contentManager.SaveDraftAsync(menu);

Expand Down
Loading