From c16becc1481a3d73965c68bcb6c6f213465798bc Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Mon, 3 Apr 2017 12:15:10 -0700 Subject: [PATCH] render/detailed: When summarising children, add fallback for unlisted topologies Currently, if a topology does not have any specific info in nodeSummariesByID, any children of the node that belong to that topology will be silently omitted. This change adds a default behaviour for such topologies, with no special columns but at least it is displayed at all. Unlisted topologies are displayed after all listed ones, in arbitrary order. Note that completely bogus or other special cases (eg. topology = Pseudo) still will not be displayed as report.Topology() will fail. --- render/detailed/node.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/render/detailed/node.go b/render/detailed/node.go index fc5147ff7..cd637c688 100644 --- a/render/detailed/node.go +++ b/render/detailed/node.go @@ -246,14 +246,37 @@ func children(r report.Report, n report.Node) []NodeSummaryGroup { }) nodeSummaryGroups := []NodeSummaryGroup{} + // Apply specific group specs in the order they're listed for _, spec := range nodeSummaryGroupSpecs { if len(summaries[spec.topologyID]) > 0 { sort.Sort(nodeSummariesByID(summaries[spec.TopologyID])) group := spec.NodeSummaryGroup group.Nodes = summaries[spec.topologyID] nodeSummaryGroups = append(nodeSummaryGroups, group) + delete(summaries, spec.topologyID) } } + // As a fallback, in case a topology has no group spec defined, add any remaining at the end + for topologyID, nodeSummaries := range summaries { + if len(nodeSummaries) == 0 { + continue + } + topology, ok := r.Topology(topologyID) + if !ok { + continue + } + apiTopology, ok := primaryAPITopology[topologyID] + if !ok { + continue + } + sort.Sort(nodeSummariesByID(nodeSummaries)) + group := NodeSummaryGroup{ + ID: apiTopology, + Label: topology.LabelPlural, + Columns: []Column{}, + } + nodeSummaryGroups = append(nodeSummaryGroups, group) + } return nodeSummaryGroups }