Skip to content

Commit 0a69ce5

Browse files
authored
Export link struct and add some helper methods (#106)
* Export link struct and add some helper methods This commit exports the `link` struct in board.go, allowing users to interact with the `link` field in Dashboards properly. We also add some new helper methods to construct Links and add then to dashboards * Add test for AddLink method in Board's This commit adds a test for the method `AddLink` added in the previous commit, just calling it and making sure that the Link is added to the `Links` slice in the board
1 parent 68d50b8 commit 0a69ce5

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

board.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type (
6161
Refresh *BoolString `json:"refresh,omitempty"`
6262
SchemaVersion uint `json:"schemaVersion"`
6363
Version uint `json:"version"`
64-
Links []link `json:"links"`
64+
Links []Link `json:"links"`
6565
Time Time `json:"time"`
6666
Timepicker Timepicker `json:"timepicker"`
6767
GraphTooltip int `json:"graphTooltip,omitempty"`
@@ -124,25 +124,24 @@ type (
124124
Tags []string `json:"tags"`
125125
Type string `json:"type"`
126126
}
127+
// Link represents link to another dashboard or external weblink
128+
Link struct {
129+
Title string `json:"title"`
130+
Type string `json:"type"`
131+
AsDropdown *bool `json:"asDropdown,omitempty"`
132+
DashURI *string `json:"dashUri,omitempty"`
133+
Dashboard *string `json:"dashboard,omitempty"`
134+
Icon *string `json:"icon,omitempty"`
135+
IncludeVars bool `json:"includeVars"`
136+
KeepTime *bool `json:"keepTime,omitempty"`
137+
Params *string `json:"params,omitempty"`
138+
Tags []string `json:"tags,omitempty"`
139+
TargetBlank *bool `json:"targetBlank,omitempty"`
140+
Tooltip *string `json:"tooltip,omitempty"`
141+
URL *string `json:"url,omitempty"`
142+
}
127143
)
128144

129-
// link represents link to another dashboard or external weblink
130-
type link struct {
131-
Title string `json:"title"`
132-
Type string `json:"type"`
133-
AsDropdown *bool `json:"asDropdown,omitempty"`
134-
DashURI *string `json:"dashUri,omitempty"`
135-
Dashboard *string `json:"dashboard,omitempty"`
136-
Icon *string `json:"icon,omitempty"`
137-
IncludeVars bool `json:"includeVars"`
138-
KeepTime *bool `json:"keepTime,omitempty"`
139-
Params *string `json:"params,omitempty"`
140-
Tags []string `json:"tags,omitempty"`
141-
TargetBlank *bool `json:"targetBlank,omitempty"`
142-
Tooltip *string `json:"tooltip,omitempty"`
143-
URL *string `json:"url,omitempty"`
144-
}
145-
146145
// Height of rows maybe passed as number (ex 200) or
147146
// as string (ex "200px") or empty string
148147
type Height string
@@ -175,6 +174,10 @@ func NewBoard(title string) *Board {
175174
}
176175
}
177176

177+
func (b *Board) AddLink(link Link) {
178+
b.Links = append(b.Links, link)
179+
}
180+
178181
func (b *Board) RemoveTags(tags ...string) {
179182
// order might change after removing the tags
180183
for _, toRemoveTag := range tags {

board_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,16 @@ func TestBoardHasTag_TagNotExists(t *testing.T) {
9090
t.Error("tag not exists but found")
9191
}
9292
}
93+
94+
func TestBoardAddLink(t *testing.T) {
95+
b := sdk.NewBoard("Sample")
96+
b.AddLink(sdk.Link {
97+
Title: "test",
98+
Type: "external_link",
99+
IncludeVars: false,
100+
})
101+
102+
if len(b.Links) != 1 {
103+
t.Error("Link wasn't added")
104+
}
105+
}

panel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type (
7070
HideTimeOverride *bool `json:"hideTimeOverride,omitempty"`
7171
ID uint `json:"id"`
7272
IsNew bool `json:"isNew"`
73-
Links []link `json:"links,omitempty"` // general
73+
Links []Link `json:"links,omitempty"` // general
7474
MinSpan *float32 `json:"minSpan,omitempty"` // templating options
7575
OfType panelType `json:"-"` // it required for defining type of the panel
7676
Renderer *string `json:"renderer,omitempty"` // display styles

0 commit comments

Comments
 (0)