Skip to content

Commit 4c64b06

Browse files
committed
fix refactor error-messages generation
1 parent dba322b commit 4c64b06

File tree

5 files changed

+62
-93
lines changed

5 files changed

+62
-93
lines changed

redisinsight/ui/src/components/notifications/components/infinite-messages/InfiniteMessages.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const INFINITE_MESSAGES: InfiniteMessagesType = {
7474
PENDING_CREATE_DB: (step?: CloudJobStep) => ({
7575
id: InfiniteMessagesIds.oAuthProgress,
7676
customIcon: LoaderLargeIcon,
77+
variation: step,
7778
message: (
7879
<>
7980
{(step === CloudJobStep.Credentials || !step) &&
Lines changed: 39 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,34 @@
11
import React from 'react'
22

3-
import { riToast } from 'uiSrc/components/base/display/toast'
43
import { InfoIcon, ToastDangerIcon } from 'uiSrc/components/base/icons'
54

65
import RdiDeployErrorContent from './components/rdi-deploy-error-content'
76
import { EncryptionErrorContent, DefaultErrorContent } from './components'
87
import CloudCapiUnAuthorizedErrorContent from './components/cloud-capi-unauthorized'
9-
import { defaultContainerId } from './constants'
108

11-
// TODO: use i18n file for texts
129
export default {
13-
DEFAULT: (
14-
text: any,
15-
onClose = () => {},
16-
title: string = 'Error',
17-
toastId?: string,
18-
) =>
19-
riToast(
20-
{
21-
'data-testid': 'toast-error',
22-
customIcon: ToastDangerIcon,
23-
message: title,
24-
description: <DefaultErrorContent text={text} />,
25-
actions: {
26-
primary: {
27-
label: 'OK',
28-
closes: true,
29-
onClick: onClose,
30-
},
31-
},
32-
},
33-
{
34-
variant: riToast.Variant.Danger,
35-
toastId,
36-
containerId: defaultContainerId,
37-
},
38-
),
39-
ENCRYPTION: (onClose = () => {}, instanceId = '', toastId?: string) =>
40-
riToast(
41-
{
42-
'data-testid': 'toast-error-encryption',
43-
customIcon: InfoIcon,
44-
message: 'Unable to decrypt',
45-
description: (
46-
<EncryptionErrorContent instanceId={instanceId} onClose={onClose} />
47-
),
48-
showCloseButton: false,
49-
},
50-
{
51-
variant: riToast.Variant.Danger,
52-
toastId,
53-
containerId: defaultContainerId,
10+
DEFAULT: (text: any, onClose = () => {}, title: string = 'Error') => ({
11+
'data-testid': 'toast-error',
12+
customIcon: ToastDangerIcon,
13+
message: title,
14+
description: <DefaultErrorContent text={text} />,
15+
actions: {
16+
primary: {
17+
label: 'OK',
18+
closes: true,
19+
onClick: onClose,
5420
},
21+
},
22+
}),
23+
ENCRYPTION: (onClose = () => {}, instanceId = '') => ({
24+
'data-testid': 'toast-error-encryption',
25+
customIcon: InfoIcon,
26+
message: 'Unable to decrypt',
27+
description: (
28+
<EncryptionErrorContent instanceId={instanceId} onClose={onClose} />
5529
),
30+
showCloseButton: false,
31+
}),
5632
CLOUD_CAPI_KEY_UNAUTHORIZED: (
5733
{
5834
message,
@@ -63,47 +39,27 @@ export default {
6339
},
6440
additionalInfo: Record<string, any>,
6541
onClose: () => void,
66-
toastId?: string,
67-
) =>
68-
riToast(
69-
{
70-
'data-testid': 'toast-error-cloud-capi-key-unauthorized',
71-
customIcon: ToastDangerIcon,
72-
message: title,
73-
showCloseButton: false,
74-
description: (
75-
<CloudCapiUnAuthorizedErrorContent
76-
text={message}
77-
resourceId={additionalInfo.resourceId}
78-
onClose={onClose}
79-
/>
80-
),
81-
},
82-
{
83-
variant: riToast.Variant.Danger,
84-
toastId,
85-
containerId: defaultContainerId,
86-
},
42+
) => ({
43+
'data-testid': 'toast-error-cloud-capi-key-unauthorized',
44+
customIcon: ToastDangerIcon,
45+
message: title,
46+
showCloseButton: false,
47+
description: (
48+
<CloudCapiUnAuthorizedErrorContent
49+
text={message}
50+
resourceId={additionalInfo.resourceId}
51+
onClose={onClose}
52+
/>
8753
),
54+
}),
8855
RDI_DEPLOY_PIPELINE: (
8956
{ title, message }: { title?: string; message: string },
9057
onClose: () => void,
91-
toastId?: string,
92-
) =>
93-
riToast(
94-
{
95-
'data-testid': 'toast-error-deploy',
96-
customIcon: ToastDangerIcon,
97-
onClose,
98-
message: title,
99-
description: (
100-
<RdiDeployErrorContent message={message} onClose={onClose} />
101-
),
102-
},
103-
{
104-
variant: riToast.Variant.Danger,
105-
toastId,
106-
containerId: defaultContainerId,
107-
},
108-
),
58+
) => ({
59+
'data-testid': 'toast-error-deploy',
60+
customIcon: ToastDangerIcon,
61+
onClose,
62+
message: title,
63+
description: <RdiDeployErrorContent message={message} onClose={onClose} />,
64+
}),
10965
}

redisinsight/ui/src/components/notifications/hooks/useErrorNotifications.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { ApiEncryptionErrors } from 'uiSrc/constants/apiErrors'
88
import errorMessages from 'uiSrc/components/notifications/error-messages'
99
import { CustomErrorCodes } from 'uiSrc/constants'
1010
import { errorsSelector, removeMessage } from 'uiSrc/slices/app/notifications'
11+
import { defaultContainerId } from 'uiSrc/components/notifications/constants'
12+
import { RiToastType } from 'uiSrc/components/base/display/toast/RiToast'
1113

1214
const DEFAULT_ERROR_TITLE = 'Error'
1315

@@ -36,41 +38,42 @@ export const useErrorNotifications = () => {
3638
removeToast(id)
3739
return
3840
}
39-
let toastId: ReturnType<typeof riToast>
41+
42+
let errorMessage: RiToastType
4043
if (ApiEncryptionErrors.includes(name)) {
41-
toastId = errorMessages.ENCRYPTION(
44+
errorMessage = errorMessages.ENCRYPTION(
4245
() => removeToast(id),
4346
instanceId,
44-
id,
4547
)
4648
} else if (
4749
additionalInfo?.errorCode ===
4850
CustomErrorCodes.CloudCapiKeyUnauthorized
4951
) {
50-
toastId = errorMessages.CLOUD_CAPI_KEY_UNAUTHORIZED(
52+
errorMessage = errorMessages.CLOUD_CAPI_KEY_UNAUTHORIZED(
5153
{ message, title },
5254
additionalInfo,
5355
() => removeToast(id),
54-
id,
5556
)
5657
} else if (
5758
additionalInfo?.errorCode ===
5859
CustomErrorCodes.RdiDeployPipelineFailure
5960
) {
60-
toastId = errorMessages.RDI_DEPLOY_PIPELINE(
61+
errorMessage = errorMessages.RDI_DEPLOY_PIPELINE(
6162
{ title, message },
6263
() => removeToast(id),
63-
id,
6464
)
6565
} else {
66-
toastId = errorMessages.DEFAULT(
66+
errorMessage = errorMessages.DEFAULT(
6767
message,
6868
() => removeToast(id),
6969
title,
70-
id,
7170
)
7271
}
73-
72+
const toastId: ReturnType<typeof riToast> = riToast(errorMessage, {
73+
variant: riToast.Variant.Danger,
74+
toastId: id,
75+
containerId: defaultContainerId,
76+
})
7477
toastIdsRef.current.set(id, toastId)
7578
},
7679
)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ const notificationsSlice = createSlice({
168168
if (index === -1) {
169169
state.infiniteMessages.push(payload)
170170
} else {
171+
const currentNotification = state.infiniteMessages[index]
172+
// check if existing notification is exactly the same as the new one, if yes, do not update
173+
if (
174+
currentNotification.variation &&
175+
payload.variation === currentNotification.variation
176+
) {
177+
return
178+
}
171179
state.infiniteMessages[index] = payload
172180
}
173181
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export interface IGlobalNotification {
247247

248248
export interface InfiniteMessage {
249249
id: string
250+
variation?: string
250251
variant?: ToastVariant
251252
className?: string
252253
message?: RiToastType['message']

0 commit comments

Comments
 (0)