Skip to content

Commit

Permalink
Fix [Models] App crash on deploy a model (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariana-furyk authored Feb 8, 2024
1 parent b7480e7 commit 4f635f3
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions src/lib/components/PopUpDialog/PopUpDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ illegal under applicable law, and the grant of the foregoing license
under the Apache 2.0 license is conditioned upon your compliance with
such restriction.
*/
import React, { useCallback, useEffect, useLayoutEffect, useRef } from 'react'
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { createPortal } from 'react-dom'
Expand All @@ -37,11 +37,13 @@ const PopUpDialog = React.forwardRef(
customPosition,
headerIsHidden,
headerText,
showPopUpDialog,
style,
tooltipText
},
ref
) => {
const [showPopUp, setShowPopUp] = useState(showPopUpDialog ?? true)
const popUpOverlayRef = useRef(null)
ref ??= popUpOverlayRef
const popUpClassNames = classnames(
Expand All @@ -50,6 +52,11 @@ const PopUpDialog = React.forwardRef(
customPosition.element && 'custom-position'
)

const handleClosePopUp = useCallback(() => {
closePopUp && closePopUp()
setShowPopUp(false)
}, [closePopUp])

const calculateCustomPopUpPosition = useCallback(() => {
if (customPosition && customPosition.element) {
const elementRect = customPosition.element.current.getBoundingClientRect()
Expand Down Expand Up @@ -91,33 +98,35 @@ const PopUpDialog = React.forwardRef(
}
})

return createPortal(
<div ref={ref} className={popUpClassNames} style={style}>
<div data-testid="pop-up-dialog" className="pop-up-dialog">
{!headerIsHidden && (
<div className="pop-up-dialog__header">
{headerText && (
<div data-testid="pop-up-dialog-header" className="pop-up-dialog__header-text">
<Tooltip template={<TextTooltipTemplate text={tooltipText || headerText} />}>
<span>{headerText}</span>
</Tooltip>
return showPopUp
? createPortal(
<div ref={ref} className={popUpClassNames} style={style}>
<div data-testid="pop-up-dialog" className="pop-up-dialog">
{!headerIsHidden && (
<div className="pop-up-dialog__header">
{headerText && (
<div data-testid="pop-up-dialog-header" className="pop-up-dialog__header-text">
<Tooltip template={<TextTooltipTemplate text={tooltipText || headerText} />}>
<span>{headerText}</span>
</Tooltip>
</div>
)}
<RoundedIcon
className="pop-up-dialog__btn_close"
onClick={handleClosePopUp}
tooltipText="Close"
data-testid="pop-up-close-btn"
>
<CloseIcon />
</RoundedIcon>
</div>
)}
<RoundedIcon
className="pop-up-dialog__btn_close"
onClick={closePopUp}
tooltipText="Close"
data-testid="pop-up-close-btn"
>
<CloseIcon />
</RoundedIcon>
{children}
</div>
)}
{children}
</div>
</div>,
document.getElementById('overlay_container')
)
</div>,
document.getElementById('overlay_container')
)
: null
}
)

Expand All @@ -127,6 +136,7 @@ PopUpDialog.defaultProps = {
customPosition: {},
headerIsHidden: false,
headerText: '',
showPopUpDialog: true,
style: {},
tooltipText: ''
}
Expand All @@ -137,6 +147,7 @@ PopUpDialog.propTypes = {
customPosition: POP_UP_CUSTOM_POSITION,
headerIsHidden: PropTypes.bool,
headerText: PropTypes.string,
showPopUpDialog: PropTypes.bool,
style: PropTypes.object,
tooltipText: PropTypes.string
}
Expand Down

0 comments on commit 4f635f3

Please sign in to comment.