Skip to content

Commit

Permalink
fix: Ensure row panels are rendered in report
Browse files Browse the repository at this point in the history
* Get panels in collapsed rows as well for PDF report

* Add rows with collapsed panels in test dashboard

* Set images to maximum width and floating height to fit them properly in grid

Signed-off-by: Mahendra Paipuri <mahendra.paipuri@gmail.com>
mahendrapaipuri committed Mar 14, 2024

Unverified

This user has not yet uploaded their public signing key.
1 parent fc351e4 commit a94e02c
Showing 5 changed files with 374 additions and 365 deletions.
30 changes: 13 additions & 17 deletions pkg/plugin/dashboard.go
Original file line number Diff line number Diff line change
@@ -67,27 +67,20 @@ func (p Panel) Is(t PanelType) bool {
}

// Row represents a container for Panels
type Row struct {
Id int `json:"id"`
Collapsed bool `json:"collapsed"`
Title string `json:"title"`
Panels []Panel `json:"panels"`
}

// If row is visible
func (r Row) IsVisible() bool {
return r.Collapsed
type RowOrPanel struct {
Panel
Panels []Panel `json:"panels"`
}

// Dashboard represents a Grafana dashboard
// This is both used to unmarshal the dashbaord JSON into
// and then enriched (sanitize fields for TeX consumption and add VarialbeValues)
type Dashboard struct {
Title string `json:"title"`
Description string `json:"description"`
VariableValues string // Not present in the Grafana JSON structure. Enriched data passed used by the Tex templating
Rows []Row `json:"rows"`
Panels []Panel `json:"panels"`
Title string `json:"title"`
Description string `json:"description"`
VariableValues string // Not present in the Grafana JSON structure. Enriched data passed used by the Tex templating
RowOrPanels []RowOrPanel `json:"panels"`
Panels []Panel
}

// Get dashboard variables
@@ -112,11 +105,14 @@ func NewDashboard(dashJSON []byte, queryParams url.Values) Dashboard {
} else {
// Remove row panels from model
var filteredPanels []Panel
for _, p := range dashboard.Panels {
for _, p := range dashboard.RowOrPanels {
if p.Type == "row" {
if p.Panels != nil {
filteredPanels = append(filteredPanels, p.Panels...)
}
continue
}
filteredPanels = append(filteredPanels, p)
filteredPanels = append(filteredPanels, p.Panel)
}
dashboard.Panels = filteredPanels
dashboard.VariableValues = getVariablesValues(queryParams)
6 changes: 3 additions & 3 deletions pkg/plugin/dashboard_test.go
Original file line number Diff line number Diff line change
@@ -12,14 +12,14 @@ func TestDashboard(t *testing.T) {
const dashJSON = `
{"dashboard":
{
"Panels":
"panels":
[{"type":"singlestat", "id":0},
{"type":"graph", "id":1, "gridPos":{"H":6,"W":24,"X":0,"Y":0}},
{"type":"singlestat", "id":2, "Title":"Panel3Title #"},
{"type":"singlestat", "id":2, "title":"Panel3Title #"},
{"type":"text", "gridPos":{"H":6.5,"W":20.5,"X":0,"Y":0}, "id":3},
{"type":"table", "id":4},
{"type":"row", "id":5}],
"Title":"DashTitle #"
"title":"DashTitle #"
},
"Meta":
4 changes: 2 additions & 2 deletions pkg/plugin/report_test.go
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@ import (
const dashJSON = `
{"dashboard":
{
"Title":"My first dashboard",
"Panels":
"title":"My first dashboard",
"panels":
[{"type":"singlestat", "id":1},
{"type":"graph", "id":22},
{"type":"singlestat", "id":33},
2 changes: 1 addition & 1 deletion pkg/plugin/templates/report.gohtml
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@

.grid-image {
width: 100%;
height: 100%;
{{/* height: 100%; */}}
object-fit: cover;
display: block;
}
Loading

0 comments on commit a94e02c

Please sign in to comment.