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
React
,
{
PureComponent
}
from
'react'
;
import
{
connect
}
from
'react-redux'
;
import
appEvents
from
'app/core/app_events'
;
import
appEvents
from
'app/core/app_events'
;
import
{
addAppNotification
,
clearAppNotification
}
from
'./state/actions'
;
import
{
addAppNotification
,
clearAppNotification
}
from
'./state/actions'
;
import
{
connectWithStore
}
from
'app/core/utils/connectWithReduxStore'
;
import
{
AppNotification
,
StoreState
}
from
'../../../types'
;
export
interface
Props
{
export
interface
Props
{
a
lerts
:
any
[];
a
ppNotifications
:
AppNotification
[];
addAppNotification
:
typeof
addAppNotification
;
addAppNotification
:
typeof
addAppNotification
;
clearAppNotification
:
typeof
clearAppNotification
;
clearAppNotification
:
typeof
clearAppNotification
;
}
}
...
@@ -24,12 +25,14 @@ export class AppNotificationList extends PureComponent<Props> {
...
@@ -24,12 +25,14 @@ export class AppNotificationList extends PureComponent<Props> {
}
}
addAppNotification
(
title
,
text
,
severity
,
timeout
)
{
addAppNotification
(
title
,
text
,
severity
,
timeout
)
{
const
id
=
Date
.
now
();
const
newAlert
=
{
const
newAlert
=
{
id
:
id
,
title
:
title
||
''
,
title
:
title
||
''
,
text
:
text
||
''
,
text
:
text
||
''
,
severity
:
severity
||
AppNotificationSeverity
.
Info
,
severity
:
severity
||
AppNotificationSeverity
.
Info
,
icon
:
this
.
getIconForSeverity
(
severity
),
icon
:
this
.
getIconForSeverity
(
severity
),
remove
:
this
.
clearAutomatically
(
this
,
timeout
),
remove
:
this
.
clearAutomatically
(
id
,
timeout
),
};
};
this
.
props
.
addAppNotification
(
newAlert
);
this
.
props
.
addAppNotification
(
newAlert
);
...
@@ -46,32 +49,36 @@ export class AppNotificationList extends PureComponent<Props> {
...
@@ -46,32 +49,36 @@ export class AppNotificationList extends PureComponent<Props> {
}
}
}
}
clearAutomatically
=
(
alert
,
timeout
)
=>
{
clearAutomatically
=
(
id
,
timeout
)
=>
{
setTimeout
(()
=>
{
setTimeout
(()
=>
{
this
.
props
.
clearAppNotification
(
alert
);
this
.
props
.
clearAppNotification
(
id
);
},
timeout
);
},
timeout
);
};
};
onClearAppNotification
=
alert
=>
{
onClearAppNotification
=
id
=>
{
this
.
props
.
clearAppNotification
(
alert
);
this
.
props
.
clearAppNotification
(
id
);
};
};
render
()
{
render
()
{
const
{
a
lert
s
}
=
this
.
props
;
const
{
a
ppNotification
s
}
=
this
.
props
;
return
(
return
(
<
div
>
<
div
>
{
a
lerts
.
map
((
alert
,
index
)
=>
{
{
a
ppNotifications
.
map
((
appNotification
,
index
)
=>
{
return
(
return
(
<
div
key=
{
index
}
className=
{
`alert-${a
lert
.severity} alert`
}
>
<
div
key=
{
index
}
className=
{
`alert-${a
ppNotification
.severity} alert`
}
>
<
div
className=
"alert-icon"
>
<
div
className=
"alert-icon"
>
<
i
className=
{
a
lert
.
icon
}
/>
<
i
className=
{
a
ppNotification
.
icon
}
/>
</
div
>
</
div
>
<
div
className=
"alert-body"
>
<
div
className=
"alert-body"
>
<
div
className=
"alert-title"
>
{
a
lert
.
title
}
</
div
>
<
div
className=
"alert-title"
>
{
a
ppNotification
.
title
}
</
div
>
<
div
className=
"alert-text"
>
{
a
lert
.
text
}
</
div
>
<
div
className=
"alert-text"
>
{
a
ppNotification
.
text
}
</
div
>
</
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"
/>
<
i
className=
"fa fa fa-remove"
/>
</
button
>
</
button
>
</
div
>
</
div
>
...
@@ -82,15 +89,13 @@ export class AppNotificationList extends PureComponent<Props> {
...
@@ -82,15 +89,13 @@ export class AppNotificationList extends PureComponent<Props> {
}
}
}
}
function
mapStateToProps
(
state
)
{
const
mapStateToProps
=
(
state
:
StoreState
)
=>
({
return
{
appNotifications
:
state
.
appNotifications
.
appNotifications
,
alerts
:
state
.
alerts
.
alerts
,
});
};
}
const
mapDispatchToProps
=
{
const
mapDispatchToProps
=
{
addAppNotification
,
addAppNotification
,
clearAppNotification
,
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 {
...
@@ -12,14 +12,14 @@ interface AddAppNotificationAction {
interface
ClearAppNotificationAction
{
interface
ClearAppNotificationAction
{
type
:
ActionTypes
.
ClearAppNotification
;
type
:
ActionTypes
.
ClearAppNotification
;
payload
:
AppNotification
;
payload
:
number
;
}
}
export
type
Action
=
AddAppNotificationAction
|
ClearAppNotificationAction
;
export
type
Action
=
AddAppNotificationAction
|
ClearAppNotificationAction
;
export
const
clearAppNotification
=
(
a
lert
:
AppNotification
)
=>
({
export
const
clearAppNotification
=
(
a
ppNotificationId
:
number
)
=>
({
type
:
ActionTypes
.
ClearAppNotification
,
type
:
ActionTypes
.
ClearAppNotification
,
payload
:
a
lert
,
payload
:
a
ppNotificationId
,
});
});
export
const
addAppNotification
=
(
alert
:
AppNotification
)
=>
({
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'
;
import
{
ActionTypes
}
from
'./actions'
;
describe
(
'clear alert'
,
()
=>
{
describe
(
'clear alert'
,
()
=>
{
it
(
'should filter alert'
,
()
=>
{
it
(
'should filter alert'
,
()
=>
{
const
id1
=
1540301236048
;
const
id2
=
1540301248293
;
const
initialState
=
{
const
initialState
=
{
a
lert
s
:
[
a
ppNotification
s
:
[
{
{
id
:
id1
,
severity
:
'success'
,
severity
:
'success'
,
icon
:
'success'
,
icon
:
'success'
,
title
:
'test'
,
title
:
'test'
,
text
:
'test alert'
,
text
:
'test alert'
,
},
},
{
{
id
:
id2
,
severity
:
'fail'
,
severity
:
'fail'
,
icon
:
'warning'
,
icon
:
'warning'
,
title
:
'test2'
,
title
:
'test2'
,
...
@@ -20,14 +25,15 @@ describe('clear alert', () => {
...
@@ -20,14 +25,15 @@ describe('clear alert', () => {
],
],
};
};
const
result
=
a
lert
sReducer
(
initialState
,
{
const
result
=
a
ppNotification
sReducer
(
initialState
,
{
type
:
ActionTypes
.
ClearAppNotification
,
type
:
ActionTypes
.
ClearAppNotification
,
payload
:
i
nitialState
.
alerts
[
1
]
,
payload
:
i
d2
,
});
});
const
expectedResult
=
{
const
expectedResult
=
{
a
lert
s
:
[
a
ppNotification
s
:
[
{
{
id
:
id1
,
severity
:
'success'
,
severity
:
'success'
,
icon
:
'success'
,
icon
:
'success'
,
title
:
'test'
,
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'
;
import
{
Action
,
ActionTypes
}
from
'./actions'
;
export
const
initialState
:
A
lert
sState
=
{
export
const
initialState
:
A
ppNotification
sState
=
{
a
lert
s
:
[]
as
AppNotification
[],
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
)
{
switch
(
action
.
type
)
{
case
ActionTypes
.
AddAppNotification
:
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
:
case
ActionTypes
.
ClearAppNotification
:
return
{
return
{
...
state
,
...
state
,
a
lerts
:
state
.
alerts
.
filter
(
alert
=>
alert
!==
action
.
payload
),
a
ppNotifications
:
state
.
appNotifications
.
filter
(
appNotification
=>
appNotification
.
id
!==
action
.
payload
),
};
};
}
}
return
state
;
return
state
;
};
};
export
default
{
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
React
,
{
PureComponent
}
from
'react'
;
import
{
connect
}
from
'react-redux'
;
import
Tooltip
from
'app/core/components/Tooltip/Tooltip'
;
import
Tooltip
from
'app/core/components/Tooltip/Tooltip'
;
import
SlideDown
from
'app/core/components/Animations/SlideDown'
;
import
SlideDown
from
'app/core/components/Animations/SlideDown'
;
import
{
StoreState
,
FolderInfo
}
from
'app/types'
;
import
{
StoreState
,
FolderInfo
}
from
'app/types'
;
...
@@ -13,7 +12,7 @@ import {
...
@@ -13,7 +12,7 @@ import {
import
PermissionList
from
'app/core/components/PermissionList/PermissionList'
;
import
PermissionList
from
'app/core/components/PermissionList/PermissionList'
;
import
AddPermission
from
'app/core/components/PermissionList/AddPermission'
;
import
AddPermission
from
'app/core/components/PermissionList/AddPermission'
;
import
PermissionsInfo
from
'app/core/components/PermissionList/PermissionsInfo'
;
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
{
export
interface
Props
{
dashboardId
:
number
;
dashboardId
:
number
;
...
@@ -95,13 +94,6 @@ export class DashboardPermissions extends PureComponent<Props, State> {
...
@@ -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
)
=>
({
const
mapStateToProps
=
(
state
:
StoreState
)
=>
({
permissions
:
state
.
dashboard
.
permissions
,
permissions
:
state
.
dashboard
.
permissions
,
});
});
...
...
public/app/store/configureStore.ts
View file @
bb640938
...
@@ -10,6 +10,7 @@ import dashboardReducers from 'app/features/dashboard/state/reducers';
...
@@ -10,6 +10,7 @@ import dashboardReducers from 'app/features/dashboard/state/reducers';
import
pluginReducers
from
'app/features/plugins/state/reducers'
;
import
pluginReducers
from
'app/features/plugins/state/reducers'
;
import
dataSourcesReducers
from
'app/features/datasources/state/reducers'
;
import
dataSourcesReducers
from
'app/features/datasources/state/reducers'
;
import
usersReducers
from
'app/features/users/state/reducers'
;
import
usersReducers
from
'app/features/users/state/reducers'
;
import
appNotificationReducers
from
'app/core/components/AppNotifications/state/reducers'
;
const
rootReducers
=
{
const
rootReducers
=
{
...
sharedReducers
,
...
sharedReducers
,
...
@@ -21,6 +22,7 @@ const rootReducers = {
...
@@ -21,6 +22,7 @@ const rootReducers = {
...
pluginReducers
,
...
pluginReducers
,
...
dataSourcesReducers
,
...
dataSourcesReducers
,
...
usersReducers
,
...
usersReducers
,
...
appNotificationReducers
,
};
};
export
let
store
;
export
let
store
;
...
...
public/app/types/alerts.ts
View file @
bb640938
export
interface
AppNotification
{
export
interface
AppNotification
{
id
:
number
;
severity
:
string
;
severity
:
string
;
icon
:
string
;
icon
:
string
;
title
:
string
;
title
:
string
;
text
:
string
;
text
:
string
;
}
}
export
interface
A
lert
sState
{
export
interface
A
ppNotification
sState
{
a
lert
s
:
AppNotification
[];
a
ppNotification
s
:
AppNotification
[];
}
}
public/app/types/index.ts
View file @
bb640938
...
@@ -9,7 +9,7 @@ import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys';
...
@@ -9,7 +9,7 @@ import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys';
import
{
Invitee
,
OrgUser
,
User
,
UsersState
}
from
'./user'
;
import
{
Invitee
,
OrgUser
,
User
,
UsersState
}
from
'./user'
;
import
{
DataSource
,
DataSourcesState
}
from
'./datasources'
;
import
{
DataSource
,
DataSourcesState
}
from
'./datasources'
;
import
{
PluginDashboard
,
PluginMeta
,
Plugin
,
PluginsState
}
from
'./plugins'
;
import
{
PluginDashboard
,
PluginMeta
,
Plugin
,
PluginsState
}
from
'./plugins'
;
import
{
AppNotification
,
A
lert
sState
}
from
'./alerts'
;
import
{
AppNotification
,
A
ppNotification
sState
}
from
'./alerts'
;
export
{
export
{
Team
,
Team
,
...
@@ -48,7 +48,7 @@ export {
...
@@ -48,7 +48,7 @@ export {
UsersState
,
UsersState
,
PluginDashboard
,
PluginDashboard
,
AppNotification
,
AppNotification
,
A
lert
sState
,
A
ppNotification
sState
,
};
};
export
interface
StoreState
{
export
interface
StoreState
{
...
@@ -61,5 +61,5 @@ export interface StoreState {
...
@@ -61,5 +61,5 @@ export interface StoreState {
dashboard
:
DashboardState
;
dashboard
:
DashboardState
;
dataSources
:
DataSourcesState
;
dataSources
:
DataSourcesState
;
users
:
UsersState
;
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