From 9724203c09719e59bddb4b21eb6c9f848fe51794 Mon Sep 17 00:00:00 2001 From: zhangtao25 Date: Wed, 27 Nov 2024 14:55:04 +0800 Subject: [PATCH] chore: repo overall update --- .../app/api/project/[id]/record/route.ts | 39 +++++ .../app/projects/[id]/page.tsx | 164 +++++------------- .../canyon-platform/components/main-box.tsx | 53 ++++-- .../src/components/helpers/file.ts | 2 +- 4 files changed, 119 insertions(+), 139 deletions(-) create mode 100644 packages/canyon-platform/app/api/project/[id]/record/route.ts diff --git a/packages/canyon-platform/app/api/project/[id]/record/route.ts b/packages/canyon-platform/app/api/project/[id]/record/route.ts new file mode 100644 index 00000000..1433196d --- /dev/null +++ b/packages/canyon-platform/app/api/project/[id]/record/route.ts @@ -0,0 +1,39 @@ +// export const dynamic = 'force-static' +import prisma from "@/lib/prisma"; +// import {decompressedData} from "@/utils/zstd"; + +import { NextRequest } from "next/server"; + +export async function GET(request: NextRequest) { + const { pathname } = request.nextUrl; + // const projectID = searchParams.get("project_id"); + // const sha = searchParams.get("sha"); + // const filepath = searchParams.get("filepath"); + // console.log(pathname.split('/')[3],'request.nextUrl') + const projectID = pathname.split("/")[3]; + + const coverages = await prisma.coverage + .findMany({ + where: { + projectID: projectID, + }, + select: { + sha: true, + projectID: true, + }, + }) + .then((r) => { + return r.map((item) => { + return { + sha: item.sha, + projectID: item.projectID, + times:0, + statements:0, + message: "message", + branch: "branch", + }; + }); + }); + + return Response.json(coverages); +} diff --git a/packages/canyon-platform/app/projects/[id]/page.tsx b/packages/canyon-platform/app/projects/[id]/page.tsx index ac8c24f4..6dbe7604 100644 --- a/packages/canyon-platform/app/projects/[id]/page.tsx +++ b/packages/canyon-platform/app/projects/[id]/page.tsx @@ -15,6 +15,9 @@ import { ColumnsType } from "antd/es/table"; // import { AimOutlined, BranchesOutlined } from "@ant-design/icons"; import Link from "next/link"; import MainBox from "@/components/main-box"; +import useSWR from "swr"; +import axios from "axios"; +import { useParams } from "next/navigation"; const getProjectCompartmentData = [ { label: "name", @@ -33,9 +36,30 @@ const getProjectCompartmentData = [ value: "100", }, ]; +const fetcher = ({ url, params }: { url: string; params: any }) => + axios + .get(url, { + params: params, + }) + .then((res) => res.data); + const { useToken } = theme; const t = (msg) => msg; const ProjectOverviewPage = () => { + const { filepath, id, sha } = useParams(); // 获取动态路由参数 + // console.log(id) + // 非常重要的一步,获取整体覆盖率数据 + const { data: record } = useSWR( + { + url: `/api/project/${id}/record`, + params: { + project_id: "id", + sha: "sha", + }, + }, + fetcher, + ); + const { token } = useToken(); const columns: ColumnsType = [ { @@ -49,9 +73,7 @@ const ProjectOverviewPage = () => { width: "100px", render(_, { webUrl }): JSX.Element { return ( - - {_?.slice(0, 7)} - + {_?.slice(0, 7)} ); }, }, @@ -59,7 +81,7 @@ const ProjectOverviewPage = () => { title: ( <> {/**/} - {"projects.branch"} + {"Branch"} ), dataIndex: "branch", @@ -67,46 +89,7 @@ const ProjectOverviewPage = () => { width: "120px", }, { - title: ( - <> - {/**/} - {"projects.compare_target"} - - ), - dataIndex: "compareTarget", - width: "120px", - render(_, { compareUrl }): JSX.Element { - return ( - - {_.length === 40 ? _.slice(0, 7) : _} - - ); - }, - }, - { - title: <>{"Build"}, - align: "center", - width: "70px", - render(_, record) { - return ( - <> - {record.buildID !== "-" ? ( - - - - ) : ( - - - )} - - ); - }, - }, - { - title: t("projects.message"), + title: t("Message"), dataIndex: "message", width: "160px", ellipsis: true, @@ -114,10 +97,10 @@ const ProjectOverviewPage = () => { { title: (
- {/**/} + {/**/} {/* */} {/**/} - {"projects.statements"} + {"Statements"}
), dataIndex: "statements", @@ -125,7 +108,7 @@ const ProjectOverviewPage = () => { render(_, { sha }) { return ( @@ -133,65 +116,22 @@ const ProjectOverviewPage = () => { ); }, - // width: '150px', - // render(_, { sha }) { - // return ( - //
- // - // {_}% - // - // - // coverage - // - // - //
- // ); - // }, }, { - title: ( -
- {/**/} - {/* */} - {/**/} - {"projects.newlines"} -
- ), - dataIndex: "newlines", - // width: '130px', - render(_, { sha }) { - return ( - - {_}% - - ); - }, - }, - { - title: "projects.report_times", + title: "Report Times", dataIndex: "times", - width: "80px", + // width: "80px", }, { - title: "projects.latest_report_time", + title: "Latest Report Time", dataIndex: "lastReportTime", - width: "135px", + // width: "135px", render(_) { return {"MM-DD HH:mm"}; }, }, { - title: "common.option", + title: "Option", width: "125px", render(_): JSX.Element { return ( @@ -202,24 +142,8 @@ const ProjectOverviewPage = () => { // setSha(_.sha); }} > - {"projects.reported_details"} + {"Details"} - - - {}} - onCancel={() => { - console.log("cancel"); - }} - okText="Yes" - cancelText="No" - > - - {"common.delete"} - - ); }, @@ -236,7 +160,7 @@ const ProjectOverviewPage = () => {
项目Id - {"projects.default.branch"}: {"main"} + {"default.branch"}: {"main"}
@@ -244,7 +168,7 @@ const ProjectOverviewPage = () => { - {"projects.overview"} + {"overview"}
@@ -283,14 +207,14 @@ const ProjectOverviewPage = () => { >
- {"projects.trends_in_coverage"} + {"trends_in_coverage"} - {"projects.trends.tooltip"} + {"trends.tooltip"}
{/* {
- {"projects.records"} + {"records"}
{
{ // setKeyword(value); // setCurrent(1); @@ -327,7 +251,7 @@ const ProjectOverviewPage = () => { style={{ width: "600px" }} /> - {"projects.only.default.branch"}: + {"only.default.branch"}: { // pageSize: projectsData?.getProjects?.pageSize, } } - dataSource={[]} + dataSource={record} onChange={(val) => { // setCurrent(val.current || 1); // setPageSize(val.pageSize || 10); diff --git a/packages/canyon-platform/components/main-box.tsx b/packages/canyon-platform/components/main-box.tsx index becc3825..3d68199e 100644 --- a/packages/canyon-platform/components/main-box.tsx +++ b/packages/canyon-platform/components/main-box.tsx @@ -10,11 +10,12 @@ import { Typography, } from "antd"; import Image from "next/image"; -import { usePathname } from "next/navigation"; -import React, { useEffect } from "react"; +import { useParams, usePathname } from "next/navigation"; +import React, { useEffect, useMemo } from "react"; // import Link from "next/link"; // import CIcon from "@/components/c-icon"; import AppFooter from "@/components/app-footer"; +import Link from "next/link"; const menuItems = [ { @@ -59,6 +60,7 @@ const MeData = { const { useToken } = theme; const MainBoxWrap = ({ children }: React.PropsWithChildren) => { const routeName = usePathname(); + const { id, sha } = useParams(); // 获取动态路由参数 const { token } = useToken(); const onSelectMenu = (selectInfo: any) => { console.log(selectInfo); @@ -67,6 +69,36 @@ const MainBoxWrap = ({ children }: React.PropsWithChildren) => { const selectedKey = usePathname().split("/")[1]; + // const BreadcrumbItems = [] + + const breadcrumbItems = useMemo(() => { + // return [] + if (id && !sha) { + return [ + { + title: Projects, + }, + { + title: "Overview", + }, + ]; + } else if (id && sha) { + return [ + { + title: Projects, + }, + { + title: Overview, + }, + { + title: "Coverage Details", + }, + ]; + } else { + return []; + } + }, [id, sha]); + return ( { "m-auto max-w-[1200px] min-w-[1000px] px-[12px] py-[12px]" } > - Projects, - }, - { - title: Overview, - }, - { - title: "Coverage Details", - }, - ]} - /> +
{children} diff --git a/packages/canyon-report/src/components/helpers/file.ts b/packages/canyon-report/src/components/helpers/file.ts index bf0533f3..2180e8a9 100644 --- a/packages/canyon-report/src/components/helpers/file.ts +++ b/packages/canyon-report/src/components/helpers/file.ts @@ -20,7 +20,7 @@ export const genFileDetailLines = (fileCoverage, fileContent) => { // console.log(coverage) const totalLines = fileContent.split("\n").length; const lineStats = getLineCoverage(fileCoverage); - console.log(lineStats); + // console.log(lineStats); 很奇怪,打开nextjs会报错 return Array.from({ length: totalLines }, (_, index) => { return { count: lineStats[index + 1],