grafana-dash-gen 3.3.0 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grafana/dashboard.js +6 -7
- package/grafana/external-link.js +3 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/test/dashboard.js +21 -8
- package/test/external-link.js +4 -4
package/grafana/dashboard.js
CHANGED
|
@@ -70,12 +70,6 @@ Dashboard.prototype._initRows = function _initRows(opts) {
|
|
|
70
70
|
Dashboard.prototype._initLinks = function _initLinks(opts) {
|
|
71
71
|
this.links = opts.links || [];
|
|
72
72
|
this.state.links = [];
|
|
73
|
-
|
|
74
|
-
this.links.forEach(link => {
|
|
75
|
-
if (!(link instanceof ExternalLink)) {
|
|
76
|
-
throw new TypeError('links must be defined using ExternalLink')
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
73
|
};
|
|
80
74
|
|
|
81
75
|
Dashboard.prototype._initTemplating = function _initRows(opts) {
|
|
@@ -125,7 +119,12 @@ Dashboard.prototype.addAnnotation = function addAnnotation(annotation) {
|
|
|
125
119
|
Dashboard.prototype.generate = function generate() {
|
|
126
120
|
// Generate jsons.
|
|
127
121
|
this.state.rows = this.rows.map(row => row.generate());
|
|
128
|
-
this.state.links = this.links.map(link =>
|
|
122
|
+
this.state.links = this.links.map(link => {
|
|
123
|
+
if (link instanceof ExternalLink) {
|
|
124
|
+
return link.generate()
|
|
125
|
+
}
|
|
126
|
+
return link
|
|
127
|
+
});
|
|
129
128
|
|
|
130
129
|
return this.state;
|
|
131
130
|
};
|
package/grafana/external-link.js
CHANGED
|
@@ -50,14 +50,17 @@ ExternalLink.prototype.generate = function generate() {
|
|
|
50
50
|
|
|
51
51
|
ExternalLink.prototype.includeVariableValues = function includeVariableValues() {
|
|
52
52
|
this.state.includeVars = true;
|
|
53
|
+
return this
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
ExternalLink.prototype.includeTimeFilter = function includeTimeFilter() {
|
|
56
57
|
this.state.keepTime = true;
|
|
58
|
+
return this
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
ExternalLink.prototype.withIcon = function withIcon(iconName) {
|
|
60
62
|
this.state.icon = iconName;
|
|
63
|
+
return this
|
|
61
64
|
};
|
|
62
65
|
|
|
63
66
|
module.exports = ExternalLink;
|
package/index.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
var Dashboard = require('./grafana/dashboard');
|
|
24
24
|
var Row = require('./grafana/row');
|
|
25
|
+
var ExternalLink = require('./grafana/external-link')
|
|
25
26
|
var Target = require('./grafana/target');
|
|
26
27
|
var Panels = require('./grafana/panels');
|
|
27
28
|
var Alert = require('./grafana/alert/alert');
|
|
@@ -35,6 +36,7 @@ var Annotations = require('./grafana/annotations');
|
|
|
35
36
|
module.exports = {
|
|
36
37
|
Dashboard: Dashboard,
|
|
37
38
|
Row: Row,
|
|
39
|
+
ExternalLink: ExternalLink,
|
|
38
40
|
Panels: Panels,
|
|
39
41
|
Templates: Templates,
|
|
40
42
|
Alert,
|
package/package.json
CHANGED
package/test/dashboard.js
CHANGED
|
@@ -109,7 +109,17 @@ test('Dashboard can generate correct body', function t(assert) {
|
|
|
109
109
|
new ExternalLink({
|
|
110
110
|
title: "Uber Homepage",
|
|
111
111
|
url: "www.uber.com",
|
|
112
|
-
})
|
|
112
|
+
}),
|
|
113
|
+
{
|
|
114
|
+
title: "Google Homepage",
|
|
115
|
+
tooltip: "",
|
|
116
|
+
url: "www.google.com",
|
|
117
|
+
icon: "external link",
|
|
118
|
+
targetBlank: true,
|
|
119
|
+
type: "link",
|
|
120
|
+
includeVars: false,
|
|
121
|
+
keepTime: false,
|
|
122
|
+
}
|
|
113
123
|
]
|
|
114
124
|
});
|
|
115
125
|
var row = {
|
|
@@ -134,16 +144,19 @@ test('Dashboard can generate correct body', function t(assert) {
|
|
|
134
144
|
type: "link",
|
|
135
145
|
includeVars: false,
|
|
136
146
|
keepTime: false,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
title: "Google Homepage",
|
|
150
|
+
tooltip: "",
|
|
151
|
+
url: "www.google.com",
|
|
152
|
+
icon: "external link",
|
|
153
|
+
targetBlank: true,
|
|
154
|
+
type: "link",
|
|
155
|
+
includeVars: false,
|
|
156
|
+
keepTime: false,
|
|
137
157
|
}
|
|
138
158
|
]
|
|
139
159
|
}
|
|
140
160
|
assert.deepEqual(json, expectedJson);
|
|
141
161
|
assert.end();
|
|
142
162
|
});
|
|
143
|
-
|
|
144
|
-
test('Dashboard throws error if links are defined with wrong type', function t(assert) {
|
|
145
|
-
assert.throws(() => new Dashboard({
|
|
146
|
-
links: [{ title: "custom link", url: "www.wrong.com"}]
|
|
147
|
-
}), new TypeError('links must be defined using ExternalLink'))
|
|
148
|
-
assert.end();
|
|
149
|
-
});
|
package/test/external-link.js
CHANGED
|
@@ -38,10 +38,10 @@ test('external link with custom settings', function t(assert) {
|
|
|
38
38
|
title: "Uber Home Page",
|
|
39
39
|
tooltip: "click to view",
|
|
40
40
|
url: "www.uber.com",
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
})
|
|
42
|
+
.includeTimeFilter()
|
|
43
|
+
.includeVariableValues()
|
|
44
|
+
.withIcon("custom icon");
|
|
45
45
|
|
|
46
46
|
assert.deepEqual(externalLink.generate(), {
|
|
47
47
|
title: 'Uber Home Page',
|