Some variables in grafana can be custom, so you have a query which is like:
select * from item_line where ven_category in (${VEN})
Where VEN
is a variable with the options defined as V,E,N
. Then when viewing a dashboard, there is a drop down to select which character. This character then transforms the query to be:
select * from item_line where ven_category in ('V')
There can be multi-select or non-multi select custom variables.
The Variable
definition object you get from grafana looks roughly like:
{
query: 'V,E,N'
options: [{selected: true, text: "V", value: "V"}, .. {selected: false, text: "N", value: "N"}]
name: "VEN"
label: "VEN"
multi: true
includeAll: false // this will give an "ALL" option - setting "V", "E", "N" to true.
}
Grafana takes this definition and creates a drop down which then also enables transforms on the query, according to the format provided. I.e.: ${VEN:sqlstring} transforms it to be "V", "E", "N"
where as ${VEN} will transform it to be: V,E,N
Solution:
For each panel, iterate through the variables for the panels dashboard, and determine if the variable is used within the sql. If it is, generate and display the drop down to choose the variable to use. Save this in the msupply sqlite and use it for generating reports.
Saving: Saving it as a JSON stringified object ๐ข in ReportContent
(A 'panel' record) - because each panel can have multiple variables, and multiple values for each variable:
{
VEN: ["V", "E"]
status: ["fn"]
}
Even if they're not multi-selectable, store in an array.
Limitations:
- There are other variable types other than
custom
. Also other formatting types. JUST going to implement custom
, sqlstring
formatted.
- The reporter won't be able to keep in sync well enough - i.e. if you set up variables for a panel, then go edit those variables.. ๐คท But this is pretty same same, i.e. if you set up panels and then go delete panels.. ๐คท