Skip to content

Commit 63c6c7e

Browse files
Add FolderID to SetDashboard api request (#67)
* Add FolderID to SetDashboard api request Signed-off-by: Masudur Rahman <[email protected]> * Update dashboard api Signed-off-by: Masudur Rahman <[email protected]> * Update rest-dashboard.go Signed-off-by: Masudur Rahman <[email protected]>
1 parent b82924c commit 63c6c7e

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

cmd/import-dashboards/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ func main() {
6666
continue
6767
}
6868
c.DeleteDashboard(board.UpdateSlug())
69-
_, err := c.SetDashboard(board, false)
69+
params := sdk.SetDashboardParams{
70+
FolderID: sdk.DefaultFolderId,
71+
Overwrite: false,
72+
}
73+
_, err := c.SetDashboard(board, params)
7074
if err != nil {
7175
log.Printf("error on importing dashboard %s", board.Title)
7276
continue

rest-dashboard.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ import (
3030
"github.com/pkg/errors"
3131
)
3232

33+
// DefaultFolderId is the id of the general folder
34+
// that is pre-created and cannot be removed.
35+
const DefaultFolderId = 0
36+
3337
// BoardProperties keeps metadata of a dashboard.
3438
type BoardProperties struct {
3539
IsStarred bool `json:"isStarred,omitempty"`
@@ -193,6 +197,13 @@ func (r *Client) SearchDashboards(query string, starred bool, tags ...string) ([
193197
return boards, err
194198
}
195199

200+
// SetDashboardParams contains the extra parameteres
201+
// that affects where and how the dashboard will be stored
202+
type SetDashboardParams struct {
203+
FolderID int
204+
Overwrite bool
205+
}
206+
196207
// SetDashboard updates existing dashboard or creates a new one.
197208
// Set dasboard ID to nil to create a new dashboard.
198209
// Set overwrite to true if you want to overwrite existing dashboard with
@@ -201,11 +212,12 @@ func (r *Client) SearchDashboards(query string, starred bool, tags ...string) ([
201212
// may be only loaded with HTTP API but not created or updated.
202213
//
203214
// Reflects POST /api/dashboards/db API call.
204-
func (r *Client) SetDashboard(board Board, overwrite bool) (StatusMessage, error) {
215+
func (r *Client) SetDashboard(board Board, params SetDashboardParams) (StatusMessage, error) {
205216
var (
206217
isBoardFromDB bool
207218
newBoard struct {
208219
Dashboard Board `json:"dashboard"`
220+
FolderID int `json:"folderId"`
209221
Overwrite bool `json:"overwrite"`
210222
}
211223
raw []byte
@@ -217,8 +229,9 @@ func (r *Client) SetDashboard(board Board, overwrite bool) (StatusMessage, error
217229
return StatusMessage{}, errors.New("only database dashboard (with 'db/' prefix in a slug) can be set")
218230
}
219231
newBoard.Dashboard = board
220-
newBoard.Overwrite = overwrite
221-
if !overwrite {
232+
newBoard.FolderID = params.FolderID
233+
newBoard.Overwrite = params.Overwrite
234+
if !params.Overwrite {
222235
newBoard.Dashboard.ID = 0
223236
}
224237
if raw, err = json.Marshal(newBoard); err != nil {

rest-dashboard_integration_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ func Test_Dashboard_CRUD(t *testing.T) {
2626
}
2727

2828
client.DeleteDashboard(board.UpdateSlug())
29-
if _, err = client.SetDashboard(board, false); err != nil {
29+
params := sdk.SetDashboardParams{
30+
FolderID: sdk.DefaultFolderId,
31+
Overwrite: false,
32+
}
33+
if _, err = client.SetDashboard(board, params); err != nil {
3034
t.Fatal(err)
3135
}
3236

0 commit comments

Comments
 (0)