diff --git a/README.md b/README.md index 44f80846..6ddb1bb5 100755 --- a/README.md +++ b/README.md @@ -11,3 +11,9 @@ canyon-analytics/canyon-migrate-data 3. 暂时就使用刷新页面,后面再优化 4. 暂时不用compare功能 5. 还缺一个分布式更新功能就结束了 + +核心 + +/coverage/map/client +/coverage/client + diff --git a/packages/canyon-platform/app/projects/[id]/commits/[sha]/[...filepath]/page.tsx b/packages/canyon-platform/app/projects/[id]/commits/[sha]/[...filepath]/page.tsx index b83dc040..fa6fbdb9 100644 --- a/packages/canyon-platform/app/projects/[id]/commits/[sha]/[...filepath]/page.tsx +++ b/packages/canyon-platform/app/projects/[id]/commits/[sha]/[...filepath]/page.tsx @@ -7,11 +7,9 @@ import MainBox from "@/components/main-box"; import { Report } from "../../../../../../../canyon-report/src/components"; import { theme } from "antd"; import { handleSelect } from "@/utils/handle"; -// import {handleSelect} from "@/utils/handle"; const { useToken } = theme; -// http://localhost:3000/projects/490316875/commits/f721bf684d49254717e03ca14e53a1b1f8882019/src/index.tsx -const fetcher = ({ url, params }) => +const fetcher = ({ url, params }: { url: string; params: any }) => axios .get(url, { params: params, @@ -19,11 +17,14 @@ const fetcher = ({ url, params }) => .then((res) => res.data); export default function Page() { - const { filepath, id, sha } = useParams(); // 获取动态路由参数 - const defultfilepath = filepath ? filepath.join("/") : ""; const { token } = useToken(); - const [value, setValue] = useState(defultfilepath); + const { filepath, id, sha } = useParams(); // 获取动态路由参数 + // @ts-ignore + const defaultFilePath = filepath ? filepath.join("/") : ""; + // 当前选择的路径 + const [value, setValue] = useState(defaultFilePath); + // 非常重要的一步,获取整体覆盖率数据 const { data: summary } = useSWR( { url: "/api/cov/summary/map", @@ -35,10 +36,12 @@ export default function Page() { fetcher, ); - const onSelect = (val) => { + const onSelect = (val: any) => { + // TODO 防止页面刷新,但是不能回退,是否有更好的方式? history.pushState(null, "", `/projects/${id}/commits/${sha}/${val}`); + // 设置当前选择的路径 setValue(val); - // handleSelect + // 处理选择事件 return handleSelect({ projectID: id, sha, diff --git a/packages/canyon-platform/utils/handle.ts b/packages/canyon-platform/utils/handle.ts index 681ff90d..7320d9b5 100644 --- a/packages/canyon-platform/utils/handle.ts +++ b/packages/canyon-platform/utils/handle.ts @@ -1,5 +1,4 @@ import axios from "axios"; -// import { getDecode } from "@/utils/coverage"; // 用于文件base64解码后的格式化 function getDecode(str: string) { @@ -12,8 +11,23 @@ function getDecode(str: string) { .join(""), ); } -export const handleSelect = ({ projectID, sha, filepath }) => { - return Promise.all([ +export const handleSelect = async ({ + projectID, + sha, + filepath, +}: { + projectID: string; + sha: string; + filepath: string; +}) => { + // TODO 要改,判断文件的逻辑 + if (!filepath.includes(".")) { + return Promise.resolve({ + fileCoverage: {}, + fileContent: "", + }); + } + const [coverage, sourcecode] = await Promise.all([ axios.get("/api/cov/map", { params: { project_id: projectID, @@ -29,17 +43,16 @@ export const handleSelect = ({ projectID, sha, filepath }) => { filepath, }, }) - .catch((err) => { + .then((res) => res.data) + .catch(() => { return { - data: { - content: "", - }, + content: "", }; }), - ]).then(([res1, res2]) => { - return { - fileCoverage: res1.data[filepath], - fileContent: getDecode(res2.data.content), - }; - }); + ]); + return { + // @ts-ignore + fileCoverage: coverage[filepath], + fileContent: getDecode(sourcecode.content), + }; };