Skip to content

Commit 76e5cb9

Browse files
committed
feat: use use download hook globally
1 parent c0fb5b4 commit 76e5cb9

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

src/Shared/Components/CICDHistory/Artifacts.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import { useEffect, useState } from 'react'
1818
import { useParams } from 'react-router'
19+
import { useDownload } from '@Shared/Hooks'
1920
import {
20-
showError,
2121
GenericEmptyState,
2222
ImageTagsContainer,
2323
ClipboardButton,
@@ -122,7 +122,7 @@ const Artifacts = ({
122122
artifact,
123123
blobStorageEnabled,
124124
isArtifactUploaded,
125-
getArtifactPromise,
125+
downloadArtifactUrl,
126126
ciPipelineId,
127127
artifactId,
128128
isJobView,
@@ -137,6 +137,7 @@ const Artifacts = ({
137137
renderCIListHeader,
138138
}: ArtifactType) => {
139139
const { isSuperAdmin } = useSuperAdmin()
140+
const { handleDownload } = useDownload()
140141

141142
const { triggerId, buildId } = useParams<{
142143
triggerId: string
@@ -152,17 +153,11 @@ const Artifacts = ({
152153
}, [copied])
153154

154155
async function handleArtifact() {
155-
// TODO: Use useDownload() Hook instead to download file/folder
156-
try {
157-
const response = await getArtifactPromise()
158-
const b = await (response as any).blob()
159-
const a = document.createElement('a')
160-
a.href = URL.createObjectURL(b)
161-
a.download = `${buildId || triggerId}.zip`
162-
a.click()
163-
} catch (err) {
164-
showError(err)
165-
}
156+
await handleDownload({
157+
downloadUrl: downloadArtifactUrl,
158+
showFilePreparingToast: true,
159+
fileName: `${buildId || triggerId}.zip`,
160+
})
166161
}
167162

168163
if (status.toLowerCase() === TERMINAL_STATUS_MAP.RUNNING || status.toLowerCase() === TERMINAL_STATUS_MAP.STARTING) {
@@ -260,7 +255,7 @@ const Artifacts = ({
260255
</div>
261256
</CIListItem>
262257
)}
263-
{blobStorageEnabled && getArtifactPromise && (type === HistoryComponentType.CD || isArtifactUploaded) && (
258+
{blobStorageEnabled && downloadArtifactUrl && (type === HistoryComponentType.CD || isArtifactUploaded) && (
264259
<CIListItem
265260
type="report"
266261
hideImageTaggingHardDelete={hideImageTaggingHardDelete}

src/Shared/Components/CICDHistory/TriggerOutput.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import {
6363
VirtualHistoryArtifactProps,
6464
RunSourceType,
6565
} from './types'
66-
import { getTagDetails, getTriggerDetails, cancelCiTrigger, cancelPrePostCdTrigger, getCDBuildReport } from './service'
66+
import { getTagDetails, getTriggerDetails, cancelCiTrigger, cancelPrePostCdTrigger } from './service'
6767
import { DEFAULT_ENV, TIMEOUT_VALUE, WORKER_POD_BASE_URL } from './constants'
6868
import { GitTriggers } from '../../types'
6969
import warn from '../../../Assets/Icon/ic-warning.svg'
@@ -561,6 +561,8 @@ const HistoryLogs: React.FC<{
561561
workflowId: triggerDetails.id,
562562
}
563563

564+
const CDBuildReportUrl = `app/cd-pipeline/workflow/download/${appId}/${envId}/${pipelineId}/${triggerId}`
565+
564566
const [ref, scrollToTop, scrollToBottom] = useScrollable({
565567
autoBottomScroll: triggerDetails.status.toLowerCase() !== 'succeeded',
566568
})
@@ -665,7 +667,7 @@ const HistoryLogs: React.FC<{
665667
tagsEditable={tagsEditable}
666668
appReleaseTagNames={appReleaseTags}
667669
hideImageTaggingHardDelete={hideImageTaggingHardDelete}
668-
getArtifactPromise={() => getCDBuildReport(appId, envId, pipelineId, triggerId)}
670+
downloadArtifactUrl={CDBuildReportUrl}
669671
type={HistoryComponentType.CD}
670672
renderCIListHeader={renderCIListHeader}
671673
/>

src/Shared/Components/CICDHistory/service.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,6 @@ export const getDeploymentDiffSelector = (
268268
return get(url)
269269
}
270270

271-
export function getCDBuildReport(appId, envId, pipelineId, workflowId) {
272-
return get(`app/cd-pipeline/workflow/download/${appId}/${envId}/${pipelineId}/${workflowId}`)
273-
}
274-
275271
export const getTriggerHistory = async ({
276272
appId,
277273
envId,

src/Shared/Components/CICDHistory/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ export interface ArtifactType {
551551
artifact: string
552552
blobStorageEnabled: boolean
553553
isArtifactUploaded?: boolean
554-
getArtifactPromise?: () => Promise<any>
554+
downloadArtifactUrl?: string
555555
isJobView?: boolean
556556
isJobCI?: boolean
557557
type: HistoryComponentType

0 commit comments

Comments
 (0)