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
593cc538
Commit
593cc538
authored
Aug 31, 2018
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: redux refactor
parent
d68007fd
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
111 additions
and
28 deletions
+111
-28
public/app/features/alerting/apis/index.ts
+52
-0
public/app/features/alerting/containers/AlertRuleList.test.tsx
+0
-0
public/app/features/alerting/containers/AlertRuleList.tsx
+57
-26
public/app/features/alerting/containers/__snapshots__/AlertRuleList.test.tsx.snap
+0
-0
public/app/features/serverStats/ServerStats.test.tsx
+0
-0
public/app/features/serverStats/ServerStats.tsx
+0
-0
public/app/features/serverStats/__snapshots__/ServerStats.test.tsx.snap
+0
-0
public/app/features/serverStats/api.ts
+0
-0
public/app/routes/routes.ts
+2
-2
No files found.
public/app/features/alerting/apis/index.ts
0 → 100644
View file @
593cc538
import
{
getBackendSrv
}
from
'app/core/services/backend_srv'
;
import
alertDef
from
'../alert_def'
;
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
function
setStateFields
(
rule
,
state
)
{
const
stateModel
=
alertDef
.
getStateDisplayModel
(
state
);
rule
.
state
=
state
;
rule
.
stateText
=
stateModel
.
text
;
rule
.
stateIcon
=
stateModel
.
iconClass
;
rule
.
stateClass
=
stateModel
.
stateClass
;
rule
.
stateAge
=
moment
(
rule
.
newStateDate
)
.
fromNow
()
.
replace
(
' ago'
,
''
);
}
export
const
getAlertRules
=
async
():
Promise
<
AlertRule
[]
>
=>
{
try
{
const
rules
=
await
getBackendSrv
().
get
(
'/api/alerts'
,
{});
for
(
const
rule
of
rules
)
{
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'
;
}
}
}
return
rules
;
}
catch
(
error
)
{
console
.
error
(
error
);
throw
error
;
}
};
public/app/
containers/AlertRuleList
/AlertRuleList.test.tsx
→
public/app/
features/alerting/containers
/AlertRuleList.test.tsx
View file @
593cc538
File moved
public/app/
containers/AlertRuleList
/AlertRuleList.tsx
→
public/app/
features/alerting/containers
/AlertRuleList.tsx
View file @
593cc538
import
React
from
'react'
;
import
React
,
{
PureComponent
}
from
'react'
;
import
{
hot
}
from
'react-hot-loader'
;
import
{
connect
}
from
'react-redux'
;
import
classNames
from
'classnames'
;
import
{
inject
,
observer
}
from
'mobx-react'
;
import
PageHeader
from
'app/core/components/PageHeader/PageHeader'
;
import
{
AlertRule
}
from
'app/stores/AlertListStore/AlertListStore'
;
import
appEvents
from
'app/core/app_events'
;
import
ContainerProps
from
'app/containers/ContainerProps'
;
import
Highlighter
from
'react-highlight-words'
;
import
{
initNav
}
from
'app/core/actions'
;
import
{
ContainerProps
}
from
'app/types'
;
import
{
getAlertRules
,
AlertRule
}
from
'../apis'
;
@
inject
(
'view'
,
'nav'
,
'alertList'
)
@
observer
export
class
AlertRuleList
extends
React
.
Component
<
ContainerProps
,
any
>
{
interface
Props
extends
ContainerProps
{}
interface
State
{
rules
:
AlertRule
[];
search
:
string
;
stateFilter
:
string
;
}
export
class
AlertRuleList
extends
PureComponent
<
Props
,
State
>
{
stateFilters
=
[
{
text
:
'All'
,
value
:
'all'
},
{
text
:
'OK'
,
value
:
'ok'
},
...
...
@@ -23,19 +30,35 @@ export class AlertRuleList extends React.Component<ContainerProps, any> {
constructor
(
props
)
{
super
(
props
);
this
.
props
.
nav
.
load
(
'alerting'
,
'alert-list'
);
this
.
state
=
{
rules
:
[],
search
:
''
,
stateFilter
:
''
,
};
this
.
props
.
initNav
(
'alerting'
,
'alert-list'
);
}
componentDidMount
()
{
this
.
fetchRules
();
}
onStateFilterChanged
=
evt
=>
{
this
.
props
.
view
.
updateQuery
({
state
:
evt
.
target
.
value
});
this
.
fetchRules
();
//
this.props.view.updateQuery({ state: evt.target.value });
//
this.fetchRules();
};
fetchRules
()
{
this
.
props
.
alertList
.
loadRules
({
state
:
this
.
props
.
view
.
query
.
get
(
'state'
)
||
'all'
,
});
async
fetchRules
()
{
try
{
const
rules
=
await
getAlertRules
();
this
.
setState
({
rules
});
}
catch
(
error
)
{
console
.
error
(
error
);
}
// this.props.alertList.loadRules({
// state: this.props.view.query.get('state') || 'all',
// });
}
onOpenHowTo
=
()
=>
{
...
...
@@ -47,15 +70,16 @@ export class AlertRuleList extends React.Component<ContainerProps, any> {
};
onSearchQueryChange
=
evt
=>
{
this
.
props
.
alertList
.
setSearchQuery
(
evt
.
target
.
value
);
//
this.props.alertList.setSearchQuery(evt.target.value);
};
render
()
{
const
{
nav
,
alertList
}
=
this
.
props
;
const
{
navModel
}
=
this
.
props
;
const
{
rules
,
search
,
stateFilter
}
=
this
.
state
;
return
(
<
div
>
<
PageHeader
model=
{
nav
as
any
}
/>
<
PageHeader
model=
{
nav
Model
}
/>
<
div
className=
"page-container page-body"
>
<
div
className=
"page-action-bar"
>
<
div
className=
"gf-form gf-form--grow"
>
...
...
@@ -64,7 +88,7 @@ export class AlertRuleList extends React.Component<ContainerProps, any> {
type=
"text"
className=
"gf-form-input"
placeholder=
"Search alerts"
value=
{
alertList
.
search
}
value=
{
search
}
onChange=
{
this
.
onSearchQueryChange
}
/>
<
i
className=
"gf-form-input-icon fa fa-search"
/>
...
...
@@ -74,7 +98,7 @@ export class AlertRuleList extends React.Component<ContainerProps, any> {
<
label
className=
"gf-form-label"
>
States
</
label
>
<
div
className=
"gf-form-select-wrapper width-13"
>
<
select
className=
"gf-form-input"
onChange=
{
this
.
onStateFilterChanged
}
value=
{
alertList
.
stateFilter
}
>
<
select
className=
"gf-form-input"
onChange=
{
this
.
onStateFilterChanged
}
value=
{
stateFilter
}
>
{
this
.
stateFilters
.
map
(
AlertStateFilterOption
)
}
</
select
>
</
div
>
...
...
@@ -89,8 +113,8 @@ export class AlertRuleList extends React.Component<ContainerProps, any> {
<
section
>
<
ol
className=
"alert-rule-list"
>
{
alertList
.
filteredR
ules
.
map
(
rule
=>
(
<
AlertRuleItem
rule=
{
rule
}
key=
{
rule
.
id
}
search=
{
alertList
.
search
}
/>
{
r
ules
.
map
(
rule
=>
(
<
AlertRuleItem
rule=
{
rule
}
key=
{
rule
.
id
}
search=
{
search
}
/>
))
}
</
ol
>
</
section
>
...
...
@@ -113,10 +137,9 @@ export interface AlertRuleItemProps {
search
:
string
;
}
@
observer
export
class
AlertRuleItem
extends
React
.
Component
<
AlertRuleItemProps
,
any
>
{
toggleState
=
()
=>
{
this
.
props
.
rule
.
togglePaused
();
//
this.props.rule.togglePaused();
};
renderText
(
text
:
string
)
{
...
...
@@ -134,8 +157,8 @@ export class AlertRuleItem extends React.Component<AlertRuleItemProps, any> {
const
stateClass
=
classNames
({
fa
:
true
,
'fa-play'
:
rule
.
isPaused
,
'fa-pause'
:
!
rule
.
isPaused
,
'fa-play'
:
rule
.
state
===
'paused'
,
'fa-pause'
:
rule
.
state
!==
'paused'
,
});
const
ruleUrl
=
`
${
rule
.
url
}
?panelId=
${
rule
.
panelId
}
&fullscreen=true&edit=true&tab=alert`
;
...
...
@@ -175,4 +198,12 @@ export class AlertRuleItem extends React.Component<AlertRuleItemProps, any> {
}
}
export
default
hot
(
module
)(
AlertRuleList
);
const
mapStateToProps
=
state
=>
({
navModel
:
state
.
navModel
,
});
const
mapDispatchToProps
=
{
initNav
,
};
export
default
hot
(
module
)(
connect
(
mapStateToProps
,
mapDispatchToProps
)(
AlertRuleList
));
public/app/
containers/AlertRuleList
/__snapshots__/AlertRuleList.test.tsx.snap
→
public/app/
features/alerting/containers
/__snapshots__/AlertRuleList.test.tsx.snap
View file @
593cc538
File moved
public/app/features/server
-s
tats/ServerStats.test.tsx
→
public/app/features/server
S
tats/ServerStats.test.tsx
View file @
593cc538
File moved
public/app/features/server
-s
tats/ServerStats.tsx
→
public/app/features/server
S
tats/ServerStats.tsx
View file @
593cc538
File moved
public/app/features/server
-s
tats/__snapshots__/ServerStats.test.tsx.snap
→
public/app/features/server
S
tats/__snapshots__/ServerStats.test.tsx.snap
View file @
593cc538
File moved
public/app/features/server
-s
tats/api.ts
→
public/app/features/server
S
tats/api.ts
View file @
593cc538
File moved
public/app/routes/routes.ts
View file @
593cc538
import
'./dashboard_loaders'
;
import
'./ReactContainer'
;
import
ServerStats
from
'app/features/server
-s
tats/ServerStats'
;
import
AlertRuleList
from
'app/
containers/AlertRuleList
/AlertRuleList'
;
import
ServerStats
from
'app/features/server
S
tats/ServerStats'
;
import
AlertRuleList
from
'app/
features/alerting/containers
/AlertRuleList'
;
import
FolderSettings
from
'app/containers/ManageDashboards/FolderSettings'
;
import
FolderPermissions
from
'app/containers/ManageDashboards/FolderPermissions'
;
import
TeamPages
from
'app/containers/Teams/TeamPages'
;
...
...
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