Skip to content

Commit 2e6a3cd

Browse files
committed
Merge branch 'develop' into feat/mandatory-tags-v2
2 parents 1c20006 + e97ee17 commit 2e6a3cd

File tree

11 files changed

+142
-135
lines changed

11 files changed

+142
-135
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,4 @@ typings/
105105

106106
.DS_Store
107107
.npmrc
108+
.build-cache

package-lock.json

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

package.json

Lines changed: 3 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": "1.2.5-beta-10",
3+
"version": "1.2.7",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -48,7 +48,7 @@
4848
"@typescript-eslint/eslint-plugin": "8.3.0",
4949
"@typescript-eslint/parser": "8.3.0",
5050
"@vitejs/plugin-react": "4.3.1",
51-
"eslint": "^8.56.0",
51+
"eslint": "^8.57.1",
5252
"eslint-config-airbnb": "^19.0.4",
5353
"eslint-config-prettier": "^9.1.0",
5454
"eslint-import-resolver-typescript": "^3.6.1",
@@ -107,6 +107,7 @@
107107
"tslib": "2.7.0"
108108
},
109109
"overrides": {
110+
"cross-spawn": "^7.0.5",
110111
"react-dates": {
111112
"react": "^17.0.2",
112113
"react-dom": "^17.0.2"

src/Common/Api.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,14 @@ async function fetchAPI<K = object>(
150150
})
151151
} else {
152152
handleLogout()
153-
return { code: 401, status: 'Unauthorized', result: [] }
153+
// Using this way to ensure that the user is redirected to the login page
154+
// and the component has enough time to get unmounted otherwise the component re-renders
155+
// and try to access some property of a variable and log exception to sentry
156+
return await new Promise((resolve) => {
157+
setTimeout(() => {
158+
resolve({ code: 401, status: 'Unauthorized', result: [] })
159+
}, 1000)
160+
})
154161
}
155162
} else if (response.status >= 300 && response.status <= 599) {
156163
return await handleServerError(contentType, response)

src/Common/Helper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ export const getUrlWithSearchParams = <T extends string | number = string | numb
511511
/**
512512
* Custom exception logger function for logging errors to sentry
513513
*/
514-
export const logExceptionToSentry = Sentry.captureException.bind(window)
514+
export const logExceptionToSentry: typeof Sentry.captureException = Sentry.captureException.bind(window)
515515

516516
export const customStyles = {
517517
control: (base, state) => ({

src/Common/Markdown/MarkDown.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ const MarkDown = ({ setExpandableIcon, markdown, className, breaks, disableEscap
4747
if (task) {
4848
return `<li style="list-style: none">
4949
<input disabled type="checkbox" ${checked ? 'checked' : ''} class="dc__vertical-align-middle" style="margin: 0 0.2em 0.25em -1.4em">
50-
${text}
50+
${marked(text)}
5151
</li>`
5252
}
53-
return `<li>${text}</li>`
53+
return `<li>${marked(text)}</li>`
5454
}
5555

5656
renderer.image = ({ href, title, text }: Tokens.Image) =>
@@ -60,7 +60,7 @@ const MarkDown = ({ setExpandableIcon, markdown, className, breaks, disableEscap
6060
<div class="table-container">
6161
<table>
6262
<thead>
63-
<tr>${header.map((headerCell) => `<th align="${headerCell.align}">${headerCell.text}</th>`).join('')}</tr>
63+
<tr>${header.map((headerCell) => `<th align="${headerCell.align}">${marked(headerCell.text)}</th>`).join('')}</tr>
6464
</thead>
6565
<tbody>
6666
${rows.map((row) => renderTableRow(row)).join('')}

src/Shared/Components/ConfirmationModal/ConfirmationModal.tsx

Lines changed: 85 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ import { ButtonHTMLAttributes, ChangeEvent, useCallback, useEffect, useState } f
22
import { AnimatePresence, motion } from 'framer-motion'
33
import { CustomInput, useRegisterShortcut, UseRegisterShortcutProvider } from '@Common/index'
44
import { ComponentSizeType } from '@Shared/constants'
5-
import { ConfirmationModalProps } from './types'
5+
import { ConfirmationModalBodyProps, ConfirmationModalProps } from './types'
66
import { getPrimaryButtonStyleFromVariant, getConfirmationLabel, getIconFromVariant } from './utils'
77
import { Button, ButtonStyleType, ButtonVariantType } from '../Button'
88
import './confirmationModal.scss'
99
import { Backdrop } from '../Backdrop'
1010

11-
const ConfirmationModal = ({
11+
const ConfirmationModalBody = ({
1212
title,
1313
subtitle,
1414
Icon,
1515
variant,
1616
buttonConfig,
1717
customInputConfig,
1818
children,
19-
showConfirmationModal,
2019
handleClose,
21-
}: ConfirmationModalProps) => {
20+
}: ConfirmationModalBodyProps) => {
2221
const { registerShortcut, unregisterShortcut } = useRegisterShortcut()
2322

2423
const [confirmationText, setConfirmationText] = useState<string>('')
@@ -45,108 +44,100 @@ const ConfirmationModal = ({
4544
}, [primaryButtonConfig, secondaryButtonConfig])
4645

4746
useEffect(() => {
48-
if (showConfirmationModal) {
49-
registerShortcut({ keys: ['Enter'], callback: handleTriggerPrimaryActionButton })
50-
}
47+
registerShortcut({ keys: ['Enter'], callback: handleTriggerPrimaryActionButton })
5148

5249
return () => {
53-
if (showConfirmationModal) {
54-
unregisterShortcut(['Enter'])
55-
}
50+
unregisterShortcut(['Enter'])
5651
}
57-
}, [showConfirmationModal, primaryButtonConfig, disablePrimaryButton])
52+
}, [primaryButtonConfig, disablePrimaryButton])
5853

5954
const handleCustomInputChange = (e: ChangeEvent<HTMLInputElement>) => {
6055
setConfirmationText(e.target.value)
6156
}
6257

6358
return (
64-
<AnimatePresence>
65-
{showConfirmationModal ? (
66-
<Backdrop onEscape={handleCloseWrapper}>
67-
<motion.div
68-
className="confirmation-modal flexbox-col br-8 bcn-0 dc__m-auto mt-40 w-400"
69-
exit={{ y: 100, opacity: 0, scale: 0.75, transition: { duration: 0.35 } }}
70-
initial={{ y: 100, opacity: 0, scale: 0.75 }}
71-
animate={{ y: 0, opacity: 1, scale: 1 }}
72-
>
73-
<div className="flexbox-col dc__gap-12 p-20">
74-
<RenderIcon className="icon-dim-48 dc__no-shrink" />
75-
<span className="cn-9 fs-16 fw-6 lh-24 dc__word-break">{title}</span>
76-
77-
{typeof subtitle === 'string' ? (
78-
<span className="cn-8 fs-13 fw-4 lh-20 dc__word-break">{subtitle}</span>
79-
) : (
80-
subtitle
81-
)}
82-
83-
{customInputConfig && (
84-
<CustomInput
85-
name={customInputIdentifier}
86-
value={confirmationText}
87-
onChange={handleCustomInputChange}
88-
label={getConfirmationLabel(confirmationKeyword)}
89-
inputWrapClassName="w-100"
90-
placeholder="Type to confirm"
91-
isRequiredField
92-
autoFocus
93-
/>
94-
)}
95-
96-
{children}
97-
</div>
98-
<div className="p-16 dc__gap-12 flexbox dc__content-end">
99-
{secondaryButtonConfig && (
100-
<Button
101-
dataTestId="confirmation-modal-secondary-button"
102-
size={ComponentSizeType.large}
103-
variant={ButtonVariantType.secondary}
104-
style={
105-
'style' in secondaryButtonConfig
106-
? secondaryButtonConfig.style
107-
: ButtonStyleType.neutral
108-
}
109-
disabled={secondaryButtonConfig.disabled}
110-
text={secondaryButtonConfig.text}
111-
onClick={
112-
secondaryButtonConfig.onClick as ButtonHTMLAttributes<HTMLButtonElement>['onClick']
113-
}
114-
startIcon={secondaryButtonConfig.startIcon}
115-
endIcon={secondaryButtonConfig.endIcon}
116-
/>
117-
)}
118-
119-
{primaryButtonConfig && (
120-
<Button
121-
dataTestId="confirmation-modal-primary-button"
122-
size={ComponentSizeType.large}
123-
variant={ButtonVariantType.primary}
124-
style={
125-
'style' in primaryButtonConfig
126-
? primaryButtonConfig.style
127-
: getPrimaryButtonStyleFromVariant(variant)
128-
}
129-
disabled={
130-
('disabled' in primaryButtonConfig && primaryButtonConfig.disabled) ||
131-
disablePrimaryButton
132-
}
133-
isLoading={primaryButtonConfig.isLoading}
134-
text={primaryButtonConfig.text}
135-
onClick={
136-
primaryButtonConfig.onClick as ButtonHTMLAttributes<HTMLButtonElement>['onClick']
137-
}
138-
startIcon={primaryButtonConfig.startIcon}
139-
endIcon={primaryButtonConfig.endIcon}
140-
/>
141-
)}
142-
</div>
143-
</motion.div>
144-
</Backdrop>
145-
) : null}
146-
</AnimatePresence>
59+
<Backdrop onEscape={handleCloseWrapper}>
60+
<motion.div
61+
className="confirmation-modal flexbox-col br-8 bcn-0 dc__m-auto mt-40 w-400"
62+
exit={{ y: 100, opacity: 0, scale: 0.75, transition: { duration: 0.35 } }}
63+
initial={{ y: 100, opacity: 0, scale: 0.75 }}
64+
animate={{ y: 0, opacity: 1, scale: 1 }}
65+
>
66+
<div className="flexbox-col dc__gap-12 p-20">
67+
<RenderIcon className="icon-dim-48 dc__no-shrink" />
68+
<span className="cn-9 fs-16 fw-6 lh-24 dc__word-break">{title}</span>
69+
70+
{typeof subtitle === 'string' ? (
71+
<span className="cn-8 fs-13 fw-4 lh-20 dc__word-break">{subtitle}</span>
72+
) : (
73+
subtitle
74+
)}
75+
76+
{customInputConfig && (
77+
<CustomInput
78+
name={customInputIdentifier}
79+
value={confirmationText}
80+
onChange={handleCustomInputChange}
81+
label={getConfirmationLabel(confirmationKeyword)}
82+
inputWrapClassName="w-100"
83+
placeholder="Type to confirm"
84+
isRequiredField
85+
autoFocus
86+
/>
87+
)}
88+
89+
{children}
90+
</div>
91+
<div className="p-16 dc__gap-12 flexbox dc__content-end">
92+
{secondaryButtonConfig && (
93+
<Button
94+
dataTestId="confirmation-modal-secondary-button"
95+
size={ComponentSizeType.large}
96+
variant={ButtonVariantType.secondary}
97+
style={
98+
'style' in secondaryButtonConfig ? secondaryButtonConfig.style : ButtonStyleType.neutral
99+
}
100+
disabled={secondaryButtonConfig.disabled}
101+
text={secondaryButtonConfig.text}
102+
onClick={
103+
secondaryButtonConfig.onClick as ButtonHTMLAttributes<HTMLButtonElement>['onClick']
104+
}
105+
startIcon={secondaryButtonConfig.startIcon}
106+
endIcon={secondaryButtonConfig.endIcon}
107+
/>
108+
)}
109+
110+
{primaryButtonConfig && (
111+
<Button
112+
dataTestId="confirmation-modal-primary-button"
113+
size={ComponentSizeType.large}
114+
variant={ButtonVariantType.primary}
115+
style={
116+
'style' in primaryButtonConfig
117+
? primaryButtonConfig.style
118+
: getPrimaryButtonStyleFromVariant(variant)
119+
}
120+
disabled={
121+
('disabled' in primaryButtonConfig && primaryButtonConfig.disabled) ||
122+
disablePrimaryButton
123+
}
124+
isLoading={primaryButtonConfig.isLoading}
125+
text={primaryButtonConfig.text}
126+
onClick={primaryButtonConfig.onClick as ButtonHTMLAttributes<HTMLButtonElement>['onClick']}
127+
startIcon={primaryButtonConfig.startIcon}
128+
endIcon={primaryButtonConfig.endIcon}
129+
/>
130+
)}
131+
</div>
132+
</motion.div>
133+
</Backdrop>
147134
)
148135
}
149136

137+
const ConfirmationModal = ({ showConfirmationModal, ...props }: ConfirmationModalProps) => (
138+
<AnimatePresence>{showConfirmationModal ? <ConfirmationModalBody {...props} /> : null}</AnimatePresence>
139+
)
140+
150141
const WrapWithShortcutProvider = (props: ConfirmationModalProps) => (
151142
<UseRegisterShortcutProvider ignoreTags={['button']}>
152143
<ConfirmationModal {...props} />

src/Shared/Components/ConfirmationModal/types.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ type CustomInputConfigOrChildrenType =
4545
children?: never
4646
}
4747

48-
export type ConfirmationModalProps = {
49-
title: string
50-
subtitle: ReactNode
51-
handleClose: (e?: SyntheticEvent) => void
52-
showConfirmationModal: boolean
53-
} & (
48+
type ButtonConfigAndVariantType =
5449
| {
5550
variant: Exclude<ConfirmationModalVariantType, ConfirmationModalVariantType.custom>
5651
Icon?: never
@@ -64,5 +59,13 @@ export type ConfirmationModalProps = {
6459
Pick<ButtonProps, 'disabled' | 'style'>
6560
>
6661
}
67-
) &
62+
63+
export type ConfirmationModalProps = {
64+
title: string
65+
subtitle: ReactNode
66+
handleClose: (e?: SyntheticEvent) => void
67+
showConfirmationModal: boolean
68+
} & ButtonConfigAndVariantType &
6869
CustomInputConfigOrChildrenType
70+
71+
export type ConfirmationModalBodyProps = Omit<ConfirmationModalProps, 'showConfirmationModal'>

0 commit comments

Comments
 (0)