Skip to content

Commit ed3b7bd

Browse files
authored
RI-7247: older notifications are displayed
1 parent bf5aa14 commit ed3b7bd

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

redisinsight/ui/src/components/base/display/toast/RiToast.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@ const StyledMessage = styled.div<{ theme: Theme }>`
1717
margin-bottom: ${({ theme }) => theme.core.space.space100};
1818
`
1919

20+
type RiToastType = ToastContentParams &
21+
CommonProps & {
22+
onClose?: VoidFunction
23+
}
2024
export const riToast = (
21-
{
22-
onClose,
23-
actions,
24-
message,
25-
...content
26-
}: ToastContentParams &
27-
CommonProps & {
28-
onClose?: VoidFunction
29-
},
25+
{ onClose, actions, message, ...content }: RiToastType,
3026
options?: ToastOptions | undefined,
3127
) => {
3228
const toastContent: ToastContentParams = {

redisinsight/ui/src/components/notifications/Notifications.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ const Notifications = () => {
5656

5757
const showSuccessToasts = (data: IMessage[]) =>
5858
data.forEach(({ id = '', title = '', message = '', className, group }) => {
59-
riToast(
59+
const handleClose = () => {
60+
onSubmitNotification(id, group)
61+
removeToast(id)
62+
}
63+
if (toastIdsRef.current.has(id)) {
64+
removeToast(id)
65+
return
66+
}
67+
const toastId = riToast(
6068
{
6169
className,
6270
message: title,
@@ -66,15 +74,13 @@ const Notifications = () => {
6674
primary: {
6775
closes: true,
6876
label: 'Ok',
69-
onClick: () => {
70-
onSubmitNotification(id, group)
71-
removeToast(id)
72-
},
77+
onClick: handleClose,
7378
},
7479
},
7580
},
7681
{ variant: riToast.Variant.Success },
7782
)
83+
toastIdsRef.current.set(id, toastId)
7884
})
7985

8086
const showErrorsToasts = (errors: IError[]) =>
@@ -87,6 +93,10 @@ const Notifications = () => {
8793
title = DEFAULT_ERROR_TITLE,
8894
additionalInfo,
8995
}) => {
96+
if (toastIdsRef.current.has(id)) {
97+
removeToast(id)
98+
return
99+
}
90100
let toastId: ReturnType<typeof riToast>
91101
if (ApiEncryptionErrors.includes(name)) {
92102
toastId = errorMessages.ENCRYPTION(() => removeToast(id), instanceId)
@@ -117,8 +127,12 @@ const Notifications = () => {
117127
const showInfiniteToasts = (data: InfiniteMessage[]) =>
118128
data.forEach((message: InfiniteMessage) => {
119129
const { id, Inner, className = '' } = message
120-
121-
riToast(
130+
if (toastIdsRef.current.has(id)) {
131+
removeToast(id)
132+
dispatch(removeInfiniteNotification(id))
133+
return
134+
}
135+
const toastId = riToast(
122136
{
123137
className: cx(styles.infiniteMessage, className),
124138
description: Inner,
@@ -153,6 +167,7 @@ const Notifications = () => {
153167
},
154168
{ variant: riToast.Variant.Notice, autoClose: ONE_HOUR },
155169
)
170+
toastIdsRef.current.set(id, toastId)
156171
})
157172

158173
useEffect(() => {

redisinsight/ui/src/slices/app/notifications.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ const notificationsSlice = createSlice({
8484
state.errors.push(error)
8585
},
8686
removeError: (state, { payload = '' }: { payload: string }) => {
87-
state.errors = state.errors.filter((error) => error.id !== payload)
87+
if (state.errors.find((error) => error.id === payload)) {
88+
state.errors = state.errors.filter((error) => error.id !== payload)
89+
}
8890
},
8991
resetErrors: (state) => {
9092
state.errors = []
@@ -97,10 +99,14 @@ const notificationsSlice = createSlice({
9799
})
98100
},
99101
removeMessage: (state, { payload = '' }: { payload: string }) => {
100-
state.messages = state.messages.filter(
101-
(message) => message.id !== payload,
102-
)
103-
state.errors = state.errors.filter((error) => error.id !== payload)
102+
if (state.messages.find((message) => message.id === payload)) {
103+
state.messages = state.messages.filter(
104+
(message) => message.id !== payload,
105+
)
106+
}
107+
if (state.errors.find((error) => error.id === payload)) {
108+
state.errors = state.errors.filter((error) => error.id !== payload)
109+
}
104110
},
105111
resetMessages: (state) => {
106112
state.messages = []
@@ -166,9 +172,11 @@ const notificationsSlice = createSlice({
166172
}
167173
},
168174
removeInfiniteNotification: (state, { payload }: PayloadAction<string>) => {
169-
state.infiniteMessages = state.infiniteMessages.filter(
170-
(message) => message.id !== payload,
171-
)
175+
if (state.infiniteMessages.find((message) => message.id === payload)) {
176+
state.infiniteMessages = state.infiniteMessages.filter(
177+
(message) => message.id !== payload,
178+
)
179+
}
172180
},
173181
},
174182
})

0 commit comments

Comments
 (0)