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: Load menu summaries without actions child. #45

Merged
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
33 changes: 28 additions & 5 deletions src/models/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ pub async fn allowed_menu(_language: Option<&String>, _client_id: Option<&String
}

fn load_valid_children(_tree: Option<Vec<MenuTree>>, _allowed_menu_items: Vec<MenuItem>) -> Vec<Menu> {
if _tree.is_none() {
return Vec::new()
}
let mut menus: Vec<Menu> = Vec::new();
let _tree: Vec<MenuTree> = _tree.unwrap();
if _tree.is_none() {
return Vec::new()
}
let mut menus: Vec<Menu> = Vec::new();
let _tree: Vec<MenuTree> = _tree.unwrap();
for _tree_value in _tree {
let _allowed_item: Option<MenuItem> = _allowed_menu_items.to_owned().into_iter().find(|_item: &MenuItem| _item.internal_id.is_some() && _item.internal_id == _tree_value.node_id);
if _allowed_item.is_some() {
Expand All @@ -230,6 +230,15 @@ fn load_valid_children(_tree: Option<Vec<MenuTree>>, _allowed_menu_items: Vec<Me
_current_menu.children = Some(children_loaded_menu);
}

// Verify if the node is summary and has children with action and not just more summaries
if _current_menu.is_summary.unwrap_or(false) {
let has_action_id: bool = has_action_in_childrens(&_current_menu);
if !has_action_id {
// If no action was found in the children, do not add the menu to the list
continue;
}
}

_loaded_menu = Some(_current_menu);
menus.push(_loaded_menu.unwrap());
}
Expand All @@ -240,3 +249,17 @@ fn load_valid_children(_tree: Option<Vec<MenuTree>>, _allowed_menu_items: Vec<Me
menus.sort_by(|a: &Menu, b: &Menu| a.sequence.cmp(&b.sequence));
menus
}

fn has_action_in_childrens(menu: &Menu) -> bool {
if let Some(children) = &menu.children {
for child in children {
if child.action_id.is_some() && child.action_id.unwrap() > 0 {
return true;
}
if has_action_in_childrens(child) {
return true;
}
}
}
false
}