Search: Include collapsed panels in search v2 (#83047)

* Include collapsed panels in searchv2
* Include collapsed row in TestReadSummaries
This commit is contained in:
Arati R 2024-02-28 16:11:09 +01:00 committed by GitHub
parent 91cd17f012
commit 467302480f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 104 additions and 31 deletions

View File

@ -60,6 +60,23 @@ func NewStaticDashboardSummaryBuilder(lookup DatasourceLookup, sanitize bool) en
summary.Fields["schemaVersion"] = fmt.Sprint(dash.SchemaVersion)
for _, panel := range dash.Panels {
s := panelSummary(panel, uid, dashboardRefs)
summary.Nested = append(summary.Nested, s...)
}
summary.References = dashboardRefs.Get()
if sanitize {
body, err = json.MarshalIndent(parsed, "", " ")
}
return summary, body, err
}
}
// panelSummary take panel info and returns entity summaries for the given panel and all its collapsed panels.
func panelSummary(panel panelInfo, uid string, dashboardRefs ReferenceAccumulator) []*entity.EntitySummary {
panels := []*entity.EntitySummary{}
panelRefs := NewReferenceAccumulator()
p := &entity.EntitySummary{
UID: uid + "#" + strconv.FormatInt(panel.ID, 10),
@ -90,13 +107,11 @@ func NewStaticDashboardSummaryBuilder(lookup DatasourceLookup, sanitize bool) en
dashboardRefs.Add(entity.ExternalEntityReferenceRuntime, entity.ExternalEntityReferenceRuntime_Transformer, v)
}
p.References = panelRefs.Get()
summary.Nested = append(summary.Nested, p)
}
panels = append(panels, p)
summary.References = dashboardRefs.Get()
if sanitize {
body, err = json.MarshalIndent(parsed, "", " ")
}
return summary, body, err
for _, c := range panel.Collapsed {
collapsed := panelSummary(c, uid, dashboardRefs)
panels = append(panels, collapsed...)
}
return panels
}

View File

@ -45,6 +45,32 @@
"type": "panel"
}
]
},
{
"UID": "with-library-panels#3",
"kind": "panel",
"name": "collapsed row",
"fields": {
"type": "row"
}
},
{
"UID": "with-library-panels#42",
"kind": "panel",
"name": "blue pie",
"fields": {
"type": ""
},
"references": [
{
"family": "librarypanel",
"identifier": "l3d2s634-fdgf-75u4-3fg3-67j966ii7jur"
},
{
"family": "plugin",
"type": "panel"
}
]
}
],
"references": [
@ -59,6 +85,10 @@
"family": "librarypanel",
"identifier": "e1d5f519-dabd-47c6-9ad7-83d181ce1cee"
},
{
"family": "librarypanel",
"identifier": "l3d2s634-fdgf-75u4-3fg3-67j966ii7jur"
},
{
"family": "plugin",
"type": "panel"

View File

@ -49,6 +49,34 @@
"uid": "e1d5f519-dabd-47c6-9ad7-83d181ce1cee"
},
"title": "green pie"
},
{
"collapsed": true,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 9
},
"id": 3,
"panels": [
{
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 42,
"libraryPanel": {
"name": "blue pie",
"uid": "l3d2s634-fdgf-75u4-3fg3-67j966ii7jur"
},
"title": "blue pie"
}
],
"title": "collapsed row",
"type": "row"
}
],
"refresh": "",