Skip to content

Commit

Permalink
Auto add ID's on panels
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <[email protected]>
  • Loading branch information
roidelapluie committed Dec 24, 2017
1 parent c25a7d8 commit 788c6c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 13 additions & 6 deletions grafonnet/dashboard.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,19 @@ local timepickerlib = import "timepicker.libsonnet";
_nextPanel: nextPanel + n,
rows+: [row { panels: panels }],
},
addPanels(panels):: self {
panels+::: panels,
},
addPanel(panel, gridPos):: self {
panels+::: [panel { gridPos: gridPos }],
},
addPanels(panels)::
self {
// automatically number panels in added rows.
// https://github.com/kausalco/public/blob/master/klumps/grafana.libsonnet
local n = std.length(panels),
local nextPanel = super._nextPanel,
local _panels = std.makeArray(n, function(i)
panels[i] { id: nextPanel + i }),

_nextPanel: nextPanel + n,
panels+::: _panels,
},
addPanel(panel, gridPos):: self + self.addPanels([panel { gridPos: gridPos }]),
addRows(rows):: self {
rows+: rows,
},
Expand Down
5 changes: 5 additions & 0 deletions tests/dashboards/adds_compiled.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"y": 42
},
"height": "250px",
"id": 0,
"panels": [ ],
"repeat": null,
"repeatIteration": null,
Expand All @@ -153,6 +154,7 @@
"y": 52
},
"height": "250px",
"id": 1,
"panels": [ ],
"repeat": null,
"repeatIteration": null,
Expand All @@ -172,6 +174,7 @@
"y": 62
},
"height": "250px",
"id": 2,
"panels": [ ],
"repeat": null,
"repeatIteration": null,
Expand All @@ -191,6 +194,7 @@
"y": 72
},
"height": "250px",
"id": 3,
"panels": [ ],
"repeat": null,
"repeatIteration": null,
Expand All @@ -205,6 +209,7 @@
"collapsed": false,
"h": 41,
"height": "250px",
"id": 4,
"panels": [ ],
"repeat": null,
"repeatIteration": null,
Expand Down

0 comments on commit 788c6c8

Please sign in to comment.