Skip to content

Commit

Permalink
chore: daily development
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Jan 16, 2025
1 parent f0dc220 commit c592cc5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 18 deletions.
3 changes: 2 additions & 1 deletion packages/canyon-backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ type Query {
"""升序或降序"""
order: String!
favorOnly: Boolean!
defaultCoverageDim: String!
): ProjectPagesModel!

"""获取Projects部门选项"""
Expand All @@ -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!
Expand Down
10 changes: 9 additions & 1 deletion packages/canyon-backend/src/project/project.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectPagesModel> {
return this.getProjectsService.invoke(
user?.id,
Expand All @@ -62,6 +64,7 @@ export class ProjectResolver {
sorterArgs.field,
sorterArgs.order,
favorOnly,
defaultCoverageDim,
);
}

Expand Down Expand Up @@ -94,8 +97,13 @@ export class ProjectResolver {
})
getProjectCompartmentData(
@Args("projectID", { type: () => String }) projectID: string,
@Args("defaultCoverageDim", { type: () => String })
defaultCoverageDim: string,
): Promise<ProjectCompartmentDataModel[]> {
return this.getProjectCompartmentDataService.invoke(projectID);
return this.getProjectCompartmentDataService.invoke(
projectID,
defaultCoverageDim,
);
}

@Query(() => ProjectRecordsPagesModel, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
});
Expand All @@ -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`],
),
),
) + "%",
},
Expand All @@ -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`],
) + "%",
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class GetProjectsService {
field,
order,
favorOnly,
defaultCoverageDim,
): Promise<any> {
const favorProjects = await this.prisma.user
.findUnique({
Expand Down Expand Up @@ -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,
},
});

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query GetProjectCompartmentData($projectID: String!) {
getProjectCompartmentData(projectID: $projectID) {
query GetProjectCompartmentData($projectID: String!, $defaultCoverageDim: String!) {
getProjectCompartmentData(projectID: $projectID,defaultCoverageDim: $defaultCoverageDim) {
value
label
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ query GetProjects(
$field: String!
$order: String!
$favorOnly: Boolean!
$defaultCoverageDim: String!
) {
getProjects(
current: $current
Expand All @@ -19,6 +20,7 @@ query GetProjects(
field: $field
order: $order
favorOnly: $favorOnly
defaultCoverageDim: $defaultCoverageDim
) {
total
data {
Expand All @@ -30,7 +32,6 @@ query GetProjects(
lastReportTime
maxCoverage
favored
# language
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const ProjectOverviewPage = () => {
} = useQuery(GetProjectCompartmentDataDocument, {
variables: {
projectID: pam.id as string,
defaultCoverageDim: localStorage.getItem("defaultCoverageDim") || "statements",
},
fetchPolicy: "no-cache",
});
Expand Down Expand Up @@ -224,7 +225,7 @@ const ProjectOverviewPage = () => {
},
{
title: t("common.option"),
width: "75px",
width: "85px",
render(_): JSX.Element {
return (
<div>
Expand Down
5 changes: 3 additions & 2 deletions packages/canyon-platform/src/pages/index/projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
GetProjectsDocument,
GetProjectsTagOptionsDocument,
Project,
} from "../../../helpers/backend/gen/graphql.ts";
} from "@/helpers/backend/gen/graphql.ts";

const { Text } = Typography;

Expand Down Expand Up @@ -229,7 +229,7 @@ const ProjectPage = () => {
fetchPolicy: "no-cache",
},
);

const defaultCoverageDim = localStorage.getItem("defaultCoverageDim") || "statements";
const {
data: projectsData,
loading,
Expand All @@ -245,6 +245,7 @@ const ProjectPage = () => {
field: sorter.field || "",
order: sorter.order || "",
favorOnly: favorOnly,
defaultCoverageDim: defaultCoverageDim,
},
fetchPolicy: "no-cache",
});
Expand Down

0 comments on commit c592cc5

Please sign in to comment.