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
e2fe663d
Commit
e2fe663d
authored
Jan 09, 2019
by
Hugo Häggmark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TestRuleButton
parent
a9808ef5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
5 deletions
+72
-5
public/app/features/alerting/AlertTab.tsx
+24
-5
public/app/features/alerting/TestRuleButton.tsx
+48
-0
No files found.
public/app/features/alerting/AlertTab.tsx
View file @
e2fe663d
// Libraries
import
React
,
{
PureComponent
}
from
'react'
;
import
React
,
{
PureComponent
,
SFC
}
from
'react'
;
// Services & Utils
import
{
AngularComponent
,
getAngularLoader
}
from
'app/core/services/AngularLoader'
;
...
...
@@ -14,6 +14,7 @@ import 'app/features/alerting/AlertTabCtrl';
// Types
import
{
DashboardModel
}
from
'../dashboard/dashboard_model'
;
import
{
PanelModel
}
from
'../dashboard/panel_model'
;
import
{
TestRuleButton
}
from
'./TestRuleButton'
;
interface
Props
{
angularPanel
?:
AngularComponent
;
...
...
@@ -21,6 +22,16 @@ interface Props {
panel
:
PanelModel
;
}
interface
LoadingPlaceholderProps
{
text
:
string
;
}
const
LoadingPlaceholder
:
SFC
<
LoadingPlaceholderProps
>
=
({
text
})
=>
(
<
div
className=
"gf-form-group"
>
{
text
}
<
i
className=
"fa fa-spinner fa-spin"
/>
</
div
>
);
export
class
AlertTab
extends
PureComponent
<
Props
>
{
element
:
any
;
component
:
AngularComponent
;
...
...
@@ -65,9 +76,7 @@ export class AlertTab extends PureComponent<Props> {
const
loader
=
getAngularLoader
();
const
template
=
'<alert-tab />'
;
const
scopeProps
=
{
ctrl
:
this
.
panelCtrl
,
};
const
scopeProps
=
{
ctrl
:
this
.
panelCtrl
};
this
.
component
=
loader
.
load
(
this
.
element
,
scopeProps
,
template
);
}
...
...
@@ -111,6 +120,16 @@ export class AlertTab extends PureComponent<Props> {
};
};
renderTestRuleButton
=
()
=>
{
const
{
panel
,
dashboard
}
=
this
.
props
;
return
<
TestRuleButton
panelId=
{
panel
.
id
}
dashboard=
{
dashboard
}
LoadingPlaceholder=
{
LoadingPlaceholder
}
/>;
};
testRule
=
():
EditorToolbarView
=>
({
title
:
'Test Rule'
,
render
:
()
=>
this
.
renderTestRuleButton
(),
});
onAddAlert
=
()
=>
{
this
.
panelCtrl
.
_enableAlert
();
this
.
component
.
digest
();
...
...
@@ -120,7 +139,7 @@ export class AlertTab extends PureComponent<Props> {
render
()
{
const
{
alert
}
=
this
.
props
.
panel
;
const
toolbarItems
=
alert
?
[
this
.
stateHistory
(),
this
.
deleteAlert
()]
:
[];
const
toolbarItems
=
alert
?
[
this
.
stateHistory
(),
this
.
testRule
(),
this
.
deleteAlert
()]
:
[];
const
model
=
{
title
:
'Panel has no alert rule defined'
,
...
...
public/app/features/alerting/TestRuleButton.tsx
0 → 100644
View file @
e2fe663d
import
React
,
{
PureComponent
}
from
'react'
;
import
{
JSONFormatter
}
from
'app/core/components/JSONFormatter/JSONFormatter'
;
import
{
getBackendSrv
}
from
'app/core/services/backend_srv'
;
import
{
DashboardModel
}
from
'../dashboard/dashboard_model'
;
export
interface
Props
{
panelId
:
number
;
dashboard
:
DashboardModel
;
LoadingPlaceholder
:
any
;
}
interface
State
{
isLoading
:
boolean
;
testRuleResponse
:
{};
}
export
class
TestRuleButton
extends
PureComponent
<
Props
,
State
>
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
isLoading
:
false
,
testRuleResponse
:
{}
};
}
componentDidMount
()
{
this
.
testRule
();
}
async
testRule
()
{
const
{
panelId
,
dashboard
}
=
this
.
props
;
const
payload
=
{
dashboard
:
dashboard
.
getSaveModelClone
(),
panelId
};
const
testRuleResponse
=
await
getBackendSrv
().
post
(
`/api/alerts/test`
,
payload
);
this
.
setState
(
prevState
=>
({
...
prevState
,
isLoading
:
false
,
testRuleResponse
}));
}
render
()
{
const
{
testRuleResponse
,
isLoading
}
=
this
.
state
;
const
{
LoadingPlaceholder
}
=
this
.
props
;
if
(
isLoading
===
true
)
{
return
<
LoadingPlaceholder
text=
"Evaluating rule"
/>;
}
return
(
<>
<
JSONFormatter
json=
{
testRuleResponse
}
/>
</>
);
}
}
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