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
2a64d19f
Commit
2a64d19f
authored
Sep 02, 2018
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: load alert rules via redux
parent
7b068002
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
104 additions
and
52 deletions
+104
-52
public/app/core/reducers/index.ts
+1
-1
public/app/core/reducers/location.ts
+1
-3
public/app/core/selectors/navModel.ts
+1
-1
public/app/features/admin/containers/ServerStats.tsx
+2
-2
public/app/features/alerting/AlertRuleList.tsx
+13
-14
public/app/features/alerting/state/actions.ts
+26
-0
public/app/features/alerting/state/reducers.ts
+24
-30
public/app/stores/configureStore.ts
+3
-1
public/app/types/index.ts
+33
-0
No files found.
public/app/core/reducers/index.ts
View file @
2a64d19f
import
{
navIndexReducer
as
navIndex
}
from
'./navModel'
;
import
location
from
'./location'
;
import
{
locationReducer
as
location
}
from
'./location'
;
export
default
{
navIndex
,
...
...
public/app/core/reducers/location.ts
View file @
2a64d19f
...
...
@@ -16,7 +16,7 @@ function renderUrl(path: string, query: UrlQueryMap): string {
return
path
;
}
const
router
Reducer
=
(
state
=
initialState
,
action
:
Action
):
LocationState
=>
{
export
const
location
Reducer
=
(
state
=
initialState
,
action
:
Action
):
LocationState
=>
{
switch
(
action
.
type
)
{
case
'UPDATE_LOCATION'
:
{
const
{
path
,
query
,
routeParams
}
=
action
.
payload
;
...
...
@@ -31,5 +31,3 @@ const routerReducer = (state = initialState, action: Action): LocationState => {
return
state
;
};
export
default
routerReducer
;
public/app/core/selectors/navModel.ts
View file @
2a64d19f
...
...
@@ -15,7 +15,7 @@ function getNotFoundModel(): NavModel {
};
}
export
function
selectNavNode
(
navIndex
:
NavIndex
,
id
:
string
):
NavModel
{
export
function
getNavModel
(
navIndex
:
NavIndex
,
id
:
string
):
NavModel
{
if
(
navIndex
[
id
])
{
const
node
=
navIndex
[
id
];
const
main
=
{
...
...
public/app/features/admin/containers/ServerStats.tsx
View file @
2a64d19f
...
...
@@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
import
{
hot
}
from
'react-hot-loader'
;
import
{
connect
}
from
'react-redux'
;
import
{
NavModel
,
StoreState
}
from
'app/types'
;
import
{
selectNavNode
}
from
'app/core/selectors/navModel'
;
import
{
getNavModel
}
from
'app/core/selectors/navModel'
;
import
{
getServerStats
,
ServerStat
}
from
'../apis'
;
import
PageHeader
from
'app/core/components/PageHeader/PageHeader'
;
...
...
@@ -66,7 +66,7 @@ function StatItem(stat: ServerStat) {
}
const
mapStateToProps
=
(
state
:
StoreState
)
=>
({
navModel
:
selectNavNode
(
state
.
navIndex
,
'server-stats'
),
navModel
:
getNavModel
(
state
.
navIndex
,
'server-stats'
),
getServerStats
:
getServerStats
,
});
...
...
public/app/features/alerting/AlertRuleList.tsx
View file @
2a64d19f
...
...
@@ -6,13 +6,15 @@ import PageHeader from 'app/core/components/PageHeader/PageHeader';
import
appEvents
from
'app/core/app_events'
;
import
Highlighter
from
'react-highlight-words'
;
import
{
updateLocation
}
from
'app/core/actions'
;
import
{
selectNavNode
}
from
'app/core/selectors/navModel'
;
import
{
NavModel
,
StoreState
}
from
'app/types'
;
import
{
getAlertRules
,
AlertRule
}
from
'./state/api
s'
;
import
{
getNavModel
}
from
'app/core/selectors/navModel'
;
import
{
NavModel
,
StoreState
,
AlertRule
}
from
'app/types'
;
import
{
getAlertRules
Async
}
from
'./state/action
s'
;
interface
Props
{
navModel
:
NavModel
;
alertRules
:
AlertRule
[];
updateLocation
:
typeof
updateLocation
;
getAlertRulesAsync
:
typeof
getAlertRulesAsync
;
}
interface
State
{
...
...
@@ -49,16 +51,11 @@ export class AlertRuleList extends PureComponent<Props, State> {
this
.
props
.
updateLocation
({
query
:
{
state
:
evt
.
target
.
value
},
});
//
this.fetchRules();
this
.
fetchRules
();
};
async
fetchRules
()
{
try
{
const
rules
=
await
getAlertRules
();
this
.
setState
({
rules
});
}
catch
(
error
)
{
console
.
error
(
error
);
}
await
this
.
props
.
getAlertRulesAsync
();
// this.props.alertList.loadRules({
// state: this.props.view.query.get('state') || 'all',
...
...
@@ -78,8 +75,8 @@ export class AlertRuleList extends PureComponent<Props, State> {
};
render
()
{
const
{
navModel
}
=
this
.
props
;
const
{
rules
,
search
,
stateFilter
}
=
this
.
state
;
const
{
navModel
,
alertRules
}
=
this
.
props
;
const
{
search
,
stateFilter
}
=
this
.
state
;
return
(
<
div
>
...
...
@@ -117,7 +114,7 @@ export class AlertRuleList extends PureComponent<Props, State> {
<
section
>
<
ol
className=
"alert-rule-list"
>
{
r
ules
.
map
(
rule
=>
<
AlertRuleItem
rule=
{
rule
}
key=
{
rule
.
id
}
search=
{
search
}
/>)
}
{
alertR
ules
.
map
(
rule
=>
<
AlertRuleItem
rule=
{
rule
}
key=
{
rule
.
id
}
search=
{
search
}
/>)
}
</
ol
>
</
section
>
</
div
>
...
...
@@ -201,11 +198,13 @@ export class AlertRuleItem extends React.Component<AlertRuleItemProps, any> {
}
const
mapStateToProps
=
(
state
:
StoreState
)
=>
({
navModel
:
selectNavNode
(
state
.
navIndex
,
'alert-list'
),
navModel
:
getNavModel
(
state
.
navIndex
,
'alert-list'
),
alertRules
:
state
.
alertRules
,
});
const
mapDispatchToProps
=
{
updateLocation
,
getAlertRulesAsync
,
};
export
default
hot
(
module
)(
connect
(
mapStateToProps
,
mapDispatchToProps
)(
AlertRuleList
));
public/app/features/alerting/state/actions.ts
0 → 100644
View file @
2a64d19f
import
{
Dispatch
}
from
'redux'
;
import
{
getBackendSrv
}
from
'app/core/services/backend_srv'
;
import
{
AlertRule
}
from
'app/types'
;
export
interface
LoadAlertRulesAction
{
type
:
'LOAD_ALERT_RULES'
;
payload
:
AlertRule
[];
}
export
const
loadAlertRules
=
(
rules
:
AlertRule
[]):
LoadAlertRulesAction
=>
({
type
:
'LOAD_ALERT_RULES'
,
payload
:
rules
,
});
export
type
Action
=
LoadAlertRulesAction
;
export
const
getAlertRulesAsync
=
()
=>
async
(
dispatch
:
Dispatch
<
Action
>
):
Promise
<
AlertRule
[]
>
=>
{
try
{
const
rules
=
await
getBackendSrv
().
get
(
'/api/alerts'
,
{});
dispatch
(
loadAlertRules
(
rules
));
return
rules
;
}
catch
(
error
)
{
console
.
error
(
error
);
throw
error
;
}
};
public/app/features/alerting/state/
api
s.ts
→
public/app/features/alerting/state/
reducer
s.ts
View file @
2a64d19f
import
{
getBackendSrv
}
from
'app/core/services/backend_srv'
;
import
{
Action
}
from
'./actions'
;
import
{
AlertRule
}
from
'app/types'
;
import
alertDef
from
'./alertDef'
;
import
moment
from
'moment'
;
export
interface
AlertRule
{
id
:
number
;
dashboardId
:
number
;
panelId
:
number
;
name
:
string
;
state
:
string
;
stateText
:
string
;
stateIcon
:
string
;
stateClass
:
string
;
stateAge
:
string
;
info
?:
string
;
url
:
string
;
}
export
const
initialState
:
AlertRule
[]
=
[];
export
function
setStateFields
(
rule
,
state
)
{
const
stateModel
=
alertDef
.
getStateDisplayModel
(
state
);
...
...
@@ -27,26 +16,31 @@ export function setStateFields(rule, state) {
.
replace
(
' ago'
,
''
);
}
export
const
getAlertRules
=
async
():
Promise
<
AlertRule
[]
>
=>
{
try
{
const
rules
=
await
getBackendSrv
().
get
(
'/api/alerts'
,
{});
export
const
alertRulesReducer
=
(
state
=
initialState
,
action
:
Action
):
AlertRule
[]
=>
{
switch
(
action
.
type
)
{
case
'LOAD_ALERT_RULES'
:
{
const
alertRules
=
action
.
payload
;
for
(
const
rule
of
r
ules
)
{
setStateFields
(
rule
,
rule
.
state
);
for
(
const
rule
of
alertR
ules
)
{
setStateFields
(
rule
,
rule
.
state
);
if
(
rule
.
state
!==
'paused'
)
{
if
(
rule
.
executionError
)
{
rule
.
info
=
'Execution Error: '
+
rule
.
executionError
;
}
if
(
rule
.
evalData
&&
rule
.
evalData
.
noData
)
{
rule
.
info
=
'Query returned no data'
;
if
(
rule
.
state
!==
'paused'
)
{
if
(
rule
.
executionError
)
{
rule
.
info
=
'Execution Error: '
+
rule
.
executionError
;
}
if
(
rule
.
evalData
&&
rule
.
evalData
.
noData
)
{
rule
.
info
=
'Query returned no data'
;
}
}
}
}
return
rules
;
}
catch
(
error
)
{
console
.
error
(
error
);
throw
error
;
return
alertRules
;
}
}
return
state
;
};
export
default
{
alertRules
:
alertRulesReducer
,
};
public/app/stores/configureStore.ts
View file @
2a64d19f
...
...
@@ -2,9 +2,11 @@ import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import
thunk
from
'redux-thunk'
;
import
{
createLogger
}
from
'redux-logger'
;
import
sharedReducers
from
'app/core/reducers'
;
import
alertingReducers
from
'app/features/alerting/state/reducers'
;
const
rootReducer
=
combineReducers
({
...
sharedReducers
...
sharedReducers
,
...
alertingReducers
,
});
export
let
store
;
...
...
public/app/types/index.ts
View file @
2a64d19f
//
// Location
//
export
interface
LocationUpdate
{
path
?:
string
;
query
?:
UrlQueryMap
;
...
...
@@ -14,6 +18,30 @@ export interface LocationState {
export
type
UrlQueryValue
=
string
|
number
|
boolean
|
string
[]
|
number
[]
|
boolean
[];
export
type
UrlQueryMap
=
{
[
s
:
string
]:
UrlQueryValue
};
//
// Alerting
//
export
interface
AlertRule
{
id
:
number
;
dashboardId
:
number
;
panelId
:
number
;
name
:
string
;
state
:
string
;
stateText
:
string
;
stateIcon
:
string
;
stateClass
:
string
;
stateAge
:
string
;
info
?:
string
;
url
:
string
;
executionError
?:
string
;
evalData
?:
{
noData
:
boolean
};
}
//
// NavModel
//
export
interface
NavModelItem
{
text
:
string
;
url
:
string
;
...
...
@@ -37,7 +65,12 @@ export interface NavModel {
export
type
NavIndex
=
{
[
s
:
string
]:
NavModelItem
};
//
// Store
//
export
interface
StoreState
{
navIndex
:
NavIndex
;
location
:
LocationState
;
alertRules
:
AlertRule
[];
}
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