文件分析优化
This commit is contained in:
parent
24110f17f6
commit
d331991f5d
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useEffect } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import "./index.scss";
|
||||
import Loadable from 'react-loadable';
|
||||
|
|
@ -37,6 +37,7 @@ const QualityDetail = Loadable({
|
|||
function ServerIndex(props){
|
||||
const { projectDetail } = props;
|
||||
const { owner , projectsId } = props.match.params;
|
||||
const [ qualityClass, setQualityClass ] = useState(false)
|
||||
|
||||
useEffect(()=>{
|
||||
// 非项目协作者不可进入服务tab (3397)
|
||||
|
|
@ -45,8 +46,12 @@ function ServerIndex(props){
|
|||
}
|
||||
}, [projectDetail])
|
||||
|
||||
const changeClass = (isServer = false ) => {
|
||||
setQualityClass(isServer);
|
||||
}
|
||||
|
||||
return(
|
||||
<div className="panels">
|
||||
<div className={`panels ${ qualityClass && 'panels-quality' }`}>
|
||||
<Switch {...props}>
|
||||
<Route path="/:owner/:projectsId/service/reposyncer"
|
||||
render={
|
||||
|
|
@ -60,12 +65,12 @@ function ServerIndex(props){
|
|||
></Route>
|
||||
<Route path="/:owner/:projectsId/service/quality/detail"
|
||||
render={
|
||||
() => (<QualityDetail {...props}/>)
|
||||
() => (<QualityDetail {...props} changeClass={ changeClass } />)
|
||||
}
|
||||
></Route>
|
||||
<Route path="/:owner/:projectsId/service/quality"
|
||||
render={
|
||||
() => (<Quality {...props}/>)
|
||||
() => (<Quality {...props} changeClass={ changeClass }/>)
|
||||
}
|
||||
></Route>
|
||||
{/* 个人建站服务 */}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export const maintainability = {
|
|||
LOW: '次要',
|
||||
MEDIUM: '主要',
|
||||
HIGH: '严重',
|
||||
Blocked: '阻塞'
|
||||
BLOCKED: '阻塞'
|
||||
}
|
||||
|
||||
export const issueTypeIcon = {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,15 @@
|
|||
width: 1200px;
|
||||
margin:20px auto;
|
||||
}
|
||||
.panels-quality {
|
||||
background:#f3f5f9;
|
||||
background-image: url("./img/quality/page-bg.png");
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100%;
|
||||
box-sizing: content-box;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
.btnhover{
|
||||
background-color: #466aff;
|
||||
color: #fff!important;
|
||||
|
|
|
|||
|
|
@ -8,15 +8,6 @@
|
|||
background: #FFFFFF;
|
||||
}
|
||||
}
|
||||
.panels {
|
||||
background:#f3f5f9;
|
||||
background-image: url("../img/quality/page-bg.png");
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100%;
|
||||
box-sizing: content-box;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.bug-details {
|
||||
max-height: 90vh;
|
||||
|
|
|
|||
|
|
@ -50,19 +50,12 @@ function IssueList(props) {
|
|||
const [tagShowMoreDelay, setTagShowMoreDelay] = useState(false);
|
||||
const [codeSelected, setCodeSelected] = useState(false);
|
||||
const [url, setUrl] = useState(null);
|
||||
const { projectDetail, history } = props;
|
||||
const { projectDetail, history, changeClass } = props;
|
||||
const metricKeys = 'lines,coverage,lines_to_cover,duplicated_lines_density,maintainability_issues,vulnerabilities,bugs,code_smells';
|
||||
const facets = 'impactSeverities,tags,types';
|
||||
const { owner , projectsId } = props.match.params;
|
||||
const iframeRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
let newContainer = document.getElementsByClassName("newContainer")[0];
|
||||
newContainer.style.backgroundColor = '#F7F9FCFF';
|
||||
return () => {
|
||||
newContainer.style.backgroundColor = '#FFFFFF';
|
||||
};
|
||||
}, []);
|
||||
const timeRef = useRef();
|
||||
|
||||
useEffect(() => {
|
||||
if (projectDetail) {
|
||||
|
|
@ -73,25 +66,16 @@ function IssueList(props) {
|
|||
return
|
||||
}
|
||||
setPageLoading(true)
|
||||
getActionList(owner, projectsId).then(res => {
|
||||
setPageLoading(false)
|
||||
if (res.status !== 0) {
|
||||
if (res.runs.length === 0) {
|
||||
setAnalysisStatus(actionStatus.none)
|
||||
} else {
|
||||
setAnalysisStatus(res.runs[0].status)
|
||||
if (res.runs[0].status) {
|
||||
getData()
|
||||
getIssueList()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
message.error(res.message)
|
||||
}
|
||||
})
|
||||
getAction()
|
||||
}
|
||||
}, [projectDetail]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
clearTimer()
|
||||
}
|
||||
},[])
|
||||
|
||||
useEffect(() => {
|
||||
const iframe = iframeRef.current;
|
||||
if (!iframe || !url) return; // 确保 iframe 和 url 已存在
|
||||
|
|
@ -107,6 +91,7 @@ function IssueList(props) {
|
|||
iframe.style.height = contentHeight + 'px';
|
||||
}
|
||||
} catch (e) {
|
||||
iframe.style.height = '770px';
|
||||
// 如果实际上是跨域的,这里很可能会触发错误
|
||||
console.error("调整同源 iframe 大小出错 (或者它实际是跨域的):", e);
|
||||
}
|
||||
|
|
@ -120,6 +105,41 @@ function IssueList(props) {
|
|||
};
|
||||
}, [url]); // 如果 URL 改变,重新绑定监听器
|
||||
|
||||
const clearTimer = () => {
|
||||
if (timeRef.current) {
|
||||
clearTimeout(timeRef.current);
|
||||
timeRef.current = undefined; // 清空引用
|
||||
}
|
||||
}
|
||||
|
||||
const getAction = () => {
|
||||
getActionList(owner, projectsId).then(res => {
|
||||
setPageLoading(false)
|
||||
if (res.status !== 0) {
|
||||
if (res.runs.length === 0) {
|
||||
setAnalysisStatus(actionStatus.none)
|
||||
} else {
|
||||
if (res.runs[0].status === actionStatus.success) {
|
||||
changeClass(true)
|
||||
}
|
||||
if ([actionStatus.waiting, actionStatus.running].includes(res.runs[0].status)) {
|
||||
if (timeRef.current) clearTimer();
|
||||
timeRef.current = setTimeout(() => {
|
||||
getAction()
|
||||
}, 3000);
|
||||
}
|
||||
setAnalysisStatus(res.runs[0].status)
|
||||
if (res.runs[0].status) {
|
||||
getData()
|
||||
getIssueList()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
message.error(res.message)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const getData = () => {
|
||||
getProblemData(owner, projectsId, metricKeys).then(res => {
|
||||
if (res.status === 0) {
|
||||
|
|
@ -134,18 +154,21 @@ function IssueList(props) {
|
|||
}
|
||||
|
||||
const getIssueList = () => {
|
||||
const isBLOCKED = selectedSeverity.join(',') === 'BLOCKED' //手动添加阻塞,当只选BLOCKED时筛选为空
|
||||
let params = {
|
||||
facets: facets,
|
||||
types: selectedType.join(','),
|
||||
impactSeverities: selectedSeverity.join(','),
|
||||
impactSeverities: selectedSeverity.join(',').replace('BLOCKED', ''),
|
||||
tags: selectedTag.join(','),
|
||||
p: pageNum,
|
||||
ps: pageSize
|
||||
};
|
||||
setPageLoading(true)
|
||||
if (!timeRef.current) {
|
||||
setPageLoading(true)
|
||||
}
|
||||
getList(params, owner, projectsId).then(res => {
|
||||
setPageLoading(false)
|
||||
const issues = res.issues? res.issues.reduce((acc, issue) => {
|
||||
const issues = res.issues && !isBLOCKED ? res.issues.reduce((acc, issue) => {
|
||||
if (acc[issue.component]) {
|
||||
acc[issue.component].push(issue);
|
||||
} else {
|
||||
|
|
@ -155,10 +178,25 @@ function IssueList(props) {
|
|||
}, {}) : [];
|
||||
|
||||
const filter = res.facets ? res.facets.reduce((acc, facet) => {
|
||||
if (facet.property === 'impactSeverities') {
|
||||
facet.values.unshift({
|
||||
count: 0,
|
||||
val: "BLOCKED"
|
||||
})
|
||||
}
|
||||
|
||||
if (isBLOCKED && facet.property !== 'impactSeverities') {
|
||||
if (facet.property === 'tags') facet.values = []
|
||||
facet.values.map(e => {
|
||||
e.count = 0
|
||||
})
|
||||
}
|
||||
|
||||
acc[facet.property] = facet.values;
|
||||
return acc;
|
||||
}, {}) : [];
|
||||
|
||||
if (isBLOCKED) res.total = 0
|
||||
setListFilter(filter);
|
||||
setBaseInfo(res);
|
||||
setIssues(issues);
|
||||
|
|
@ -294,6 +332,10 @@ function IssueList(props) {
|
|||
if (res1.status === 0) {
|
||||
message.success('创建分析成功,请等待分析完成')
|
||||
setAnalysisStatus(actionStatus.waiting)
|
||||
if (timeRef.current) clearTimer();
|
||||
timeRef.current = setTimeout(() => {
|
||||
getAction()
|
||||
}, 3000);
|
||||
}
|
||||
setLoading(false)
|
||||
})
|
||||
|
|
@ -310,7 +352,7 @@ function IssueList(props) {
|
|||
return <Button type="primary" style={{width: '112px', height: '36px'}} onClick={openAnalysis} loading={loading}>开始体验</Button>
|
||||
case actionStatus.waiting:
|
||||
case actionStatus.running:
|
||||
return <Button type="primary" style={{height: '36px'}} disabled>代码正在分析中,请稍候</Button>
|
||||
return <Button type="primary" style={{height: '36px'}} disabled loading>代码正在分析中,请稍候</Button>
|
||||
case actionStatus.failure:
|
||||
return <div>
|
||||
<p>分析失败,请重试</p>
|
||||
|
|
|
|||
Loading…
Reference in New Issue