Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/apis/azul/hca-dcp/common/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export interface ProjectsEntityResponse {
* Model of project summary in the response from /index/summary API endpoint.
*/
export interface ProjectSummary {
cellSuspensions: { totalCells: number };
projects: { estimatedCellCount: number };
cellSuspensions: { totalCells: number | null };
projects: { estimatedCellCount: number | null };
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/apis/azul/hca-dcp/common/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ export type SummaryResponse = {
projects: ProjectSummary[];
speciesCount: number;
specimenCount: number;
totalFileSize: number | string;
totalFileSize: number;
};
9 changes: 0 additions & 9 deletions site-config/hca-dcp/dev/index/common/constants.ts

This file was deleted.

46 changes: 41 additions & 5 deletions site-config/hca-dcp/dev/index/summaryViewModelBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
import { AzulSummaryResponse } from "@databiosphere/findable-ui/lib/apis/azul/common/entities";
import { mapSummary } from "../../../../app/components/Index/common/indexTransformer";
import { SUMMARIES } from "./common/constants";
import { formatCountSize } from "@databiosphere/findable-ui/lib/utils/formatCountSize";
import { ProjectSummary } from "../../../../app/apis/azul/hca-dcp/common/entities";
import { SummaryResponse } from "../../../../app/apis/azul/hca-dcp/common/responses";

/**
* Maps the HCA-DCP summary response to summary display key-value pairs.
* @param summaryResponse - Response model returned from the summary API.
* @returns summary key-value pairs of [count, label].
*/
export const buildSummaries = (
summaryResponse: AzulSummaryResponse
summaryResponse: SummaryResponse
): [string, string][] => {
return mapSummary(SUMMARIES, summaryResponse);
return [
[
formatCountSize(sumEstimatedCellCounts(summaryResponse)),
"Estimated Cells",
],
[formatCountSize(summaryResponse.specimenCount), "Specimens"],
[formatCountSize(summaryResponse.donorCount), "Donors"],
[formatCountSize(summaryResponse.fileCount), "Files"],
];
};

/**
* Sums the estimated cell counts across all projects in the summary response.
* Uses estimatedCellCount when available, falling back to totalCells.
* @param summaryResponse - Response model returned from the summary API.
* @returns total estimated cell count across all projects.
*/
function sumEstimatedCellCounts(summaryResponse: SummaryResponse): number {
return (summaryResponse.projects ?? []).reduce(
(accum, { cellSuspensions, projects }: ProjectSummary) => {
if (projects?.estimatedCellCount || projects?.estimatedCellCount === 0) {
accum += projects.estimatedCellCount;
} else if (
cellSuspensions?.totalCells ||
cellSuspensions?.totalCells === 0
) {
accum += cellSuspensions.totalCells;
}
return accum;
},
0
);
}
Loading