Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Feb 15, 2024
1 parent cd76f0d commit 1f6448a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import { useRequest } from 'ahooks';
import axios from 'axios';
import { useEffect, useRef } from 'react';
// import { useParams } from 'react-router';
import { useParams, useSearchParams } from 'react-router-dom';
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';

// import { GetCoverageSummaryMapDocument } from '../../../../helpers/backend/gen/graphql.ts';
import { handleSelectFile } from './helper';
const Sha = () => {
const prm = useParams();
const nav = useNavigate();
const [sprm] = useSearchParams();
// 在组件中
const location = useLocation();
const currentPathname = location.pathname;

// const { data } = useQuery(GetCoverageSummaryMapDocument, {
// variables: {
// reportID: sprm.get('report_id') || '',
Expand All @@ -28,31 +33,57 @@ const Sha = () => {
sha: prm.sha || '',
mode: sprm.get('mode') || '',
},
}).then(({data}) => data);
}).then(({ data }) => data);
},
{
onSuccess(res) {
},
onSuccess() {},
},
);
const reportRef = useRef(null);
useEffect(() => {
if (reportRef.current && data) {
const report = init(reportRef.current, {
theme:localStorage.getItem('theme')||'light',
defaultPath: sprm.get('path') || '~',
theme: localStorage.getItem('theme') || 'light',
onSelectFile(path: string) {
return handleSelectFile({
filepath: path,
reportID: sprm.get('report_id') || '',
sha: prm.sha || '',
projectID: prm.id || '',
mode: sprm.get('mode') || '',
}).then(r=>{
return r
});
// console.log(path)

// 假设你想要导航到 '/path' 并且拼接参数
// const path1 = `/path`;
const params = new URLSearchParams();
if (sprm.get('report_id')) {
params.append('report_id', sprm.get('report_id') || '');
}
if (sprm.get('mode')) {
params.append('mode', sprm.get('mode') || '');
}

// params.append('mode', sprm.get('mode'));
params.append('path', path);

// 将参数拼接到路径中
const pathWithParams = `${currentPathname}?${params.toString()}`;

nav(pathWithParams);
if (path.includes('.')) {
return handleSelectFile({
filepath: path,
reportID: sprm.get('report_id') || '',
sha: prm.sha || '',
projectID: prm.id || '',
mode: sprm.get('mode') || '',
}).then((r) => {
return r;
});
} else {
return new Promise((resolve) => {
resolve({});
});
// return new P
}
},
});
const summary = data.reduce((acc: any, cur) => {
const summary = data.reduce((acc: any, cur: any) => {
acc[cur.path] = cur;
return acc;
}, {});
Expand Down
2 changes: 1 addition & 1 deletion packages/canyon-platform/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default defineConfig({
host: '0.0.0.0',
proxy: {
'^/graphql|^/api': {
target: 'http://10.130.238.190',
target: 'http://10.128.124.139',
changeOrigin: true,
}
},
Expand Down
20 changes: 11 additions & 9 deletions packages/canyon-report/src/Report/components/IstanbulReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ const capitalized = (word: string) =>
const dims = ['statements', 'branches', 'functions', 'lines', 'newlines'];
const IstanbulReport: FC<IstanbulReportProps> = ({
theme,
defaultPath,
onSelectFile,
watermarks,
}) => {
console.log(defaultPath,'defaultPath')
const [summary, setSummary] = useState<CoverageSummaryDataMap>({});
// @ts-ignore
const [fileCoverage, setFileCoverage] = useState({} as any);
const [fileContent, setFileContent] = useState('');
const [fileCodeChange, setFileCodeChange] = useState<number[]>([]);
const [loading, setLoading] = useState(false);
const [activePath, setActivePath] = useState('~');
const [activePath, setActivePath] = useState(defaultPath);

const summaryTreeItem = useMemo(() => {
return genSummaryTreeItem(activePath, summary);
Expand All @@ -46,17 +48,17 @@ const IstanbulReport: FC<IstanbulReportProps> = ({
}, [activePath]);

useEffect(() => {
if (activePath.includes('.')) {
setLoading(true);
onSelectFile(activePath).then(
({ fileContent, fileCoverage, fileCodeChange }) => {
setLoading(true);
onSelectFile(activePath).then(
({ fileContent, fileCoverage, fileCodeChange }) => {
if (activePath.includes('.')) {
setFileContent(fileContent);
setFileCoverage(fileCoverage);
setFileCodeChange(fileCodeChange);
setLoading(false);
},
);
}
}
setLoading(false);
},
);
}, [activePath]);
useEffect(() => {
const handleSetOptionEvent = (e: { detail: any }) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/canyon-report/src/Report/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ const configWatermarks = {
};
const init = (
dom: HTMLElement,
{ onSelectFile,theme }: { onSelectFile: OnSelectFile,theme:string },
{ onSelectFile,theme,defaultPath }: { onSelectFile: OnSelectFile,theme:string,defaultPath:string },
) => {
loadCssCode();
render(
<IstanbulReport
theme={theme}
onSelectFile={onSelectFile}
watermarks={configWatermarks}
defaultPath={defaultPath}
/>,
dom!,
);
Expand Down
1 change: 1 addition & 0 deletions packages/canyon-report/src/Report/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export type IstanbulReportProps = {
onSelectFile: OnSelectFile;
watermarks: Watermarks;
theme: string;
defaultPath:string;
};
34 changes: 21 additions & 13 deletions packages/canyon-report/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './reset.css';
import './assets/css/index.css'
import './assets/css/index.css';

import { genSummaryMapByCoverageMap } from '@canyon/data';

import { init } from './index';
Expand All @@ -17,19 +18,26 @@ function getDecode(str: string) {
}

const report = init(document.querySelector('#root') as any, {
theme:'light',
theme: 'light',
defaultPath: '~/src',
onSelectFile(path: string) {
return new Promise((resolve) => {
setTimeout(()=>{
resolve({
// @ts-ignore
fileCoverage: __coverage__[path],
// @ts-ignore
fileContent: getDecode(__filecontent__[path]),
fileCodeChange:[1,2,3,4]
});
},200)
});
if (path.includes('.')) {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
// @ts-ignore
fileCoverage: __coverage__[path],
// @ts-ignore
fileContent: getDecode(__filecontent__[path]),
fileCodeChange: [1, 2, 3, 4],
});
}, 200);
});
} else {
return new Promise((resolve) => {
resolve({});
});
}
},
});
report.setOption({
Expand Down

0 comments on commit 1f6448a

Please sign in to comment.