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: #3621 - AddNavigationNode - Search in sub nodes for id #3625

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Commands/Model/SharePoint/NavigationNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class NavigationNode
public bool IsHidden { get; set; }
public bool IsTitleForExistingLanguage { get; set; }
public string Key { get; set; }
public List<object> Nodes { get; set; }
public List<NavigationNode> Nodes { get; set; }
public int NodeType { get; set; }
public bool? OpenInNewWindow { get; set; }
public string SimpleUrl { get; set; }
Expand Down
14 changes: 13 additions & 1 deletion src/Commands/Navigation/AddNavigationNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ protected override void ExecuteCmdlet()
CurrentWeb.EnsureProperties(w => w.Url);
var menuState = Utilities.REST.RestHelper.GetAsync<Model.SharePoint.NavigationNodeCollection>(Connection.HttpClient, $"{CurrentWeb.Url}/_api/navigation/MenuState", ClientContext.GetAccessToken(), false).GetAwaiter().GetResult();

var currentItem = menuState?.Nodes?.Where(t => t.Key == addedNode.Id.ToString()).FirstOrDefault();
var currentItem = menuState?.Nodes?.Select(node => SearchNodeById(node, addedNode.Id))
.FirstOrDefault(result => result != null);
if (currentItem != null)
{
currentItem.OpenInNewWindow = OpenInNewTab.ToBool();
Expand All @@ -150,5 +151,16 @@ protected override void ExecuteCmdlet()
throw new Exception("Unable to define Navigation Node collection to add the node to");
}
}

private static Model.SharePoint.NavigationNode SearchNodeById(Model.SharePoint.NavigationNode root, int id)
{
if (root.Key == id.ToString())
{
return root;
}

return root.Nodes.Select(child => SearchNodeById(child, id)).FirstOrDefault(result => result != null);
}

}
}
Loading