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
d8595e9f
Commit
d8595e9f
authored
Mar 22, 2019
by
ryan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved migration hook to its own function
parent
a6c2a8c3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
14 deletions
+28
-14
packages/grafana-ui/src/types/panel.ts
+15
-2
public/app/features/dashboard/dashgrid/DashboardPanel.tsx
+3
-3
public/app/plugins/panel/singlestat2/module.tsx
+10
-9
No files found.
packages/grafana-ui/src/types/panel.ts
View file @
d8595e9f
...
...
@@ -22,12 +22,17 @@ export interface PanelEditorProps<T = any> {
}
/**
* Called when a panel is first loaded with existing options
*/
export
type
PanelMigrationHook
<
TOptions
=
any
>
=
(
options
:
Partial
<
TOptions
>
)
=>
Partial
<
TOptions
>
;
/**
* Called before a panel is initalized
*/
export
type
PanelTypeChangedHook
<
TOptions
=
any
>
=
(
options
:
Partial
<
TOptions
>
,
prevPluginId
?
:
string
,
prevOptions
?
:
any
prevPluginId
:
string
,
prevOptions
:
any
)
=>
Partial
<
TOptions
>
;
export
class
ReactPanelPlugin
<
TOptions
=
any
>
{
...
...
@@ -35,6 +40,7 @@ export class ReactPanelPlugin<TOptions = any> {
editor
?:
ComponentClass
<
PanelEditorProps
<
TOptions
>>
;
defaults
?:
TOptions
;
panelMigrationHook
?:
PanelMigrationHook
<
TOptions
>
;
panelTypeChangedHook
?:
PanelTypeChangedHook
<
TOptions
>
;
constructor
(
panel
:
ComponentClass
<
PanelProps
<
TOptions
>>
)
{
...
...
@@ -50,6 +56,13 @@ export class ReactPanelPlugin<TOptions = any> {
}
/**
* Called when the panel first loaded with
*/
setPanelMigrationHook
(
v
:
PanelMigrationHook
<
TOptions
>
)
{
this
.
panelMigrationHook
=
v
;
}
/**
* Called when the visualization changes.
* Lets you keep whatever settings made sense in the previous panel
*/
...
...
public/app/features/dashboard/dashgrid/DashboardPanel.tsx
View file @
d8595e9f
...
...
@@ -98,10 +98,10 @@ export class DashboardPanel extends PureComponent<Props, State> {
}
panel
.
changeType
(
pluginId
,
hook
);
}
}
else
if
(
plugin
.
exports
&&
plugin
.
exports
.
reactPanel
)
{
const
hook
=
plugin
.
exports
.
reactPanel
.
panel
TypeChanged
Hook
;
}
else
if
(
plugin
.
exports
&&
plugin
.
exports
.
reactPanel
&&
panel
.
options
)
{
const
hook
=
plugin
.
exports
.
reactPanel
.
panel
Migration
Hook
;
if
(
hook
)
{
panel
.
options
=
hook
(
panel
.
options
||
{},
null
,
null
);
panel
.
options
=
hook
(
panel
.
options
);
}
}
...
...
public/app/plugins/panel/singlestat2/module.tsx
View file @
d8595e9f
...
...
@@ -10,23 +10,23 @@ const optionsToKeep = ['valueOptions', 'stat', 'maxValue', 'maxValue', 'threshol
export
const
singleStatBaseOptionsCheck
=
(
options
:
Partial
<
SingleStatBaseOptions
>
,
prevPluginId
?
:
string
,
prevOptions
?
:
any
prevPluginId
:
string
,
prevOptions
:
any
)
=>
{
if
(
prevOptions
)
{
for
(
const
otk
of
optionsToKeep
)
{
if
(
prevOptions
.
hasOwnProperty
(
otk
))
{
options
[
otk
]
=
cloneDeep
(
prevOptions
[
otk
]);
}
optionsToKeep
.
forEach
(
v
=>
{
if
(
prevOptions
.
hasOwnProperty
(
v
))
{
options
[
v
]
=
cloneDeep
(
prevOptions
.
display
);
}
}
});
return
options
;
};
export
const
singleStatMigrationCheck
=
(
options
:
Partial
<
SingleStatBaseOptions
>
)
=>
{
// 6.1 renamed some stats, This makes sure they are up to date
// avg -> mean, current -> last, total -> sum
const
{
valueOptions
}
=
options
;
if
(
valueOptions
&&
valueOptions
.
stat
)
{
valueOptions
.
stat
=
getStatsCalculators
([
valueOptions
.
stat
]).
map
(
s
=>
s
.
id
)[
0
];
console
.
log
(
'CHANGED'
,
valueOptions
);
}
return
options
;
};
...
...
@@ -34,3 +34,4 @@ export const singleStatBaseOptionsCheck = (
reactPanel
.
setEditor
(
SingleStatEditor
);
reactPanel
.
setDefaults
(
defaults
);
reactPanel
.
setPanelTypeChangedHook
(
singleStatBaseOptionsCheck
);
reactPanel
.
setPanelMigrationHook
(
singleStatMigrationCheck
);
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