diff --git a/packages/canyon-backend/schema.gql b/packages/canyon-backend/schema.gql index 0e5bdd41..80191013 100644 --- a/packages/canyon-backend/schema.gql +++ b/packages/canyon-backend/schema.gql @@ -252,6 +252,7 @@ type Query { """升序或降序""" order: String! favorOnly: Boolean! + defaultCoverageDim: String! ): ProjectPagesModel! """获取Projects部门选项""" @@ -264,7 +265,7 @@ type Query { getProjectChartData(projectID: String!, branch: String!): [ProjectChartDataModel!]! """获取Project宫格""" - getProjectCompartmentData(projectID: String!): [ProjectCompartmentDataModel!]! + getProjectCompartmentData(projectID: String!, defaultCoverageDim: String!): [ProjectCompartmentDataModel!]! """获取Project记录""" getProjectRecords(projectID: String!, current: Int!, pageSize: Int!, keyword: String!, onlyDefault: Boolean): ProjectRecordsPagesModel! diff --git a/packages/canyon-backend/src/project/project.resolver.ts b/packages/canyon-backend/src/project/project.resolver.ts index 2d71c138..ea7704af 100755 --- a/packages/canyon-backend/src/project/project.resolver.ts +++ b/packages/canyon-backend/src/project/project.resolver.ts @@ -50,6 +50,8 @@ export class ProjectResolver { @Args() paginationArgs: PaginationArgs, @Args() sorterArgs: SorterArgs, @Args("favorOnly", { type: () => Boolean }) favorOnly: boolean, + @Args("defaultCoverageDim", { type: () => String }) + defaultCoverageDim: string, ): Promise { return this.getProjectsService.invoke( user?.id, @@ -62,6 +64,7 @@ export class ProjectResolver { sorterArgs.field, sorterArgs.order, favorOnly, + defaultCoverageDim, ); } @@ -94,8 +97,13 @@ export class ProjectResolver { }) getProjectCompartmentData( @Args("projectID", { type: () => String }) projectID: string, + @Args("defaultCoverageDim", { type: () => String }) + defaultCoverageDim: string, ): Promise { - return this.getProjectCompartmentDataService.invoke(projectID); + return this.getProjectCompartmentDataService.invoke( + projectID, + defaultCoverageDim, + ); } @Query(() => ProjectRecordsPagesModel, { diff --git a/packages/canyon-backend/src/project/services/get-project-compartment-data.service.ts b/packages/canyon-backend/src/project/services/get-project-compartment-data.service.ts index 370d28a6..85434758 100644 --- a/packages/canyon-backend/src/project/services/get-project-compartment-data.service.ts +++ b/packages/canyon-backend/src/project/services/get-project-compartment-data.service.ts @@ -6,7 +6,7 @@ import { percent } from "canyon-data"; @Injectable() export class GetProjectCompartmentDataService { constructor(private readonly prisma: PrismaService) {} - async invoke(projectID) { + async invoke(projectID, defaultCoverageDim) { const project = await this.prisma.project.findFirst({ where: { id: projectID, @@ -26,6 +26,12 @@ export class GetProjectCompartmentDataService { select: { statementsCovered: true, statementsTotal: true, + branchesTotal: true, + branchesCovered: true, + functionsTotal: true, + functionsCovered: true, + linesTotal: true, + linesCovered: true, updatedAt: true, }, }); @@ -39,8 +45,11 @@ export class GetProjectCompartmentDataService { label: "projects.max_coverage", value: Math.max( - ...coverages.map((c) => - percent(c.statementsCovered, c.statementsTotal), + ...coverages.map((item) => + percent( + item[`${defaultCoverageDim}Covered`], + item[`${defaultCoverageDim}Total`], + ), ), ) + "%", }, @@ -52,8 +61,8 @@ export class GetProjectCompartmentDataService { label: "projects.latest_report_coverage", value: percent( - coverages[0].statementsCovered, - coverages[0].statementsTotal, + coverages[0][`${defaultCoverageDim}Covered`], + coverages[0][`${defaultCoverageDim}Total`], ) + "%", }, ]; diff --git a/packages/canyon-backend/src/project/services/get-projects.service.ts b/packages/canyon-backend/src/project/services/get-projects.service.ts index 2a1b791a..b5e1f853 100644 --- a/packages/canyon-backend/src/project/services/get-projects.service.ts +++ b/packages/canyon-backend/src/project/services/get-projects.service.ts @@ -18,6 +18,7 @@ export class GetProjectsService { field, order, favorOnly, + defaultCoverageDim, ): Promise { const favorProjects = await this.prisma.user .findUnique({ @@ -80,15 +81,17 @@ export class GetProjectsService { }, select: { projectID: true, - // project: true, sha: true, - // branch: true, - // report: true, createdAt: true, updatedAt: true, statementsCovered: true, statementsTotal: true, - // summary: true, + branchesTotal: true, + branchesCovered: true, + functionsTotal: true, + functionsCovered: true, + linesTotal: true, + linesCovered: true, }, }); @@ -124,7 +127,10 @@ export class GetProjectsService { ...covs .filter((item) => within30days(item.updatedAt)) .map((item) => - percent(item.statementsCovered, item.statementsTotal), + percent( + item[`${defaultCoverageDim}Covered`], + item[`${defaultCoverageDim}Total`], + ), ), ) : 0, diff --git a/packages/canyon-platform/src/helpers/backend/gql/queries/GetProjectCompartmentData.graphql b/packages/canyon-platform/src/helpers/backend/gql/queries/GetProjectCompartmentData.graphql index e62c8117..818a80f3 100644 --- a/packages/canyon-platform/src/helpers/backend/gql/queries/GetProjectCompartmentData.graphql +++ b/packages/canyon-platform/src/helpers/backend/gql/queries/GetProjectCompartmentData.graphql @@ -1,5 +1,5 @@ -query GetProjectCompartmentData($projectID: String!) { - getProjectCompartmentData(projectID: $projectID) { +query GetProjectCompartmentData($projectID: String!, $defaultCoverageDim: String!) { + getProjectCompartmentData(projectID: $projectID,defaultCoverageDim: $defaultCoverageDim) { value label } diff --git a/packages/canyon-platform/src/helpers/backend/gql/queries/GetProjects.graphql b/packages/canyon-platform/src/helpers/backend/gql/queries/GetProjects.graphql index eea5146f..8404cebd 100755 --- a/packages/canyon-platform/src/helpers/backend/gql/queries/GetProjects.graphql +++ b/packages/canyon-platform/src/helpers/backend/gql/queries/GetProjects.graphql @@ -8,6 +8,7 @@ query GetProjects( $field: String! $order: String! $favorOnly: Boolean! + $defaultCoverageDim: String! ) { getProjects( current: $current @@ -19,6 +20,7 @@ query GetProjects( field: $field order: $order favorOnly: $favorOnly + defaultCoverageDim: $defaultCoverageDim ) { total data { @@ -30,7 +32,6 @@ query GetProjects( lastReportTime maxCoverage favored - # language } } } diff --git a/packages/canyon-platform/src/pages/index/projects/[id]/index.tsx b/packages/canyon-platform/src/pages/index/projects/[id]/index.tsx index 7652177e..ffb1adde 100755 --- a/packages/canyon-platform/src/pages/index/projects/[id]/index.tsx +++ b/packages/canyon-platform/src/pages/index/projects/[id]/index.tsx @@ -86,6 +86,7 @@ const ProjectOverviewPage = () => { } = useQuery(GetProjectCompartmentDataDocument, { variables: { projectID: pam.id as string, + defaultCoverageDim: localStorage.getItem("defaultCoverageDim") || "statements", }, fetchPolicy: "no-cache", }); @@ -224,7 +225,7 @@ const ProjectOverviewPage = () => { }, { title: t("common.option"), - width: "75px", + width: "85px", render(_): JSX.Element { return (
diff --git a/packages/canyon-platform/src/pages/index/projects/index.tsx b/packages/canyon-platform/src/pages/index/projects/index.tsx index c27f03f6..90659e01 100755 --- a/packages/canyon-platform/src/pages/index/projects/index.tsx +++ b/packages/canyon-platform/src/pages/index/projects/index.tsx @@ -21,7 +21,7 @@ import { GetProjectsDocument, GetProjectsTagOptionsDocument, Project, -} from "../../../helpers/backend/gen/graphql.ts"; +} from "@/helpers/backend/gen/graphql.ts"; const { Text } = Typography; @@ -229,7 +229,7 @@ const ProjectPage = () => { fetchPolicy: "no-cache", }, ); - + const defaultCoverageDim = localStorage.getItem("defaultCoverageDim") || "statements"; const { data: projectsData, loading, @@ -245,6 +245,7 @@ const ProjectPage = () => { field: sorter.field || "", order: sorter.order || "", favorOnly: favorOnly, + defaultCoverageDim: defaultCoverageDim, }, fetchPolicy: "no-cache", });