Skip to content

Commit 59b1ba8

Browse files
authored
✨ 上线体验增强分析模块公告 (#564)
* ✨ 增加体验增强分析模块公告 * 🎨 issue详情兼容长文本,避免渲染问题
1 parent 6c77fc0 commit 59b1ba8

10 files changed

Lines changed: 204 additions & 7 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as useNotification } from './useNotification';
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React, { useEffect } from 'react';
2+
import Moment from 'moment';
3+
import { notification, Button, Space } from 'coding-oa-uikit';
4+
import { ArgsProps } from 'coding-oa-uikit/lib/notification';
5+
6+
/** 通知存储数据结构 */
7+
interface NotifyStorageData {
8+
/** 不再提醒 */
9+
neverRemind: boolean;
10+
/** 过期时间 */
11+
expireTimestamp?: number;
12+
}
13+
14+
/** 获取在LocalStorage的通知数据 */
15+
const getNotificationDataByLocalStorage = (key: string) => {
16+
const keyValue = localStorage.getItem(key);
17+
if (keyValue) {
18+
try {
19+
const keyObj: NotifyStorageData = JSON.parse(keyValue);
20+
return keyObj;
21+
} catch (error) {
22+
// 解析失败
23+
}
24+
}
25+
return null;
26+
};
27+
28+
/** 设置通知数据到LocalStorage */
29+
const setNotificationDataToLocalStorage = (key: string, notifyStorageData: NotifyStorageData) => {
30+
localStorage.setItem(key, JSON.stringify(notifyStorageData));
31+
};
32+
33+
/** 通知入参数数据结构 */
34+
interface NotificationProps {
35+
/** 唯一标识 */
36+
key: string,
37+
/** 通知类型 */
38+
type: 'info' | 'success' | 'error' | 'warning',
39+
/** 是否开启过期操作 */
40+
useExpireOper?: boolean;
41+
/** 通知其他参数 */
42+
notifyArgs: Omit<ArgsProps, 'key'>
43+
}
44+
45+
/** 通知hooks */
46+
const useNotification = ({ key, type, useExpireOper = false, notifyArgs }: NotificationProps) => {
47+
const { btn, ...rest } = notifyArgs;
48+
49+
useEffect(() => {
50+
if (useExpireOper) {
51+
const notifyStorageData = getNotificationDataByLocalStorage(key);
52+
if (notifyStorageData?.neverRemind
53+
|| (notifyStorageData?.expireTimestamp && Moment().valueOf() < notifyStorageData.expireTimestamp)
54+
) {
55+
return;
56+
}
57+
}
58+
59+
notification[type]({
60+
duration: null,
61+
btn: useExpireOper ? <Space>
62+
<Button type="primary" size="small" onClick={() => {
63+
// 明日凌点时间戳
64+
const timestamp = Moment().startOf('day')
65+
.add(1, 'day')
66+
.valueOf();
67+
const notifyStorageData: NotifyStorageData = {
68+
neverRemind: false,
69+
expireTimestamp: timestamp,
70+
};
71+
setNotificationDataToLocalStorage(key, notifyStorageData);
72+
notification.close(key);
73+
}}>
74+
今日不再提醒
75+
</Button>
76+
<Button type="secondary" size="small" onClick={() => {
77+
const notifyStorageData: NotifyStorageData = { neverRemind: true };
78+
setNotificationDataToLocalStorage(key, notifyStorageData);
79+
notification.close(key);
80+
}}>
81+
不再提醒
82+
</Button>
83+
</Space> : btn,
84+
...rest,
85+
key,
86+
});
87+
}, []);
88+
};
89+
90+
export default useNotification;

web/packages/tca-analysis/src/modules/projects/issues/issue-detail-modal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import { getRuleDetail } from '@src/services/schemes';
2626
import { Operation } from './issue-popover';
2727
import style from './style.scss';
2828

29+
/** 定义每行显示最长长度,避免渲染问题 */
30+
const CODE_MAX_CHAR_LENGTH = 1000
31+
2932
interface IssueModalProps {
3033
curSchemeId: number;
3134
params: any;
@@ -101,7 +104,7 @@ const IssueModal = (props: IssueModalProps) => {
101104
};
102105

103106
const rowRenderer = ({ index, style: rowStyle }: any) => {
104-
const { lineNum: line, content } = codeFile?.codeContents[index] || {};
107+
const { lineNum: line, content = '' } = codeFile?.codeContents[index] || {};
105108
const rowRef: any = useRef({});
106109
const language = detail.language ?? codeFile.suffix?.split('.')[1] ?? 'plaintext';
107110

@@ -145,7 +148,7 @@ const IssueModal = (props: IssueModalProps) => {
145148
)
146149
}
147150
<Highlight className={language}>
148-
{content}
151+
{content.length > CODE_MAX_CHAR_LENGTH ? `${content.substring(0, CODE_MAX_CHAR_LENGTH)}...` : content}
149152
</Highlight>
150153
</div>
151154
</div>

web/packages/tca-analysis/src/modules/projects/overview/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ export const getCyCLineChartData = (scans: any, standard: string) => {
222222
: scan.default_summary;
223223
if (summary) {
224224
const date = formatChartDate(scan.scan_time);
225-
console.log(scan.scan_time)
226225

227226
rowsTotal.push({
228227
date,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as useNotification } from './useNotification';
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React, { useEffect } from 'react';
2+
import Moment from 'moment';
3+
import { notification, Button, Space } from 'coding-oa-uikit';
4+
import { ArgsProps } from 'coding-oa-uikit/lib/notification';
5+
6+
/** 通知存储数据结构 */
7+
interface NotifyStorageData {
8+
/** 不再提醒 */
9+
neverRemind: boolean;
10+
/** 过期时间 */
11+
expireTimestamp?: number;
12+
}
13+
14+
/** 获取在LocalStorage的通知数据 */
15+
const getNotificationDataByLocalStorage = (key: string) => {
16+
const keyValue = localStorage.getItem(key);
17+
if (keyValue) {
18+
try {
19+
const keyObj: NotifyStorageData = JSON.parse(keyValue);
20+
return keyObj;
21+
} catch (error) {
22+
// 解析失败
23+
}
24+
}
25+
return null;
26+
};
27+
28+
/** 设置通知数据到LocalStorage */
29+
const setNotificationDataToLocalStorage = (key: string, notifyStorageData: NotifyStorageData) => {
30+
localStorage.setItem(key, JSON.stringify(notifyStorageData));
31+
};
32+
33+
/** 通知入参数数据结构 */
34+
interface NotificationProps {
35+
/** 唯一标识 */
36+
key: string,
37+
/** 通知类型 */
38+
type: 'info' | 'success' | 'error' | 'warning',
39+
/** 是否开启过期操作 */
40+
useExpireOper?: boolean;
41+
/** 通知其他参数 */
42+
notifyArgs: Omit<ArgsProps, 'key'>
43+
}
44+
45+
/** 通知hooks */
46+
const useNotification = ({ key, type, useExpireOper = false, notifyArgs }: NotificationProps) => {
47+
const { btn, ...rest } = notifyArgs;
48+
49+
useEffect(() => {
50+
if (useExpireOper) {
51+
const notifyStorageData = getNotificationDataByLocalStorage(key);
52+
if (notifyStorageData?.neverRemind
53+
|| (notifyStorageData?.expireTimestamp && Moment().valueOf() < notifyStorageData.expireTimestamp)
54+
) {
55+
return;
56+
}
57+
}
58+
59+
notification[type]({
60+
duration: null,
61+
btn: useExpireOper ? <Space>
62+
<Button type="primary" size="small" onClick={() => {
63+
// 明日凌点时间戳
64+
const timestamp = Moment().startOf('day')
65+
.add(1, 'day')
66+
.valueOf();
67+
const notifyStorageData: NotifyStorageData = {
68+
neverRemind: false,
69+
expireTimestamp: timestamp,
70+
};
71+
setNotificationDataToLocalStorage(key, notifyStorageData);
72+
notification.close(key);
73+
}}>
74+
今日不再提醒
75+
</Button>
76+
<Button type="secondary" size="small" onClick={() => {
77+
const notifyStorageData: NotifyStorageData = { neverRemind: true };
78+
setNotificationDataToLocalStorage(key, notifyStorageData);
79+
notification.close(key);
80+
}}>
81+
不再提醒
82+
</Button>
83+
</Space> : btn,
84+
...rest,
85+
key,
86+
});
87+
}, []);
88+
};
89+
90+
export default useNotification;

web/packages/tca-layout/src/load-init-service.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { SET_USERINFO } from '@src/context/constant';
1515
import Constant from '@src/reducer/constant';
1616
import { gUserInfo } from '@src/services/user';
1717
import { setLayoutCompletedClass, info } from '@src/utils';
18+
import { useNotification } from '@src/components/notification'
1819

1920
/**
2021
* 初始化页面时的一些请求
@@ -24,6 +25,18 @@ const LoadInitService: FC = ({ children }: any) => {
2425
const dispatch = useDispatchStore();
2526
const storeDispatch = useDispatch();
2627

28+
useNotification({
29+
key: 'notify-license-trial',
30+
type: 'info',
31+
useExpireOper: true,
32+
notifyArgs: {
33+
message: '免费体验增强分析模块',
34+
description: <>
35+
TCA为开源社区免费提供更多功能精度更高的增强分析模块,欢迎免费申请License体验。详情请参考<a className='text-weight-medium' href="https://tencent.github.io/CodeAnalysis/zh/quickStarted/enhanceDeploy.html" target='_blank' rel="noreferrer" >增强分析模块文档</a>
36+
</>
37+
}
38+
})
39+
2740
useEffect(() => {
2841
storeDispatch({
2942
type: Constant.SET_LAYOUT_COMPLETED,
17 Bytes
Binary file not shown.
680 Bytes
Binary file not shown.

web/tca-deploy-source/conf/configs.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
{
33
"name": "tca-layout",
44
"description": "tca layout微前端",
5-
"commitId": "74b8d27f11cd06c37e3381dcc9ca5ac53ef755fd",
5+
"commitId": "5816721ba7b4f280f7aa5a150353c8c8a0e3b270",
66
"match": "/",
77
"js": [
88
"/static/tca-layout/runtime~tca-layout-283c04f5.js",
99
"/static/tca-layout/vendors~tca-layout-a5cfaa26.js",
10-
"/static/tca-layout/tca-layout-807a9152.js"
10+
"/static/tca-layout/tca-layout-c70c5807.js"
1111
],
1212
"css": [
1313
"/static/tca-layout/vendors~tca-layout-9b6df0cb.css",
@@ -40,12 +40,12 @@
4040
{
4141
"name": "tca-analysis",
4242
"description": "TCA Analysis 微前端",
43-
"commitId": "9be160bacbfdee93404fd95d580c5068a41eaf27",
43+
"commitId": "5816721ba7b4f280f7aa5a150353c8c8a0e3b270",
4444
"match": "^/t/[^/]+/p/[^/]+/(code-analysis|repos|template|profile|group)",
4545
"js": [
4646
"/static/tca-analysis/runtime~tca-analysis-749a7dad.js",
4747
"/static/tca-analysis/vendors~tca-analysis-7f52f6b6.js",
48-
"/static/tca-analysis/tca-analysis-16575169.js"
48+
"/static/tca-analysis/tca-analysis-79d5562b.js"
4949
],
5050
"css": [
5151
"/static/tca-analysis/vendors~tca-analysis-9b6df0cb.css",

0 commit comments

Comments
 (0)