Skip to content

Commit fbc2038

Browse files
feature: id var display uses dis
1 parent 721a1d8 commit fbc2038

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/datasource.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Field,
88
MetricFindValue,
99
getDefaultTimeRange,
10+
FieldType,
1011
} from '@grafana/data';
1112
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
1213

@@ -113,14 +114,20 @@ export class DataSource extends DataSourceWithBackend<HaystackQuery, HaystackDat
113114
}
114115

115116
let fieldVals = field.values.map((value) => {
116-
if (value.startsWith('@')) {
117-
// Detect ref using @ prefix, and adjust value to just the Ref
118-
let spaceIndex = value.indexOf(' ');
119-
let id = value.substring(0, spaceIndex);
120-
return { text: value, value: id };
121-
} else {
122-
// Otherwise, just use the value directly
123-
return { text: value, value: value };
117+
switch (field.type) {
118+
case FieldType.string:
119+
if (value.startsWith('@')) {
120+
// Detect ref using @ prefix, and adjust value to just the Ref
121+
let spaceIndex = value.indexOf(' ');
122+
let id = value.substring(0, spaceIndex);
123+
let dis = value.substring(spaceIndex + 2, value.length - 1);
124+
return { text: dis, value: id };
125+
} else {
126+
// Otherwise, just use the value directly
127+
return { text: value, value: value };
128+
}
129+
default:
130+
return { text: value, value: value };
124131
}
125132
});
126133
return acc.concat(fieldVals);

0 commit comments

Comments
 (0)