Skip to content

Commit 0b2b5a4

Browse files
authored
Remove query parameter value from Custom entity (#132)
* Remove query parameter value from Custom entity * Update query generation for Custom entity * Fix linter issue
1 parent 110cbc8 commit 0b2b5a4

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/templates/custom.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Custom {
6969
}
7070

7171
const newOptions = [];
72-
const newQuery = [];
72+
const queryParts = [];
7373

7474
let hasAll = false;
7575
for (let i = 0; i < this.state.options.length; i++) {
@@ -90,7 +90,11 @@ class Custom {
9090
}
9191

9292
newOptions.push(opt);
93-
newQuery.push(opt.value);
93+
const valueWithEscapedCommas = String(opt.value).replace(
94+
/,/g,
95+
'\\,'
96+
);
97+
queryParts.push(`${opt.text} : ${valueWithEscapedCommas}`);
9498
}
9599

96100
if (this.defaultValue !== '') {
@@ -112,7 +116,7 @@ class Custom {
112116
}
113117

114118
this.state.options = newOptions;
115-
this.state.query = newQuery.join(',');
119+
this.state.query = queryParts.join(', ');
116120
}
117121

118122
generate() {

test/fixtures/override_dashboard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const overrideDashboard: GrafanaDashboard = {
5757
value: 'b',
5858
},
5959
],
60-
query: 'a,b',
60+
query: 'a : a, b : b',
6161
refresh: 0,
6262
refresh_on_load: false,
6363
type: 'custom',
@@ -94,7 +94,7 @@ const overrideDashboard: GrafanaDashboard = {
9494
value: '1min',
9595
},
9696
],
97-
query: '30min,10min,5min,2min,1min',
97+
query: '30min : 30min, 10min : 10min, 5min : 5min, 2min : 2min, 1min : 1min',
9898
refresh: 0,
9999
refresh_on_load: false,
100100
type: 'custom',

test/fixtures/templates/override_custom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const overrideCustomTemplate: GrafanaCustomTemplate = {
3939
includeAll: false,
4040
allValue: '',
4141
allFormat: 'glob',
42-
query: 'a,b',
42+
query: 'a : a, b : b',
4343
current: {
4444
text: 'a',
4545
value: 'a',

test/fixtures/templates/override_custom_text_value.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const overrideCustomTextValue: GrafanaCustomTemplate = {
3535
includeAll: false,
3636
allValue: '',
3737
allFormat: 'glob',
38-
query: 'myValue',
38+
query: 'myText : myValue',
3939
current: {
4040
text: 'myText',
4141
value: 'myValue',

0 commit comments

Comments
 (0)