Skip to content

Commit e1dc7fd

Browse files
committed
PM-2135 - fallback for ai model icon
1 parent 6251eae commit e1dc7fd

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { FC, useCallback, useRef } from 'react'
2+
3+
import iconDeepseekAi from '~/apps/review/src/lib/assets/icons/deepseek.svg'
4+
5+
import { AiWorkflow } from '../../../lib/hooks'
6+
7+
interface AiModelIconProps {
8+
model: AiWorkflow['llm']
9+
}
10+
11+
const AiModelIcon: FC<AiModelIconProps> = props => {
12+
const llmIconImgRef = useRef<HTMLImageElement>(null)
13+
14+
const handleError = useCallback(() => {
15+
if (!llmIconImgRef.current) {
16+
return
17+
}
18+
19+
llmIconImgRef.current.src = iconDeepseekAi
20+
}, [])
21+
22+
return (
23+
<img src={props.model.icon} alt={props.model.name} onError={handleError} ref={llmIconImgRef} />
24+
)
25+
}
26+
27+
export default AiModelIcon

src/apps/review/src/pages/ai-scorecards/components/AiModelModal/AiModelModal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { BaseModal } from '~/libs/ui'
44
import { AiWorkflow } from '~/apps/review/src/lib/hooks'
55
import { IconExternalLink } from '~/apps/review/src/lib/assets/icons'
66

7+
import AiModelIcon from '../AiModelIcon'
8+
79
import styles from './AiModelModal.module.scss'
810

911
interface AiModelModalProps {
@@ -22,11 +24,11 @@ const AiModelModal: FC<AiModelModalProps> = props => (
2224
<div className={styles.wrap}>
2325
<div className={styles.modelNameWrap}>
2426
<div className={styles.modelIcon}>
25-
<img src={props.model.icon} alt={props.model.name} />
27+
<AiModelIcon model={props.model} />
2628
</div>
2729
<div className={styles.modelName}>
2830
<h3>{props.model.name}</h3>
29-
<a href={props.model.url} target='_blank' rel='noreferrer'>
31+
<a href={props.model.url} target='_blank' rel='noreferrer noopener'>
3032
<IconExternalLink />
3133
</a>
3234
</div>

src/apps/review/src/pages/ai-scorecards/components/ScorecardHeader/ScorecardHeader.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import moment, { Duration } from 'moment'
44
import { AiScorecardContextModel } from '~/apps/review/src/lib/models'
55

66
import { useAiScorecardContext } from '../../AiScorecardContext'
7-
import { IconClock, IconDeepseekAi, IconPremium } from '../../../../lib/assets/icons'
7+
import { IconClock, IconPremium } from '../../../../lib/assets/icons'
88
import { AiModelModal } from '../AiModelModal'
9+
import AiModelIcon from '../AiModelIcon'
910

1011
import styles from './ScorecardHeader.module.scss'
1112

@@ -19,7 +20,7 @@ const formatDuration = (duration: Duration): string => [
1920
const ScorecardHeader: FC = () => {
2021
const { workflow, workflowRun }: AiScorecardContextModel = useAiScorecardContext()
2122
const runDuration = useMemo(() => (
22-
workflowRun && moment.duration(
23+
workflowRun && workflowRun.completedAt && workflowRun.startedAt && moment.duration(
2324
+new Date(workflowRun.completedAt) - +new Date(workflowRun.startedAt),
2425
'milliseconds',
2526
)
@@ -38,7 +39,9 @@ const ScorecardHeader: FC = () => {
3839
<div className={styles.wrap}>
3940
<div className={styles.headerWrap}>
4041
<div className={styles.workflowInfo}>
41-
<IconDeepseekAi className={styles.workflowIcon} />
42+
<div className={styles.workflowIcon}>
43+
<AiModelIcon model={workflow.llm} />
44+
</div>
4245
<div className={styles.workflowName}>
4346
<h3>{workflow.name}</h3>
4447
<span className={styles.modelName} onClick={toggleModelDetails}>{workflow.llm.name}</span>

0 commit comments

Comments
 (0)