|
1 | 1 | import React, { useMemo } from 'react'; |
2 | | - |
3 | 2 | import { Space } from 'antd'; |
4 | 3 | import { |
5 | 4 | CheckCircleFilled, |
6 | 5 | WarningFilled, |
7 | 6 | InfoHexagonFilled, |
8 | 7 | CloseCircleFilled |
9 | 8 | } from '@actiontech/icons'; |
| 9 | +import { useTranslation } from 'react-i18next'; |
| 10 | +import { ResultIconRenderProps } from './index.type'; |
| 11 | + |
| 12 | +const IconLevelDictionary = { |
| 13 | + normal: <CheckCircleFilled width={20} height={20} />, |
| 14 | + notice: <InfoHexagonFilled width={20} height={20} />, |
| 15 | + warn: <WarningFilled width={20} height={20} />, |
| 16 | + error: <CloseCircleFilled width={20} height={20} /> |
| 17 | +}; |
10 | 18 |
|
| 19 | +/** @deprecated use ResultIconRenderProps instead */ |
11 | 20 | export type IResultIconRender = { |
12 | 21 | iconLevels: string[]; |
13 | 22 | }; |
14 | 23 |
|
15 | | -const ResultIconRender = (props: IResultIconRender) => { |
16 | | - const { iconLevels } = props; |
| 24 | +const ResultIconRender = (props: ResultIconRenderProps) => { |
| 25 | + const { auditResultInfo, iconLevels } = props; |
| 26 | + const { t } = useTranslation(); |
17 | 27 |
|
18 | | - const iconData = useMemo(() => { |
19 | | - return Array.from(new Set(iconLevels.filter((icon: string) => icon))); |
| 28 | + const legacyIconData = useMemo(() => { |
| 29 | + return Array.from( |
| 30 | + new Set((iconLevels ?? []).filter((icon: string) => icon)) |
| 31 | + ); |
20 | 32 | }, [iconLevels]); |
21 | 33 |
|
22 | | - const renderIcon = useMemo(() => { |
23 | | - return { |
24 | | - normal: <CheckCircleFilled width={20} height={20} />, |
25 | | - notice: <InfoHexagonFilled width={20} height={20} />, |
26 | | - warn: <WarningFilled width={20} height={20} />, |
27 | | - error: <CloseCircleFilled width={20} height={20} /> |
28 | | - }; |
29 | | - }, []); |
| 34 | + const auditResultIconData = useMemo(() => { |
| 35 | + return Array.from( |
| 36 | + new Set(auditResultInfo?.map((v) => v.level)?.filter(Boolean)) |
| 37 | + ); |
| 38 | + }, [auditResultInfo]); |
| 39 | + |
| 40 | + if (auditResultInfo) { |
| 41 | + if (auditResultInfo.some((item) => item.executionFailed)) { |
| 42 | + return ( |
| 43 | + <Space> |
| 44 | + <WarningFilled width={20} height={20} /> |
| 45 | + <span>{t('components.auditResultMessage.hasException')}</span> |
| 46 | + </Space> |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + return ( |
| 51 | + <Space size={8}> |
| 52 | + {auditResultIconData.length |
| 53 | + ? auditResultIconData.map((icon) => ( |
| 54 | + <React.Fragment key={icon}> |
| 55 | + {IconLevelDictionary[ |
| 56 | + icon as keyof typeof IconLevelDictionary |
| 57 | + ] ?? null} |
| 58 | + </React.Fragment> |
| 59 | + )) |
| 60 | + : IconLevelDictionary.normal} |
| 61 | + </Space> |
| 62 | + ); |
| 63 | + } |
30 | 64 |
|
31 | 65 | return ( |
32 | 66 | <Space size={8}> |
33 | | - {iconData.map((icon) => { |
34 | | - return ( |
35 | | - <React.Fragment key={icon}> |
36 | | - {renderIcon[icon as keyof typeof renderIcon] ?? null} |
37 | | - </React.Fragment> |
38 | | - ); |
39 | | - })} |
| 67 | + {legacyIconData.map((icon) => ( |
| 68 | + <React.Fragment key={icon}> |
| 69 | + {IconLevelDictionary[icon as keyof typeof IconLevelDictionary] ?? |
| 70 | + null} |
| 71 | + </React.Fragment> |
| 72 | + ))} |
40 | 73 | </Space> |
41 | 74 | ); |
42 | 75 | }; |
|
0 commit comments