Skip to content

Commit

Permalink
feat: clear timeout on unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
arunjaindev committed Nov 26, 2024
1 parent ed3df67 commit 86d0b81
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtron-labs/devtron-fe-common-lib",
"version": "1.1.4-beta-1",
"version": "1.1.4-beta-2",
"description": "Supporting common component library",
"type": "module",
"main": "dist/index.js",
Expand Down
1 change: 0 additions & 1 deletion src/Shared/Components/Backdrop/Backdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useRegisterShortcut } from '@Common/Hooks'
import { preventBodyScroll, preventOutsideFocus } from '@Shared/Helpers'
import { DEVTRON_BASE_MAIN_ID } from '@Shared/constants'
import { BackdropProps } from './types'
import './backdrop.scss'

const Backdrop = ({ children, onEscape }: BackdropProps) => {
const { registerShortcut, unregisterShortcut } = useRegisterShortcut()
Expand Down
5 changes: 0 additions & 5 deletions src/Shared/Components/Backdrop/backdrop.scss

This file was deleted.

3 changes: 3 additions & 0 deletions src/Shared/Components/Backdrop/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ import { ReactNode } from 'react'

export interface BackdropProps {
children: ReactNode
/**
* @param onEscape: please wrap in a useCallback, with respective dependencies or []
*/
onEscape: () => void
}
2 changes: 2 additions & 0 deletions src/Shared/Components/CICDHistory/TriggerOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ const ProgressingStatus = React.memo(({ status, stage, type }: ProgressingStatus
const toggleAbortConfiguration = (): void => {
setAbortConfirmation(!abortConfirmation)
}

const closeForceAbortModal = (): void => {
setAbortError({
status: false,
message: '',
})
}

return (
<>
<div className="flex dc__gap-8 left pt-12">
Expand Down
12 changes: 5 additions & 7 deletions src/Shared/Components/ConfirmationModal/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Button, ButtonStyleType, ButtonVariantType } from '../Button'
import './confirmationModal.scss'
import { Backdrop } from '../Backdrop'

let timeoutId: number

const ConfirmationModal = ({
title,
subtitle,
Expand Down Expand Up @@ -53,14 +55,15 @@ const ConfirmationModal = ({
useEffect(() => {
if (showConfirmationModal) {
// Timeout so that if modal is opened on enter press, it does not trigger onClick
setTimeout(() => {
timeoutId = setTimeout(() => {
registerShortcut({ keys: ['Enter'], callback: handleTriggerPrimaryActionButton })
}, 100)
}

return () => {
if (showConfirmationModal) {
unregisterShortcut(['Enter'])
clearTimeout(timeoutId)
}
}
}, [showConfirmationModal, primaryButtonConfig, disablePrimaryButton])
Expand All @@ -81,12 +84,7 @@ const ConfirmationModal = ({
>
<div className="flexbox-col dc__gap-12 p-20">
<RenderIcon className="icon-dim-48 dc__no-shrink" />

{typeof title === 'string' ? (
<span className="cn-9 fs-16 fw-6 lh-24 dc__word-break">{title}</span>
) : (
title
)}
<span className="cn-9 fs-16 fw-6 lh-24 dc__word-break">{title}</span>

{typeof subtitle === 'string' ? (
<span className="cn-8 fs-13 fw-4 lh-20 dc__word-break">{subtitle}</span>
Expand Down
10 changes: 4 additions & 6 deletions src/Shared/Components/ConfirmationModal/types.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FunctionComponent, ReactNode, SVGProps } from 'react'
import { FunctionComponent, ReactNode, SVGProps, SyntheticEvent } from 'react'
import { ButtonProps } from '../Button'

export enum ConfirmationModalVariantType {
Expand All @@ -9,7 +9,7 @@ export enum ConfirmationModalVariantType {
}

interface CommonButtonProps extends Pick<ButtonProps, 'text'>, Partial<Pick<ButtonProps, 'startIcon' | 'endIcon'>> {
onClick: (e?: any) => void
onClick: (e?: SyntheticEvent) => void
}

interface CustomInputConfig {
Expand Down Expand Up @@ -46,9 +46,9 @@ type CustomInputConfigOrChildrenType =
}

export type ConfirmationModalProps = {
title: ReactNode
title: string
subtitle: ReactNode
handleClose: (e?: any) => void
handleClose: (e?: SyntheticEvent) => void
showConfirmationModal: boolean
} & (
| {
Expand All @@ -59,8 +59,6 @@ export type ConfirmationModalProps = {
| {
variant: ConfirmationModalVariantType.custom
Icon: FunctionComponent<SVGProps<SVGSVGElement>>
customInputConfig?: never
children?: ReactNode
buttonConfig: ButtonConfig<
Pick<ButtonProps, 'isLoading' | 'disabled' | 'style'>,
Pick<ButtonProps, 'disabled' | 'style'>
Expand Down
3 changes: 3 additions & 0 deletions src/Shared/Helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export const preventBodyScroll = (lock: boolean): void => {

export const preventOutsideFocus = ({ identifier, preventFocus }: PreventOutsideFocusProps) => {
const identifierElement = document.getElementById(identifier)
if (!identifierElement) {
return
}
if (preventFocus) {
identifierElement.setAttribute('inert', 'true')
} else {
Expand Down

0 comments on commit 86d0b81

Please sign in to comment.