|
10 | 10 | // New API: Mixins go in the mixins map.
|
11 | 11 | mixins+:: {},
|
12 | 12 |
|
13 |
| - // emptyMixin allows us to reliably do `mixin.grafanaDashboards` without |
| 13 | + // mixinProto allows us to reliably do `mixin.grafanaDashboards` without |
14 | 14 | // having to check the field exists first. Some mixins don't declare all
|
15 | 15 | // the fields, and thats fine.
|
16 |
| - local emptyMixin = { |
17 |
| - grafanaDashboards+: {}, |
| 16 | + // |
| 17 | + // We also use this to add a little "opinion": |
| 18 | + // - Dashboard UIDs are set to the md5 hash of their filename. |
| 19 | + // - Timezone are set to be "default" (ie local). |
| 20 | + // - Tooltip only show a single value. |
| 21 | + local mixinProto = { |
| 22 | + grafanaDashboards+:: {}, |
| 23 | + } + { |
| 24 | + local grafanaDashboards = super.grafanaDashboards, |
| 25 | + |
| 26 | + grafanaDashboards+:: { |
| 27 | + [filename]: |
| 28 | + local dashboard = grafanaDashboards[filename]; |
| 29 | + dashboard { |
| 30 | + uid: std.md5(filename), |
| 31 | + timezone: '', |
| 32 | + |
| 33 | + [if std.objectHas(dashboard, 'rows') then 'rows']: [ |
| 34 | + row { |
| 35 | + panels: [ |
| 36 | + panel { |
| 37 | + tooltip+: { |
| 38 | + shared: false, |
| 39 | + }, |
| 40 | + } |
| 41 | + for panel in super.panels |
| 42 | + ], |
| 43 | + } |
| 44 | + for row in super.rows |
| 45 | + ], |
| 46 | + } |
| 47 | + for filename in std.objectFields(grafanaDashboards) |
| 48 | + }, |
18 | 49 | },
|
19 | 50 |
|
20 | 51 | // Legacy extension points for you to add your own dashboards.
|
21 | 52 | grafanaDashboards+:: std.foldr(
|
22 | 53 | function(mixinName, acc)
|
23 |
| - local mixin = $.mixins[mixinName] + emptyMixin; |
| 54 | + local mixin = $.mixins[mixinName] + mixinProto; |
24 | 55 | if !std.objectHas(mixin, 'grafanaDashboardFolder')
|
25 | 56 | then acc + mixin.grafanaDashboards
|
26 | 57 | else acc,
|
|
30 | 61 |
|
31 | 62 | dashboardsByFolder+:: std.foldr(
|
32 | 63 | function(mixinName, acc)
|
33 |
| - local mixin = $.mixins[mixinName] + emptyMixin; |
| 64 | + local mixin = $.mixins[mixinName] + mixinProto; |
34 | 65 | if std.objectHas(mixin, 'grafanaDashboardFolder')
|
35 | 66 | then acc {
|
36 | 67 | [mixin.grafanaDashboardFolder]: mixin.grafanaDashboards,
|
|
0 commit comments