Skip to content

Commit 9b29f7d

Browse files
committed
PM-2179 update logic
1 parent 2d9be6f commit 9b29f7d

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

src/apps/review/src/lib/components/Scorecard/ScorecardAttachments/ScorecardAttachments.module.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,19 @@
2525

2626
.expired {
2727
cursor: not-allowed;
28-
opacity: 0.4;
2928
color: #999;
3029

3130
&:hover {
3231
text-decoration: none;
3332
}
33+
}
34+
35+
.artifactType {
36+
display: flex;
37+
gap: 5px;
38+
align-items: center;
39+
40+
.artifactIcon {
41+
stroke: #00797A;
42+
}
3443
}

src/apps/review/src/lib/components/Scorecard/ScorecardAttachments/ScorecardAttachments.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ const ScorecardAttachments: FC<ScorecardAttachmentsProps> = (props: ScorecardAtt
4545
[handleDownload],
4646
)
4747

48-
console.log('attachments', artifacts)
49-
5048
const columns = useMemo<TableColumn<AiWorkflowRunArtifact>[]>(
5149
() => [
5250
{
@@ -68,7 +66,7 @@ const ScorecardAttachments: FC<ScorecardAttachmentsProps> = (props: ScorecardAtt
6866
onClick={!isExpired ? createDownloadHandler(attachment.id) : undefined}
6967
>
7068
<span>{attachment.name}</span>
71-
{isExpired && <span>Expired</span>}
69+
{isExpired && <span>(Link Expired)</span>}
7270
</div>
7371
)
7472
},
@@ -79,7 +77,7 @@ const ScorecardAttachments: FC<ScorecardAttachmentsProps> = (props: ScorecardAtt
7977
label: 'Type',
8078
renderer: () => (
8179
<div className={styles.artifactType}>
82-
<IconOutline.CubeIcon />
80+
<IconOutline.CubeIcon className={styles.artifactIcon} width={26} />
8381
<span>Artifact</span>
8482
</div>
8583
),

src/apps/review/src/lib/hooks/useFetchAiWorkflowRuns.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'
22
import useSWR, { SWRResponse } from 'swr'
33

44
import { EnvironmentConfig } from '~/config'
5-
import { xhrGetAsync } from '~/libs/core'
5+
import { xhrGetAsync, xhrGetBlobAsync } from '~/libs/core'
66
import { handleError } from '~/libs/shared/lib/utils/handle-error'
77

88
import { AiFeedbackItem, Scorecard } from '../models'
@@ -216,26 +216,22 @@ export function useDownloadAiWorkflowsRunArtifact(
216216

217217
const url = `${TC_API_BASE_URL}/workflows/${workflowId}/runs/${runId}/attachments/${artifactId}/zip`
218218

219-
const response = await fetch(url, {
220-
credentials: 'include',
221-
method: 'GET',
222-
})
223-
224-
if (!response.ok) {
225-
throw new Error(`Download failed with status ${response.status}`)
226-
}
227-
228-
const blob = await response.blob()
229-
230-
// Create a blob URL and trigger browser download
231-
const objectUrl = window.URL.createObjectURL(blob)
232-
const link = document.createElement('a')
233-
link.href = objectUrl
234-
link.download = `artifact-${artifactId}.zip`
235-
link.click()
236-
237-
// Cleanup
238-
window.URL.revokeObjectURL(objectUrl)
219+
xhrGetBlobAsync<Blob>(url)
220+
.then(blob => {
221+
const objectUrl = window.URL.createObjectURL(blob)
222+
const link = document.createElement('a')
223+
link.href = objectUrl
224+
link.download = `artifact-${artifactId}.zip`
225+
226+
document.body.appendChild(link)
227+
link.click()
228+
link.remove()
229+
230+
window.URL.revokeObjectURL(objectUrl)
231+
})
232+
.catch(err => {
233+
handleError(err as Error)
234+
})
239235
} catch (err) {
240236
handleError(err as Error)
241237
} finally {

0 commit comments

Comments
 (0)