Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
0b1f5c5e
Unverified
Commit
0b1f5c5e
authored
Jan 29, 2021
by
Hugo Häggmark
Committed by
GitHub
Jan 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PanelLibrary: better handling of deleted panels (#30709)
parent
2028f89c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
7 deletions
+56
-7
devenv/dev-dashboards/panel-library/panel-library.json
+4
-2
pkg/services/librarypanels/database.go
+9
-2
pkg/services/librarypanels/librarypanels.go
+10
-1
pkg/services/librarypanels/librarypanels_test.go
+33
-2
No files found.
devenv/dev-dashboards/panel-library/panel-library.json
View file @
0b1f5c5e
...
@@ -142,7 +142,8 @@
...
@@ -142,7 +142,8 @@
},
},
"id"
:
3
,
"id"
:
3
,
"libraryPanel"
:
{
"libraryPanel"
:
{
"uid"
:
"MAnX2ifMk"
"uid"
:
"MAnX2ifMk"
,
"name"
:
"React Table"
}
}
},
},
{
{
...
@@ -154,7 +155,8 @@
...
@@ -154,7 +155,8 @@
},
},
"id"
:
2
,
"id"
:
2
,
"libraryPanel"
:
{
"libraryPanel"
:
{
"uid"
:
"g1sNpCaMz"
"uid"
:
"g1sNpCaMz"
,
"name"
:
"React Gauge"
}
}
}
}
],
],
...
...
pkg/services/librarypanels/database.go
View file @
0b1f5c5e
...
@@ -113,13 +113,20 @@ func (lps *LibraryPanelService) connectLibraryPanelsForDashboard(c *models.ReqCo
...
@@ -113,13 +113,20 @@ func (lps *LibraryPanelService) connectLibraryPanelsForDashboard(c *models.ReqCo
// deleteLibraryPanel deletes a Library Panel.
// deleteLibraryPanel deletes a Library Panel.
func
(
lps
*
LibraryPanelService
)
deleteLibraryPanel
(
c
*
models
.
ReqContext
,
uid
string
)
error
{
func
(
lps
*
LibraryPanelService
)
deleteLibraryPanel
(
c
*
models
.
ReqContext
,
uid
string
)
error
{
orgID
:=
c
.
SignedInUser
.
OrgId
return
lps
.
SQLStore
.
WithTransactionalDbSession
(
context
.
Background
(),
func
(
session
*
sqlstore
.
DBSession
)
error
{
return
lps
.
SQLStore
.
WithTransactionalDbSession
(
context
.
Background
(),
func
(
session
*
sqlstore
.
DBSession
)
error
{
result
,
err
:=
session
.
Exec
(
"DELETE FROM library_panel WHERE uid=? and org_id=?"
,
uid
,
orgID
)
panel
,
err
:=
getLibraryPanel
(
session
,
uid
,
c
.
SignedInUser
.
OrgId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
_
,
err
:=
session
.
Exec
(
"DELETE FROM library_panel_dashboard WHERE librarypanel_id=?"
,
panel
.
ID
);
err
!=
nil
{
return
err
}
result
,
err
:=
session
.
Exec
(
"DELETE FROM library_panel WHERE id=?"
,
panel
.
ID
)
if
err
!=
nil
{
return
err
}
if
rowsAffected
,
err
:=
result
.
RowsAffected
();
err
!=
nil
{
if
rowsAffected
,
err
:=
result
.
RowsAffected
();
err
!=
nil
{
return
err
return
err
}
else
if
rowsAffected
!=
1
{
}
else
if
rowsAffected
!=
1
{
...
...
pkg/services/librarypanels/librarypanels.go
View file @
0b1f5c5e
...
@@ -71,7 +71,16 @@ func (lps *LibraryPanelService) LoadLibraryPanelsForDashboard(dash *models.Dashb
...
@@ -71,7 +71,16 @@ func (lps *LibraryPanelService) LoadLibraryPanelsForDashboard(dash *models.Dashb
libraryPanelInDB
,
ok
:=
libraryPanels
[
uid
]
libraryPanelInDB
,
ok
:=
libraryPanels
[
uid
]
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"found connection to library panel %q that isn't in database"
,
uid
)
name
:=
libraryPanel
.
Get
(
"name"
)
.
MustString
()
elem
:=
dash
.
Data
.
Get
(
"panels"
)
.
GetIndex
(
i
)
elem
.
Set
(
"gridPos"
,
panelAsJSON
.
Get
(
"gridPos"
)
.
MustMap
())
elem
.
Set
(
"id"
,
panelAsJSON
.
Get
(
"id"
)
.
MustInt64
())
elem
.
Set
(
"type"
,
fmt
.
Sprintf
(
"Name:
\"
%s
\"
, UID:
\"
%s
\"
"
,
name
,
uid
))
elem
.
Set
(
"libraryPanel"
,
map
[
string
]
interface
{}{
"uid"
:
uid
,
"name"
:
name
,
})
continue
}
}
// we have a match between what is stored in db and in dashboard json
// we have a match between what is stored in db and in dashboard json
...
...
pkg/services/librarypanels/librarypanels_test.go
View file @
0b1f5c5e
...
@@ -650,7 +650,7 @@ func TestLoadLibraryPanelsForDashboard(t *testing.T) {
...
@@ -650,7 +650,7 @@ func TestLoadLibraryPanelsForDashboard(t *testing.T) {
require
.
EqualError
(
t
,
err
,
errLibraryPanelHeaderUIDMissing
.
Error
())
require
.
EqualError
(
t
,
err
,
errLibraryPanelHeaderUIDMissing
.
Error
())
})
})
testScenario
(
t
,
"When an admin tries to load a dashboard with a library panel that is not connected, it should
fail
"
,
testScenario
(
t
,
"When an admin tries to load a dashboard with a library panel that is not connected, it should
set correct JSON and continue
"
,
func
(
t
*
testing
.
T
,
sc
scenarioContext
)
{
func
(
t
*
testing
.
T
,
sc
scenarioContext
)
{
command
:=
getCreateCommand
(
1
,
"Text - Library Panel1"
)
command
:=
getCreateCommand
(
1
,
"Text - Library Panel1"
)
response
:=
sc
.
service
.
createHandler
(
sc
.
reqContext
,
command
)
response
:=
sc
.
service
.
createHandler
(
sc
.
reqContext
,
command
)
...
@@ -692,7 +692,38 @@ func TestLoadLibraryPanelsForDashboard(t *testing.T) {
...
@@ -692,7 +692,38 @@ func TestLoadLibraryPanelsForDashboard(t *testing.T) {
}
}
err
=
sc
.
service
.
LoadLibraryPanelsForDashboard
(
&
dash
)
err
=
sc
.
service
.
LoadLibraryPanelsForDashboard
(
&
dash
)
require
.
EqualError
(
t
,
err
,
fmt
.
Errorf
(
"found connection to library panel %q that isn't in database"
,
existing
.
Result
.
UID
)
.
Error
())
require
.
NoError
(
t
,
err
)
expectedJSON
:=
map
[
string
]
interface
{}{
"panels"
:
[]
interface
{}{
map
[
string
]
interface
{}{
"id"
:
int64
(
1
),
"gridPos"
:
map
[
string
]
interface
{}{
"h"
:
6
,
"w"
:
6
,
"x"
:
0
,
"y"
:
0
,
},
},
map
[
string
]
interface
{}{
"id"
:
int64
(
2
),
"gridPos"
:
map
[
string
]
interface
{}{
"h"
:
6
,
"w"
:
6
,
"x"
:
6
,
"y"
:
0
,
},
"libraryPanel"
:
map
[
string
]
interface
{}{
"uid"
:
existing
.
Result
.
UID
,
"name"
:
existing
.
Result
.
Name
,
},
"type"
:
fmt
.
Sprintf
(
"Name:
\"
%s
\"
, UID:
\"
%s
\"
"
,
existing
.
Result
.
Name
,
existing
.
Result
.
UID
),
},
},
}
expected
:=
simplejson
.
NewFromAny
(
expectedJSON
)
if
diff
:=
cmp
.
Diff
(
expected
.
Interface
(),
dash
.
Data
.
Interface
(),
getCompareOptions
()
...
);
diff
!=
""
{
t
.
Fatalf
(
"Result mismatch (-want +got):
\n
%s"
,
diff
)
}
})
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment