Skip to content

Commit

Permalink
Merge pull request #215 from K-Phoen/converter-textbox-variables
Browse files Browse the repository at this point in the history
Converter textbox variables
  • Loading branch information
K-Phoen authored Mar 21, 2023
2 parents 3d6a24f + c6ad082 commit d1f4e8a
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/K-Phoen/dark
go 1.19

require (
github.com/K-Phoen/grabana v0.21.15
github.com/K-Phoen/grabana v0.21.16
github.com/K-Phoen/sdk v0.12.0
github.com/go-logr/logr v1.2.3
github.com/onsi/ginkgo v1.16.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/K-Phoen/grabana v0.21.15 h1:rUyJm9pV2XiPWQNVDjR+ubEBP+A8zv0hpRQmZjFcBnM=
github.com/K-Phoen/grabana v0.21.15/go.mod h1:HDl99djdna5Auu7RcOgxE64HnvQ9UBIpqc+A2A5XnL8=
github.com/K-Phoen/grabana v0.21.16 h1:IxZKPqrQyt3Yq00p/YMhexCtPAxJJpAEfMQorRVG7+0=
github.com/K-Phoen/grabana v0.21.16/go.mod h1:HDl99djdna5Auu7RcOgxE64HnvQ9UBIpqc+A2A5XnL8=
github.com/K-Phoen/sdk v0.12.0 h1:+0QqHoDZbO6zetFMggM3zKF48GKRu744Ycc9w4oyY0E=
github.com/K-Phoen/sdk v0.12.0/go.mod h1:wp7qXARaIhCYktmoOjRZ+TDMlek5nbayC+waN7vigxI=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down
12 changes: 12 additions & 0 deletions internal/pkg/converter/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func (converter *JSON) convertVariable(variable sdk.TemplateVar, dashboard *grab
converter.convertConstVar(variable, dashboard)
case "datasource":
converter.convertDatasourceVar(variable, dashboard)
case "textbox":
converter.convertTextVar(variable, dashboard)
default:
converter.logger.Warn("unhandled variable type found: skipped", zap.String("type", variable.Type), zap.String("name", variable.Name))
}
Expand Down Expand Up @@ -66,6 +68,16 @@ func (converter *JSON) convertCustomVar(variable sdk.TemplateVar, dashboard *gra
dashboard.Variables = append(dashboard.Variables, grabana.DashboardVariable{Custom: custom})
}

func (converter *JSON) convertTextVar(variable sdk.TemplateVar, dashboard *grabana.DashboardModel) {
textVar := &grabana.VariableText{
Name: variable.Name,
Label: variable.Label,
Hide: converter.convertVarHide(variable),
}

dashboard.Variables = append(dashboard.Variables, grabana.DashboardVariable{Text: textVar})
}

func (converter *JSON) convertQueryVar(variable sdk.TemplateVar, dashboard *grabana.DashboardModel) {
datasource := ""
if variable.Datasource != nil {
Expand Down
23 changes: 23 additions & 0 deletions internal/pkg/converter/variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,26 @@ func TestConvertQueryVar(t *testing.T) {
req.True(query.IncludeAll)
req.True(query.DefaultAll)
}

func TestConvertTextboxVar(t *testing.T) {
req := require.New(t)

variable := defaultVar("textbox")
variable.Name = "var_textbox"
variable.Label = "Filter"
variable.Hide = 1

converter := NewJSON(zap.NewNop())

dashboard := &grabana.DashboardModel{}
converter.convertVariables([]sdk.TemplateVar{variable}, dashboard)

req.Len(dashboard.Variables, 1)
req.NotNil(dashboard.Variables[0].Text)

textVar := dashboard.Variables[0].Text

req.Equal("var_textbox", textVar.Name)
req.Equal("Filter", textVar.Label)
req.Equal("label", textVar.Hide)
}
14 changes: 13 additions & 1 deletion vendor/github.com/K-Phoen/grabana/dashboard/dashboard.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 44 additions & 11 deletions vendor/github.com/K-Phoen/grabana/decoder/variables.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions vendor/github.com/K-Phoen/grabana/variable/text/text.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/K-Phoen/grabana v0.21.15
# github.com/K-Phoen/grabana v0.21.16
## explicit; go 1.19
github.com/K-Phoen/grabana
github.com/K-Phoen/grabana/alert
Expand Down Expand Up @@ -49,6 +49,7 @@ github.com/K-Phoen/grabana/variable/custom
github.com/K-Phoen/grabana/variable/datasource
github.com/K-Phoen/grabana/variable/interval
github.com/K-Phoen/grabana/variable/query
github.com/K-Phoen/grabana/variable/text
# github.com/K-Phoen/sdk v0.12.0
## explicit; go 1.16
github.com/K-Phoen/sdk
Expand Down

0 comments on commit d1f4e8a

Please sign in to comment.