Skip to content

Commit e542699

Browse files
committed
[feature]: Enhance audit result handling with new status checks and UI updates
1 parent a32b599 commit e542699

12 files changed

Lines changed: 538 additions & 226 deletions

File tree

packages/sqle/src/components/AuditResultMessage/ResultIconRender.tsx

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,75 @@
11
import React, { useMemo } from 'react';
2-
32
import { Space } from 'antd';
43
import {
54
CheckCircleFilled,
65
WarningFilled,
76
InfoHexagonFilled,
87
CloseCircleFilled
98
} 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+
};
1018

19+
/** @deprecated use ResultIconRenderProps instead */
1120
export type IResultIconRender = {
1221
iconLevels: string[];
1322
};
1423

15-
const ResultIconRender = (props: IResultIconRender) => {
16-
const { iconLevels } = props;
24+
const ResultIconRender = (props: ResultIconRenderProps) => {
25+
const { auditResultInfo, iconLevels } = props;
26+
const { t } = useTranslation();
1727

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+
);
2032
}, [iconLevels]);
2133

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+
}
3064

3165
return (
3266
<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+
))}
4073
</Space>
4174
);
4275
};

packages/sqle/src/components/AuditResultMessage/index.type.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ export type AuditResultMessageProps = {
88
isRuleDeleted?: boolean;
99
auditStatus?: string;
1010
};
11+
12+
export type AuditResultInfoItem = {
13+
level: string;
14+
executionFailed: boolean;
15+
};
16+
17+
export type ResultIconRenderProps = {
18+
iconLevels?: string[];
19+
auditResultInfo?: AuditResultInfoItem[];
20+
};

packages/sqle/src/components/AuditResultMessage/style.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { styled } from '@mui/material/styles';
22

3+
import { BasicTag } from '@actiontech/shared';
34
import { AuditResultMessageProps } from './index.type';
45

6+
export const ResultIconTagStyleWrapper = styled(BasicTag)`
7+
width: fit-content;
8+
`;
9+
510
export const AuditResultMessageStyleWrapper = styled('div')`
611
display: flex;
712
align-items: center;

packages/sqle/src/locale/en-US/components.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
export default {
33
auditResultMessage: {
44
auditPassed: 'Audit passed',
5-
ruleDeleted: 'The rule has been deleted'
5+
ruleDeleted: 'The rule has been deleted',
6+
auditing: 'Auditing',
7+
hasException: 'Audit exception occurred'
68
}
79
};

packages/sqle/src/locale/en-US/managementConf.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export default {
155155
firstAppearanceTime: 'First appearance time',
156156
occurrenceCount: 'Occurrence count',
157157
status: 'Status',
158+
auditStatus: 'Audit status',
159+
auditResult: 'Audit result',
160+
auditResultTooltip: 'Shows the latest audit result',
161+
audited: 'Audited',
158162
explanation: {
159163
text: 'Explanation',
160164
operator: 'Add explanation'

packages/sqle/src/locale/zh-CN/components.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
export default {
33
auditResultMessage: {
44
auditPassed: '审核通过',
5-
ruleDeleted: '该规则已删除'
5+
ruleDeleted: '该规则已删除',
6+
auditing: '审核中',
7+
hasException: '审核存在异常'
68
}
79
};

packages/sqle/src/locale/zh-CN/managementConf.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ export default {
151151
firstAppearanceTime: '最早一次出现时间',
152152
occurrenceCount: '出现次数',
153153
status: '状态',
154+
auditStatus: '审核状态',
155+
auditResult: '审核结果',
156+
auditResultTooltip: '展示最新的审核结果',
157+
audited: '已审核',
154158
explanation: {
155159
text: '说明',
156160
operator: '添加说明'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { useTranslation } from 'react-i18next';
2+
import { ResultIconTagStyleWrapper } from '../../../../components/AuditResultMessage/style';
3+
import { AUDITED, BEING_AUDITED } from './utils';
4+
5+
type AuditStatusTagProps = {
6+
status?: string;
7+
};
8+
9+
const AuditStatusTag: React.FC<AuditStatusTagProps> = ({ status }) => {
10+
const { t } = useTranslation();
11+
12+
if (status === BEING_AUDITED) {
13+
return (
14+
<ResultIconTagStyleWrapper size="small" color="geekblue">
15+
{t('components.auditResultMessage.auditing')}
16+
</ResultIconTagStyleWrapper>
17+
);
18+
}
19+
20+
if (status === AUDITED) {
21+
return (
22+
<ResultIconTagStyleWrapper size="small" color="green">
23+
{t('managementConf.detail.scanTypeSqlCollection.column.audited')}
24+
</ResultIconTagStyleWrapper>
25+
);
26+
}
27+
28+
return <>{status || '-'}</>;
29+
};
30+
31+
export default AuditStatusTag;

0 commit comments

Comments
 (0)