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
f21fe65b
Commit
f21fe65b
authored
Nov 16, 2018
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed issues when changing type, need to remove event listeners and cleanup props
parent
dac02d3d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
4 deletions
+56
-4
public/app/core/constants.ts
+1
-0
public/app/features/dashboard/dashgrid/DashboardPanel.tsx
+1
-1
public/app/features/dashboard/panel_model.ts
+54
-3
No files found.
public/app/core/constants.ts
View file @
f21fe65b
...
...
@@ -14,3 +14,4 @@ export const DASHBOARD_TOP_PADDING = 20;
export
const
PANEL_HEADER_HEIGHT
=
27
;
export
const
PANEL_BORDER
=
2
;
export
const
PANEL_OPTIONS_KEY_PREFIX
=
'options-'
;
public/app/features/dashboard/dashgrid/DashboardPanel.tsx
View file @
f21fe65b
...
...
@@ -55,7 +55,7 @@ export class DashboardPanel extends PureComponent<Props, State> {
}
onPluginTypeChanged
=
(
plugin
:
PanelPlugin
)
=>
{
this
.
props
.
panel
.
changeType
(
plugin
.
id
);
this
.
props
.
panel
.
changeType
(
plugin
.
id
,
this
.
state
.
angularPanel
!==
null
);
this
.
loadPlugin
();
};
...
...
public/app/features/dashboard/panel_model.ts
View file @
f21fe65b
import
{
Emitter
}
from
'app/core/utils/emitter'
;
import
_
from
'lodash'
;
import
{
PANEL_OPTIONS_KEY_PREFIX
}
from
'app/core/constants'
;
export
interface
GridPos
{
x
:
number
;
...
...
@@ -16,6 +17,42 @@ const notPersistedProperties: { [str: string]: boolean } = {
hasRefreshed
:
true
,
};
// For angular panels we need to clean up properties when changing type
// To make sure the change happens without strange bugs happening when panels use same
// named property with different type / value expectations
// This is not required for react panels
const
mustKeepProps
:
{
[
str
:
string
]:
boolean
}
=
{
id
:
true
,
gridPos
:
true
,
type
:
true
,
title
:
true
,
scopedVars
:
true
,
repeat
:
true
,
repeatIteration
:
true
,
repeatPanelId
:
true
,
repeatDirection
:
true
,
repeatedByRow
:
true
,
minSpan
:
true
,
collapsed
:
true
,
panels
:
true
,
targets
:
true
,
datasource
:
true
,
timeFrom
:
true
,
timeShift
:
true
,
hideTimeOverride
:
true
,
maxDataPoints
:
true
,
interval
:
true
,
description
:
true
,
links
:
true
,
fullscreen
:
true
,
isEditing
:
true
,
hasRefreshed
:
true
,
events
:
true
,
cacheTimeout
:
true
,
nullPointMode
:
true
,
};
const
defaults
:
any
=
{
gridPos
:
{
x
:
0
,
y
:
0
,
h
:
3
,
w
:
6
},
datasource
:
null
,
...
...
@@ -82,7 +119,7 @@ export class PanelModel {
}
private
getOptionsKey
()
{
return
this
.
type
+
'Options'
;
return
'options-'
+
this
.
type
;
}
getSaveModel
()
{
...
...
@@ -146,11 +183,25 @@ export class PanelModel {
this
.
events
.
emit
(
'panel-initialized'
);
}
changeType
(
pluginId
:
string
)
{
changeType
(
pluginId
:
string
,
fromAngularPanel
:
boolean
)
{
this
.
type
=
pluginId
;
delete
this
.
thresholds
;
// for now we need to remove alert rules when changing type
delete
this
.
alert
;
// for angular panels only we need to remove all events and let angular panels do some cleanup
if
(
fromAngularPanel
)
{
this
.
destroy
();
for
(
const
key
of
_
.
keys
(
this
))
{
if
(
mustKeepProps
[
key
]
||
key
.
indexOf
(
PANEL_OPTIONS_KEY_PREFIX
)
===
0
)
{
continue
;
}
delete
this
[
key
];
console
.
log
(
'deleting '
,
key
);
}
}
}
destroy
()
{
...
...
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