Skip to content

Commit be6fa2d

Browse files
feature: id col is used for variable if present
1 parent df50c09 commit be6fa2d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ To use them, simply enter the value in the input string. Below is an example of
6666
### Query Variables
6767

6868
You can use the Haystack connector to source new variables. Create a query and then enter the name of the column that
69-
contains the variable values. If no column is specified, the first one is used.
69+
contains the variable values. If no column is specified, `id` is used if present. Otherwise, the first column is used.
7070

7171
The value injected by the variable exactly matches the displayed value, with the exception of Ref types. Instead, Ref
7272
types display the "display" portion and inject only the "ID" portion (i.e. `@abc "Site A"` will be displayed as `Site A`

src/datasource.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ export class DataSource extends DataSourceWithBackend<HaystackQuery, HaystackDat
9999
}
100100

101101
return response.data.reduce((acc: MetricFindValue[], frame: DataFrame) => {
102+
// Default to the first field
102103
let field = frame.fields[0];
103104
if (variableQuery.column !== undefined && variableQuery.column !== '') {
104105
// If a column was input, match the column name
105106
field = frame.fields.find((field: Field) => field.name === variableQuery.column) ?? field;
107+
} else if (frame.fields.some((field: Field) => field.name === 'id')) {
108+
// If there is an id column, use that
109+
field = frame.fields.find((field: Field) => field.name === 'id') ?? field;
106110
}
107111

108112
let fieldVals = field.values.map((value) => {

0 commit comments

Comments
 (0)