Skip to content

Commit

Permalink
Fix [Job Artifacts] UI crash on attempt to download artifact (#3016)
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-prokopchuk authored Jan 14, 2025
1 parent 3f9f7bf commit 1f25435
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/common/CopyToClipboard/CopyToClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ under the Apache 2.0 license is conditioned upon your compliance with
such restriction.
*/
import PropTypes from 'prop-types'
import { useMemo } from 'react'
import { useDispatch } from 'react-redux'

import { Tooltip, TextTooltipTemplate, RoundedIcon } from 'igz-controls/components'
Expand All @@ -31,10 +32,11 @@ const CopyToClipboard = ({
children = null,
className = '',
disabled = false,
textToCopy,
textToCopy = '',
tooltipText
}) => {
const dispatch = useDispatch()
const copyIsDisabled = useMemo(() => disabled || !textToCopy, [disabled, textToCopy])

const copyToClipboard = textToCopy => {
navigator.clipboard
Expand Down Expand Up @@ -63,7 +65,7 @@ const CopyToClipboard = ({
<RoundedIcon
tooltipText={tooltipText}
onClick={() => copyToClipboard(textToCopy)}
disabled={disabled}
disabled={copyIsDisabled}
>
<Copy />
</RoundedIcon>
Expand All @@ -76,7 +78,7 @@ CopyToClipboard.propTypes = {
children: PropTypes.string,
className: PropTypes.string,
disabled: PropTypes.bool,
textToCopy: PropTypes.string.isRequired,
textToCopy: PropTypes.string,
tooltipText: PropTypes.string.isRequired
}

Expand Down
35 changes: 19 additions & 16 deletions src/common/Download/Download.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Download = ({
fileName,
fileSize,
onlyIcon = false,
path,
path = '',
projectName,
user,
withoutIcon = false
Expand All @@ -47,8 +47,9 @@ const Download = ({
const downloadIsDisabled = useMemo(
() =>
disabled ||
!path ||
(artifactLimits?.max_download_size && fileSize > artifactLimits.max_download_size),
[disabled, artifactLimits.max_download_size, fileSize]
[disabled, artifactLimits.max_download_size, fileSize, path]
)
const downloadClassNames = classnames(
'download',
Expand All @@ -57,18 +58,20 @@ const Download = ({
)

const handleClick = () => {
dispatch(
setDownloadItem({
filename: fileName,
id: path + Date.now(),
path,
user: user,
artifactLimits,
fileSize,
projectName
})
)
dispatch(setShowDownloadsList(true))
if (path) {
dispatch(
setDownloadItem({
filename: fileName,
id: path + Date.now(),
path,
user: user,
artifactLimits,
fileSize,
projectName
})
)
dispatch(setShowDownloadsList(true))
}
}

return (
Expand All @@ -79,7 +82,7 @@ const Download = ({
onClick={handleClick}
>
{onlyIcon ? (
<Tooltip template={!downloadIsDisabled ? <TextTooltipTemplate text="Download" /> : null}>
<Tooltip template={<TextTooltipTemplate text="Download" />}>
<RoundedIcon disabled={downloadIsDisabled}>
<DownloadIcon />
</RoundedIcon>
Expand All @@ -100,7 +103,7 @@ Download.propTypes = {
fileName: PropTypes.string,
fileSize: PropTypes.number,
onlyIcon: PropTypes.bool,
path: PropTypes.string.isRequired,
path: PropTypes.string,
projectName: PropTypes.string.isRequired,
user: PropTypes.string,
withoutIcon: PropTypes.bool
Expand Down

0 comments on commit 1f25435

Please sign in to comment.