Skip to content

Commit f435930

Browse files
committed
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-lib into refactor/application-group-overview-table
2 parents fa56ace + 52daa53 commit f435930

37 files changed

+701
-211
lines changed

.eslintrc.cjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,24 @@ module.exports = {
108108
'import/no-cycle': 'off',
109109
'import/prefer-default-export': 'off',
110110
'no-restricted-exports': 'off',
111-
'import/named': 'off'
111+
'import/named': 'off',
112112
},
113113
overrides: [
114114
{
115115
files: ['*.ts', '*.tsx'],
116116
rules: {
117117
'no-undef': 'off',
118+
'no-restricted-imports': [
119+
'error',
120+
{
121+
paths: [
122+
{
123+
name: 'react-toastify',
124+
message: 'Please use "ToastManager.showToast" instead.',
125+
}
126+
],
127+
},
128+
],
118129
},
119130
},
120131
],

package-lock.json

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.2.30-beta-2",
3+
"version": "0.3.5",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -64,7 +64,7 @@
6464
"prettier": "^3.1.1",
6565
"react-ga4": "^1.4.1",
6666
"react-mde": "^11.5.0",
67-
"react-toastify": "^8.2.0",
67+
"react-toastify": "9.1.3",
6868
"typescript": "5.5.4",
6969
"vite": "5.4.2",
7070
"vite-plugin-dts": "4.0.3",

src/Assets/Icon/ic-error.svg

Lines changed: 4 additions & 0 deletions
Loading

src/Assets/Icon/ic-info-filled.svg

Lines changed: 3 additions & 6 deletions
Loading

src/Assets/Icon/ic-locked.svg

Lines changed: 5 additions & 0 deletions
Loading

src/Assets/Icon/ic-success.svg

Lines changed: 4 additions & 0 deletions
Loading

src/Common/Constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { RegistryTypeDetailType } from './Types'
18+
import { getContainerRegistryIcon } from './utils'
1819

1920
export const FALLBACK_REQUEST_TIMEOUT = 60000
2021
export const Host = window?.__ORCHESTRATOR_ROOT__ ?? '/orchestrator'
@@ -207,6 +208,7 @@ export const REGISTRY_TYPE_MAP: Record<string, RegistryTypeDetailType> = {
207208
defaultValue: '',
208209
placeholder: '',
209210
},
211+
startIcon: getContainerRegistryIcon('ecr'),
210212
},
211213
'docker-hub': {
212214
value: 'docker-hub',
@@ -230,6 +232,7 @@ export const REGISTRY_TYPE_MAP: Record<string, RegistryTypeDetailType> = {
230232
defaultValue: '',
231233
placeholder: '',
232234
},
235+
startIcon: getContainerRegistryIcon('docker-hub'),
233236
},
234237
acr: {
235238
value: 'acr',
@@ -254,6 +257,7 @@ export const REGISTRY_TYPE_MAP: Record<string, RegistryTypeDetailType> = {
254257
defaultValue: '',
255258
placeholder: '',
256259
},
260+
startIcon: getContainerRegistryIcon('acr'),
257261
},
258262
'artifact-registry': {
259263
value: 'artifact-registry',
@@ -277,6 +281,7 @@ export const REGISTRY_TYPE_MAP: Record<string, RegistryTypeDetailType> = {
277281
defaultValue: '',
278282
placeholder: 'Paste json file content here',
279283
},
284+
startIcon: getContainerRegistryIcon('artifact-registry'),
280285
},
281286
gcr: {
282287
value: 'gcr',
@@ -300,6 +305,7 @@ export const REGISTRY_TYPE_MAP: Record<string, RegistryTypeDetailType> = {
300305
defaultValue: '',
301306
placeholder: 'Paste json file content here',
302307
},
308+
startIcon: getContainerRegistryIcon('gcr'),
303309
},
304310
quay: {
305311
value: 'quay',
@@ -323,6 +329,7 @@ export const REGISTRY_TYPE_MAP: Record<string, RegistryTypeDetailType> = {
323329
defaultValue: '',
324330
placeholder: '',
325331
},
332+
startIcon: getContainerRegistryIcon('quay'),
326333
},
327334
other: {
328335
value: 'other',
@@ -346,6 +353,7 @@ export const REGISTRY_TYPE_MAP: Record<string, RegistryTypeDetailType> = {
346353
defaultValue: '',
347354
placeholder: '',
348355
},
356+
startIcon: getContainerRegistryIcon('other'),
349357
},
350358
}
351359

src/Common/DeleteComponentModal/DeleteComponent.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import React, { useState } from 'react'
1818
import { useHistory } from 'react-router-dom'
19-
import { toast } from 'react-toastify'
2019
import info from '../../Assets/Icon/ic-info-filled.svg'
2120
import { ConfirmationDialog, DeleteDialog } from '../Dialogs'
2221
import { ServerErrors } from '../ServerError'
2322
import { DeleteComponentProps } from './types'
23+
import { ToastManager, ToastVariantType } from '@Shared/Services'
2424

2525
const DeleteComponent = ({
2626
setDeleting,
@@ -43,7 +43,10 @@ const DeleteComponent = ({
4343
setDeleting(true)
4444
try {
4545
await deleteComponent(payload)
46-
toast.success('Successfully deleted')
46+
ToastManager.showToast({
47+
variant: ToastVariantType.success,
48+
description: 'Successfully deleted',
49+
})
4750
toggleConfirmation(false)
4851
if (redirectTo) {
4952
push(url)

src/Common/GenericDescription/GenericDescription.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { useState, useRef, useEffect } from 'react'
1818
import Tippy from '@tippyjs/react'
1919
import ReactMde from 'react-mde'
2020
import 'react-mde/lib/styles/css/react-mde-all.css'
21-
import { toast } from 'react-toastify'
2221
import moment from 'moment'
2322
import Markdown from '../Markdown/MarkDown'
2423
import { DATE_TIME_FORMATS, deepEqual, showError } from '..'
@@ -31,7 +30,7 @@ import {
3130
MARKDOWN_EDITOR_COMMAND_TITLE,
3231
MARKDOWN_EDITOR_COMMAND_ICON_TIPPY_CONTENT,
3332
} from '../Markdown/constant'
34-
import { ButtonWithLoader } from '../../Shared'
33+
import { ButtonWithLoader, ToastManager, ToastVariantType } from '../../Shared'
3534
import { ReactComponent as HeaderIcon } from '../../Assets/Icon/ic-header.svg'
3635
import { ReactComponent as BoldIcon } from '../../Assets/Icon/ic-bold.svg'
3736
import { ReactComponent as ItalicIcon } from '../../Assets/Icon/ic-italic.svg'
@@ -73,7 +72,10 @@ const GenericDescription = ({
7372
const validateDescriptionText = (description: string): boolean => {
7473
let isValid = true
7574
if (description.length === 0) {
76-
toast.error(DESCRIPTION_EMPTY_ERROR_MSG)
75+
ToastManager.showToast({
76+
variant: ToastVariantType.error,
77+
description: DESCRIPTION_EMPTY_ERROR_MSG,
78+
})
7779
isValid = false
7880
}
7981
return isValid

src/Common/Helper.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,13 @@ import { components } from 'react-select'
2121
import * as Sentry from '@sentry/browser'
2222
import moment from 'moment'
2323
import { useLocation } from 'react-router-dom'
24-
import { toast } from 'react-toastify'
2524
import YAML from 'yaml'
26-
import { ERROR_EMPTY_SCREEN, SortingOrder, EXCLUDED_FALSY_VALUES, DISCORD_LINK, ZERO_TIME_STRING } from './Constants'
25+
import { ERROR_EMPTY_SCREEN, SortingOrder, EXCLUDED_FALSY_VALUES, DISCORD_LINK, ZERO_TIME_STRING, TOAST_ACCESS_DENIED } from './Constants'
2726
import { ServerErrors } from './ServerError'
28-
import { toastAccessDenied } from './ToastBody'
2927
import { AsyncOptions, AsyncState, UseSearchString } from './Types'
30-
import { scrollableInterface, DATE_TIME_FORMAT_STRING } from '../Shared'
28+
import { scrollableInterface, DATE_TIME_FORMAT_STRING, ToastManager, ToastVariantType } from '../Shared'
3129
import { ReactComponent as ArrowDown } from '../Assets/Icon/ic-chevron-down.svg'
3230

33-
toast.configure({
34-
autoClose: 3000,
35-
hideProgressBar: true,
36-
pauseOnHover: true,
37-
pauseOnFocusLoss: true,
38-
closeOnClick: false,
39-
newestOnTop: true,
40-
toastClassName: 'devtron-toast',
41-
bodyClassName: 'devtron-toast__body',
42-
})
43-
4431
export function showError(serverError, showToastOnUnknownError = true, hideAccessError = false) {
4532
if (serverError instanceof ServerErrors && Array.isArray(serverError.errors)) {
4633
serverError.errors.map(({ userMessage, internalMessage }) => {
@@ -49,10 +36,16 @@ export function showError(serverError, showToastOnUnknownError = true, hideAcces
4936
(userMessage === ERROR_EMPTY_SCREEN.UNAUTHORIZED || userMessage === ERROR_EMPTY_SCREEN.FORBIDDEN)
5037
) {
5138
if (!hideAccessError) {
52-
toastAccessDenied()
39+
ToastManager.showToast({
40+
variant: ToastVariantType.notAuthorized,
41+
description: TOAST_ACCESS_DENIED.SUBTITLE,
42+
})
5343
}
5444
} else {
55-
toast.error(userMessage || internalMessage)
45+
ToastManager.showToast({
46+
variant: ToastVariantType.error,
47+
description: userMessage || internalMessage,
48+
})
5649
}
5750
})
5851
} else {
@@ -62,9 +55,15 @@ export function showError(serverError, showToastOnUnknownError = true, hideAcces
6255

6356
if (showToastOnUnknownError) {
6457
if (serverError.message) {
65-
toast.error(serverError.message)
58+
ToastManager.showToast({
59+
variant: ToastVariantType.error,
60+
description: serverError.message,
61+
})
6662
} else {
67-
toast.error('Some Error Occurred')
63+
ToastManager.showToast({
64+
variant: ToastVariantType.error,
65+
description: 'Some Error Occurred',
66+
})
6867
}
6968
}
7069
}
@@ -465,7 +464,10 @@ export function copyToClipboard(str, callback = noop) {
465464
callback()
466465
})
467466
.catch(() => {
468-
toast.error('Failed to copy to clipboard')
467+
ToastManager.showToast({
468+
variant: ToastVariantType.error,
469+
description: 'Failed to copy to clipboard',
470+
})
469471
})
470472
} else {
471473
unsecureCopyToClipboard(str, callback)

src/Common/ImageTags.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import { useEffect, useRef, useState } from 'react'
18-
import { toast } from 'react-toastify'
1918
import Tippy from '@tippyjs/react'
2019
import { ReactComponent as Add } from '../Assets/Icon/ic-add.svg'
2120
import { ReactComponent as Close } from '../Assets/Icon/ic-cross.svg'
@@ -30,7 +29,7 @@ import { ImageButtonType, ImageTaggingContainerType, ReleaseTag } from './ImageT
3029
import { showError, stopPropagation } from './Helper'
3130
import { setImageTags } from './Common.service'
3231
import { Progressing } from './Progressing'
33-
import { InfoIconTippy } from '../Shared'
32+
import { InfoIconTippy, ToastManager, ToastVariantType } from '../Shared'
3433

3534
export const ImageTagsContainer = ({
3635
// Setting it to zero in case of external pipeline
@@ -257,7 +256,10 @@ export const ImageTagsContainer = ({
257256
.catch((err) => {
258257
// Fix toast message
259258
if (err.errors?.[0]?.userMessage?.appReleaseTags?.length) {
260-
toast.error(err.errors?.[0]?.internalMessage)
259+
ToastManager.showToast({
260+
variant: ToastVariantType.error,
261+
description: err.errors?.[0]?.internalMessage,
262+
})
261263
errorStateHandling(err.errors)
262264
} else {
263265
showError(err)
@@ -395,7 +397,7 @@ export const ImageTagsContainer = ({
395397
</div>
396398
{showTagsWarning && (
397399
<div className="cn-7 mb-8 flex left">
398-
<Info className="form__icon--info icon-dim-16 mr-2" />
400+
<Info className="icon-dim-16 mr-2" />
399401
Tags cannot be edited/removed later
400402
</div>
401403
)}

0 commit comments

Comments
 (0)