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
50da456b
Unverified
Commit
50da456b
authored
Feb 08, 2021
by
Torkel Ödegaard
Committed by
GitHub
Feb 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Alerts: Dedupe alerts so that we do not fill the screen with the same alert messsage (#30935)
parent
ae64dcf0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
+59
-4
public/app/core/reducers/appNotification.test.ts
+42
-0
public/app/core/reducers/appNotification.ts
+17
-4
No files found.
public/app/core/reducers/appNotification.test.ts
View file @
50da456b
...
...
@@ -116,4 +116,46 @@ describe('notify', () => {
expect
(
result
).
toEqual
(
expectedResult
);
});
it
(
'Dedupe identical alerts'
,
()
=>
{
const
initialState
=
{
appNotifications
:
[
{
id
:
'id1'
,
severity
:
AppNotificationSeverity
.
Success
,
icon
:
'success'
,
title
:
'test'
,
text
:
'test alert'
,
timeout
:
AppNotificationTimeout
.
Success
,
},
],
};
const
result
=
appNotificationsReducer
(
initialState
,
notifyApp
({
id
:
'id2'
,
severity
:
AppNotificationSeverity
.
Success
,
icon
:
'success'
,
title
:
'test'
,
text
:
'test alert'
,
timeout
:
AppNotificationTimeout
.
Success
,
})
);
const
expectedResult
=
{
appNotifications
:
[
{
id
:
'id1'
,
severity
:
AppNotificationSeverity
.
Success
,
icon
:
'success'
,
title
:
'test'
,
text
:
'test alert'
,
timeout
:
AppNotificationTimeout
.
Success
,
},
],
};
expect
(
result
).
toEqual
(
expectedResult
);
});
});
public/app/core/reducers/appNotification.ts
View file @
50da456b
...
...
@@ -15,10 +15,23 @@ const appNotificationsSlice = createSlice({
name
:
'appNotifications'
,
initialState
,
reducers
:
{
notifyApp
:
(
state
,
action
:
PayloadAction
<
AppNotification
>
):
AppNotificationsState
=>
({
...
state
,
appNotifications
:
state
.
appNotifications
.
concat
([
action
.
payload
]),
}),
notifyApp
:
(
state
,
action
:
PayloadAction
<
AppNotification
>
)
=>
{
const
newAlert
=
action
.
payload
;
for
(
const
existingAlert
of
state
.
appNotifications
)
{
if
(
newAlert
.
icon
===
existingAlert
.
icon
&&
newAlert
.
severity
===
existingAlert
.
severity
&&
newAlert
.
text
===
existingAlert
.
text
&&
newAlert
.
title
===
existingAlert
.
title
&&
newAlert
.
component
===
existingAlert
.
component
)
{
return
;
}
}
state
.
appNotifications
.
push
(
newAlert
);
},
clearAppNotification
:
(
state
,
action
:
PayloadAction
<
string
>
):
AppNotificationsState
=>
({
...
state
,
appNotifications
:
state
.
appNotifications
.
filter
((
appNotification
)
=>
appNotification
.
id
!==
action
.
payload
),
...
...
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