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
bb640938
Commit
bb640938
authored
Oct 23, 2018
by
Peter Holmberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
connected to store, self remove logic
parent
bbd02dd6
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
66 additions
and
49 deletions
+66
-49
public/app/core/components/AppNotifications/AppNotificationList.tsx
+25
-20
public/app/core/components/AppNotifications/state/actions.ts
+3
-3
public/app/core/components/AppNotifications/state/reducers.test.ts
+11
-5
public/app/core/components/AppNotifications/state/reducers.ts
+7
-7
public/app/core/utils/connectWithReduxStore.tsx
+11
-0
public/app/features/dashboard/permissions/DashboardPermissions.tsx
+1
-9
public/app/store/configureStore.ts
+2
-0
public/app/types/alerts.ts
+3
-2
public/app/types/index.ts
+3
-3
No files found.
public/app/core/components/AppNotifications/AppNotificationList.tsx
View file @
bb640938
import
React
,
{
PureComponent
}
from
'react'
;
import
{
connect
}
from
'react-redux'
;
import
appEvents
from
'app/core/app_events'
;
import
{
addAppNotification
,
clearAppNotification
}
from
'./state/actions'
;
import
{
connectWithStore
}
from
'app/core/utils/connectWithReduxStore'
;
import
{
AppNotification
,
StoreState
}
from
'../../../types'
;
export
interface
Props
{
a
lerts
:
any
[];
a
ppNotifications
:
AppNotification
[];
addAppNotification
:
typeof
addAppNotification
;
clearAppNotification
:
typeof
clearAppNotification
;
}
...
...
@@ -24,12 +25,14 @@ export class AppNotificationList extends PureComponent<Props> {
}
addAppNotification
(
title
,
text
,
severity
,
timeout
)
{
const
id
=
Date
.
now
();
const
newAlert
=
{
id
:
id
,
title
:
title
||
''
,
text
:
text
||
''
,
severity
:
severity
||
AppNotificationSeverity
.
Info
,
icon
:
this
.
getIconForSeverity
(
severity
),
remove
:
this
.
clearAutomatically
(
this
,
timeout
),
remove
:
this
.
clearAutomatically
(
id
,
timeout
),
};
this
.
props
.
addAppNotification
(
newAlert
);
...
...
@@ -46,32 +49,36 @@ export class AppNotificationList extends PureComponent<Props> {
}
}
clearAutomatically
=
(
alert
,
timeout
)
=>
{
clearAutomatically
=
(
id
,
timeout
)
=>
{
setTimeout
(()
=>
{
this
.
props
.
clearAppNotification
(
alert
);
this
.
props
.
clearAppNotification
(
id
);
},
timeout
);
};
onClearAppNotification
=
alert
=>
{
this
.
props
.
clearAppNotification
(
alert
);
onClearAppNotification
=
id
=>
{
this
.
props
.
clearAppNotification
(
id
);
};
render
()
{
const
{
a
lert
s
}
=
this
.
props
;
const
{
a
ppNotification
s
}
=
this
.
props
;
return
(
<
div
>
{
a
lerts
.
map
((
alert
,
index
)
=>
{
{
a
ppNotifications
.
map
((
appNotification
,
index
)
=>
{
return
(
<
div
key=
{
index
}
className=
{
`alert-${a
lert
.severity} alert`
}
>
<
div
key=
{
index
}
className=
{
`alert-${a
ppNotification
.severity} alert`
}
>
<
div
className=
"alert-icon"
>
<
i
className=
{
a
lert
.
icon
}
/>
<
i
className=
{
a
ppNotification
.
icon
}
/>
</
div
>
<
div
className=
"alert-body"
>
<
div
className=
"alert-title"
>
{
a
lert
.
title
}
</
div
>
<
div
className=
"alert-text"
>
{
a
lert
.
text
}
</
div
>
<
div
className=
"alert-title"
>
{
a
ppNotification
.
title
}
</
div
>
<
div
className=
"alert-text"
>
{
a
ppNotification
.
text
}
</
div
>
</
div
>
<
button
type=
"button"
className=
"alert-close"
onClick=
{
()
=>
this
.
onClearAppNotification
(
alert
)
}
>
<
button
type=
"button"
className=
"alert-close"
onClick=
{
()
=>
this
.
onClearAppNotification
(
appNotification
.
id
)
}
>
<
i
className=
"fa fa fa-remove"
/>
</
button
>
</
div
>
...
...
@@ -82,15 +89,13 @@ export class AppNotificationList extends PureComponent<Props> {
}
}
function
mapStateToProps
(
state
)
{
return
{
alerts
:
state
.
alerts
.
alerts
,
};
}
const
mapStateToProps
=
(
state
:
StoreState
)
=>
({
appNotifications
:
state
.
appNotifications
.
appNotifications
,
});
const
mapDispatchToProps
=
{
addAppNotification
,
clearAppNotification
,
};
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
AppNotificationList
);
export
default
connect
WithStore
(
AppNotificationList
,
mapStateToProps
,
mapDispatchToProps
);
public/app/core/components/AppNotifications/state/actions.ts
View file @
bb640938
...
...
@@ -12,14 +12,14 @@ interface AddAppNotificationAction {
interface
ClearAppNotificationAction
{
type
:
ActionTypes
.
ClearAppNotification
;
payload
:
AppNotification
;
payload
:
number
;
}
export
type
Action
=
AddAppNotificationAction
|
ClearAppNotificationAction
;
export
const
clearAppNotification
=
(
a
lert
:
AppNotification
)
=>
({
export
const
clearAppNotification
=
(
a
ppNotificationId
:
number
)
=>
({
type
:
ActionTypes
.
ClearAppNotification
,
payload
:
a
lert
,
payload
:
a
ppNotificationId
,
});
export
const
addAppNotification
=
(
alert
:
AppNotification
)
=>
({
...
...
public/app/core/components/AppNotifications/state/reducers.test.ts
View file @
bb640938
import
{
a
lert
sReducer
}
from
'./reducers'
;
import
{
a
ppNotification
sReducer
}
from
'./reducers'
;
import
{
ActionTypes
}
from
'./actions'
;
describe
(
'clear alert'
,
()
=>
{
it
(
'should filter alert'
,
()
=>
{
const
id1
=
1540301236048
;
const
id2
=
1540301248293
;
const
initialState
=
{
a
lert
s
:
[
a
ppNotification
s
:
[
{
id
:
id1
,
severity
:
'success'
,
icon
:
'success'
,
title
:
'test'
,
text
:
'test alert'
,
},
{
id
:
id2
,
severity
:
'fail'
,
icon
:
'warning'
,
title
:
'test2'
,
...
...
@@ -20,14 +25,15 @@ describe('clear alert', () => {
],
};
const
result
=
a
lert
sReducer
(
initialState
,
{
const
result
=
a
ppNotification
sReducer
(
initialState
,
{
type
:
ActionTypes
.
ClearAppNotification
,
payload
:
i
nitialState
.
alerts
[
1
]
,
payload
:
i
d2
,
});
const
expectedResult
=
{
a
lert
s
:
[
a
ppNotification
s
:
[
{
id
:
id1
,
severity
:
'success'
,
icon
:
'success'
,
title
:
'test'
,
...
...
public/app/core/components/AppNotifications/state/reducers.ts
View file @
bb640938
import
{
AppNotification
,
A
lert
sState
}
from
'app/types'
;
import
{
AppNotification
,
A
ppNotification
sState
}
from
'app/types'
;
import
{
Action
,
ActionTypes
}
from
'./actions'
;
export
const
initialState
:
A
lert
sState
=
{
a
lert
s
:
[]
as
AppNotification
[],
export
const
initialState
:
A
ppNotification
sState
=
{
a
ppNotification
s
:
[]
as
AppNotification
[],
};
export
const
a
lertsReducer
=
(
state
=
initialState
,
action
:
Action
):
Alert
sState
=>
{
export
const
a
ppNotificationsReducer
=
(
state
=
initialState
,
action
:
Action
):
AppNotification
sState
=>
{
switch
(
action
.
type
)
{
case
ActionTypes
.
AddAppNotification
:
return
{
...
state
,
a
lerts
:
state
.
alert
s
.
concat
([
action
.
payload
])
};
return
{
...
state
,
a
ppNotifications
:
state
.
appNotification
s
.
concat
([
action
.
payload
])
};
case
ActionTypes
.
ClearAppNotification
:
return
{
...
state
,
a
lerts
:
state
.
alerts
.
filter
(
alert
=>
alert
!==
action
.
payload
),
a
ppNotifications
:
state
.
appNotifications
.
filter
(
appNotification
=>
appNotification
.
id
!==
action
.
payload
),
};
}
return
state
;
};
export
default
{
a
lerts
:
alert
sReducer
,
a
ppNotifications
:
appNotification
sReducer
,
};
public/app/core/utils/connectWithReduxStore.tsx
0 → 100644
View file @
bb640938
import
React
from
'react'
;
import
{
connect
}
from
'react-redux'
;
import
{
store
}
from
'../../store/configureStore'
;
export
function
connectWithStore
(
WrappedComponent
,
...
args
)
{
const
ConnectedWrappedComponent
=
connect
(...
args
)(
WrappedComponent
);
return
props
=>
{
return
<
ConnectedWrappedComponent
{
...
props
}
store=
{
store
}
/>;
};
}
public/app/features/dashboard/permissions/DashboardPermissions.tsx
View file @
bb640938
import
React
,
{
PureComponent
}
from
'react'
;
import
{
connect
}
from
'react-redux'
;
import
Tooltip
from
'app/core/components/Tooltip/Tooltip'
;
import
SlideDown
from
'app/core/components/Animations/SlideDown'
;
import
{
StoreState
,
FolderInfo
}
from
'app/types'
;
...
...
@@ -13,7 +12,7 @@ import {
import
PermissionList
from
'app/core/components/PermissionList/PermissionList'
;
import
AddPermission
from
'app/core/components/PermissionList/AddPermission'
;
import
PermissionsInfo
from
'app/core/components/PermissionList/PermissionsInfo'
;
import
{
store
}
from
'app/store/configure
Store'
;
import
{
connectWithStore
}
from
'../../../core/utils/connectWithRedux
Store'
;
export
interface
Props
{
dashboardId
:
number
;
...
...
@@ -95,13 +94,6 @@ export class DashboardPermissions extends PureComponent<Props, State> {
}
}
function
connectWithStore
(
WrappedComponent
,
...
args
)
{
const
ConnectedWrappedComponent
=
connect
(...
args
)(
WrappedComponent
);
return
props
=>
{
return
<
ConnectedWrappedComponent
{
...
props
}
store=
{
store
}
/>;
};
}
const
mapStateToProps
=
(
state
:
StoreState
)
=>
({
permissions
:
state
.
dashboard
.
permissions
,
});
...
...
public/app/store/configureStore.ts
View file @
bb640938
...
...
@@ -10,6 +10,7 @@ import dashboardReducers from 'app/features/dashboard/state/reducers';
import
pluginReducers
from
'app/features/plugins/state/reducers'
;
import
dataSourcesReducers
from
'app/features/datasources/state/reducers'
;
import
usersReducers
from
'app/features/users/state/reducers'
;
import
appNotificationReducers
from
'app/core/components/AppNotifications/state/reducers'
;
const
rootReducers
=
{
...
sharedReducers
,
...
...
@@ -21,6 +22,7 @@ const rootReducers = {
...
pluginReducers
,
...
dataSourcesReducers
,
...
usersReducers
,
...
appNotificationReducers
,
};
export
let
store
;
...
...
public/app/types/alerts.ts
View file @
bb640938
export
interface
AppNotification
{
id
:
number
;
severity
:
string
;
icon
:
string
;
title
:
string
;
text
:
string
;
}
export
interface
A
lert
sState
{
a
lert
s
:
AppNotification
[];
export
interface
A
ppNotification
sState
{
a
ppNotification
s
:
AppNotification
[];
}
public/app/types/index.ts
View file @
bb640938
...
...
@@ -9,7 +9,7 @@ import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys';
import
{
Invitee
,
OrgUser
,
User
,
UsersState
}
from
'./user'
;
import
{
DataSource
,
DataSourcesState
}
from
'./datasources'
;
import
{
PluginDashboard
,
PluginMeta
,
Plugin
,
PluginsState
}
from
'./plugins'
;
import
{
AppNotification
,
A
lert
sState
}
from
'./alerts'
;
import
{
AppNotification
,
A
ppNotification
sState
}
from
'./alerts'
;
export
{
Team
,
...
...
@@ -48,7 +48,7 @@ export {
UsersState
,
PluginDashboard
,
AppNotification
,
A
lert
sState
,
A
ppNotification
sState
,
};
export
interface
StoreState
{
...
...
@@ -61,5 +61,5 @@ export interface StoreState {
dashboard
:
DashboardState
;
dataSources
:
DataSourcesState
;
users
:
UsersState
;
a
lerts
:
Alert
sState
;
a
ppNotifications
:
AppNotification
sState
;
}
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