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 63b846c commit a05a85d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ canyon-analytics/canyon-migrate-data
3. 暂时就使用刷新页面,后面再优化
4. 暂时不用compare功能
5. 还缺一个分布式更新功能就结束了

核心

/coverage/map/client
/coverage/client

Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ 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,
})
.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",
Expand All @@ -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,
Expand Down
39 changes: 26 additions & 13 deletions packages/canyon-platform/utils/handle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from "axios";
// import { getDecode } from "@/utils/coverage";

// 用于文件base64解码后的格式化
function getDecode(str: string) {
Expand All @@ -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,
Expand All @@ -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),
};
};

0 comments on commit a05a85d

Please sign in to comment.