Skip to content

Commit

Permalink
chore: repo overall update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 20, 2024
1 parent 373143c commit e43e918
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
"use client";
import { useParams, useRouter } from "next/navigation";
import React, { useMemo, useState } from "react";
import { useParams } from "next/navigation";
import React, { useState } from "react";
import useSWR from "swr";
import axios from "axios";
import MainBox from "@/components/main-box";
import { Report } from "../../../../../../../canyon-report/src/components";
import { theme } from "antd";
import { genSummaryMapByCoverageMap, getSummaryByPath } from "canyon-data";
import { handleSelect } from "@/utils/handle";
// import {handleSelect} from "@/utils/handle";
const { useToken } = theme;
function getDecode(str: string) {
return decodeURIComponent(
atob(str)
.split("")
.map(function (c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
})
.join(""),
);
}

// http://localhost:3000/projects/490316875/commits/f721bf684d49254717e03ca14e53a1b1f8882019/src/index.tsx
const fetcher = ({ url, params }) =>
Expand All @@ -29,60 +20,32 @@ const fetcher = ({ url, params }) =>

export default function Page() {
const { filepath, id, sha } = useParams(); // 获取动态路由参数
const filePath = filepath ? filepath.join("/") : "";
const defultfilepath = filepath ? filepath.join("/") : "";
const { token } = useToken();
const router = useRouter();
// const [value, setValue] = useState(window.location.hash.slice(1));

const { data: fileCoverage } = useSWR(
{
url: "/api/cov/map",
params: {
project_id: id,
sha,
filepath: filePath,
},
},
fetcher,
);
const [value, setValue] = useState(defultfilepath);

const { data: summary } = useSWR(
{
url: "/api/cov/summary/map",
params: {
project_id: id,
sha,
// filepath: filePath,
},
},
fetcher,
);

const { data: fileContent } = useSWR(
{
url: "/api/sourcecode",
params: {
project_id: id,
sha,
filepath: filePath,
},
},
fetcher,
);

const onSelect = (val) => {
// console.log(val, "val");
router.push(`/projects/${id}/commits/${sha}/${val}`);
return new Promise((resolve) => {
resolve({
fileContent: getDecode(fileContent.content),
fileCoverage: fileCoverage[filePath],
});
history.pushState(null, "", `/projects/${id}/commits/${sha}/${val}`);
setValue(val);
// handleSelect
return handleSelect({
projectID: id,
sha,
filepath: val,
});
};

// const summary = genSummaryMapByCoverageMap(cov, []);

return (
<MainBox>
<div
Expand All @@ -91,12 +54,12 @@ export default function Page() {
boxShadow: `${token.boxShadowTertiary}`,
}}
>
{summary?.length && fileContent && fileCoverage && (
{summary?.length && (
<Report
reportName={"reportName"}
dataSource={summary || []}
onSelect={onSelect}
value={filePath}
value={value}
/>
)}
</div>
Expand Down
45 changes: 45 additions & 0 deletions packages/canyon-platform/utils/handle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import axios from "axios";
// import { getDecode } from "@/utils/coverage";

// 用于文件base64解码后的格式化
function getDecode(str: string) {
return decodeURIComponent(
atob(str)
.split("")
.map(function (c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
})
.join(""),
);
}
export const handleSelect = ({ projectID, sha, filepath }) => {
return Promise.all([
axios.get("/api/cov/map", {
params: {
project_id: projectID,
sha,
filepath,
},
}),
axios
.get("/api/sourcecode", {
params: {
project_id: projectID,
sha,
filepath,
},
})
.catch((err) => {
return {
data: {
content: "",
},
};
}),
]).then(([res1, res2]) => {
return {
fileCoverage: res1.data[filepath],
fileContent: getDecode(res2.data.content),
};
});
};

0 comments on commit e43e918

Please sign in to comment.