| 1 | using AgentForge.Abstractions; |
| 2 | using AgentForge.Contracts; |
| 3 | using AgentForge.Data.Entities; |
| 4 | using AgentForge.Plugin.View; |
| 5 | using AgentForge.Plugin.View.Components; |
| 6 | |
| 7 | namespace AgentForge.Plugin.Org.Web.Components; |
| 8 | |
| 9 | internal static class ForgeViewOrgRepoTree |
| 10 | { |
| 11 | public static string Render( |
| 12 | string orgSlug, |
| 13 | string catalogBasePath, |
| 14 | IReadOnlyList<ForgeRepoGroupEntity> groups, |
| 15 | IReadOnlyList<RepoResponse> repos, |
| 16 | IReadOnlyDictionary<string, string> groupPaths, |
| 17 | ForgeOrgCatalogViewContext groupingContext, |
| 18 | IForgeOrgCatalogGrouping? grouping = null, |
| 19 | string? activeGroupPath = null) |
| 20 | { |
| 21 | if (groups.Count == 0 && repos.Count == 0) |
| 22 | return ForgeViewEmptyState.Render("No repository groups or repos yet."); |
| 23 | |
| 24 | var normalizedActive = string.IsNullOrWhiteSpace(activeGroupPath) |
| 25 | ? null |
| 26 | : ForgeRepoGroupPath.NormalizeRoute(activeGroupPath); |
| 27 | |
| 28 | var index = ForgeViewOrgCatalogIndex.Build(groups, repos, groupPaths); |
| 29 | var context = new ForgeViewOrgCatalogContext( |
| 30 | orgSlug, |
| 31 | catalogBasePath, |
| 32 | index, |
| 33 | groupPaths, |
| 34 | normalizedActive, |
| 35 | groupingContext, |
| 36 | grouping); |
| 37 | |
| 38 | var nodes = index.RootGroups |
| 39 | .Select(g => ForgeViewOrgGroupNode.Render(g, context)) |
| 40 | .ToList(); |
| 41 | |
| 42 | if (index.Ungrouped.Count > 0) |
| 43 | nodes.Add(ForgeViewOrgUngroupedNode.Render(index.Ungrouped, grouping, groupingContext)); |
| 44 | |
| 45 | return ForgeHtml.Ul("plain org-repo-tree", [.. nodes]); |
| 46 | } |
| 47 | } |
| 48 | |