Fix bug in sidebar when menu item is not present
What does this MR do?
In the project refactor code, there is an edge case that we have to fix. Sidebars::Menu
object has two methods insert_item_before
and insert_item_after
that allow us to insert menu items at specific positions.
insert_item_before
when the item exists, we insert the new menu before the item. If not, we insert the new item at the beginning of the list.
insert_item_after
when the item exists, we insert the new menu after the item. If not, we insert the new item at the end of the list.
We mostly use these methods in EE to insert EE menus in specific positions using the list coming from CE. But, if the menu item doesn't exist we'll add them in a position we don't want.
When we define new menu items, we usually do:
def foo_menu_item
return unless condition
Sidebars::MenuItem.new(...)
end
This means that we can return nil
menu items and the scenario where the menu item in EE is inserted at the beginning or end of the item list can happen. In order to fix this, we need to always return a menu item.
In this MR we're introducing the Null object pattern by introducing the NilMenuItem
. This new menu item will be returned whenever the user cannot render a menu item. It will be added to the list (therefore, it can be referenced when placing other menus) but not rendered.
In !61164 (closed), we will update all menu items to return the new NilMenuItem
.
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have not included a changelog entry because it's a tooling change.
-
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Separation of EE specific content