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
35 changes: 22 additions & 13 deletions app/components/Index/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
calculateSummaryTotalCellCount,
getSummaryCount,
} from "./utils";
import { formatCountSize } from "@databiosphere/findable-ui/lib/utils/formatCountSize";
import { formatFileSize } from "@databiosphere/findable-ui/lib/utils/formatFileSize";

// Template constants
const {
Expand Down Expand Up @@ -53,24 +55,29 @@ const {
FILES,
SPECIES,
SPECIMENS,
TOTAL_FILE_SIZE,
} = SUMMARY;

/**
* Functions binding summary response API to summary count.
*/
export const BIND_SUMMARY_RESPONSE = {
[BIOSAMPLES]: (r: AzulSummaryResponse): number =>
getSummaryCount(r, SUMMARY_KEY.BIOSAMPLES),
[DONORS]: (r: AzulSummaryResponse): number =>
getSummaryCount(r, SUMMARY_KEY.DONORS),
[ESTIMATED_CELLS]: calculateSummaryTotalCellCount,
[FILES]: (r: AzulSummaryResponse): number =>
getSummaryCount(r, SUMMARY_KEY.FILES),
[FILE_FORMATS]: calculateSummaryFileFormatsCount,
[SPECIES]: (r: AzulSummaryResponse): number =>
getSummaryCount(r, SUMMARY_KEY.SPECIES),
[SPECIMENS]: (r: AzulSummaryResponse): number =>
getSummaryCount(r, SUMMARY_KEY.SPECIMENS),
[BIOSAMPLES]: (r: AzulSummaryResponse): string =>
formatCountSize(getSummaryCount(r, SUMMARY_KEY.BIOSAMPLES)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatCountSize added to each binder fn to allow totalFileSize to be formatted by formatFileSize. See https://github.com/DataBiosphere/data-browser/pull/4571/files#r2408973202.

[DONORS]: (r: AzulSummaryResponse): string =>
formatCountSize(getSummaryCount(r, SUMMARY_KEY.DONORS)),
[ESTIMATED_CELLS]: (r: AzulSummaryResponse): string =>
formatCountSize(calculateSummaryTotalCellCount(r)),
[FILES]: (r: AzulSummaryResponse): string =>
formatCountSize(getSummaryCount(r, SUMMARY_KEY.FILES)),
[FILE_FORMATS]: (r: AzulSummaryResponse): string =>
formatCountSize(calculateSummaryFileFormatsCount(r)),
[SPECIES]: (r: AzulSummaryResponse): string =>
formatCountSize(getSummaryCount(r, SUMMARY_KEY.SPECIES)),
[SPECIMENS]: (r: AzulSummaryResponse): string =>
formatCountSize(getSummaryCount(r, SUMMARY_KEY.SPECIMENS)),
[TOTAL_FILE_SIZE]: (r: AzulSummaryResponse): string =>
formatFileSize(getSummaryCount(r, SUMMARY_KEY.TOTAL_FILE_SIZE)),
};

export const NETWORK_KEYS = [
Expand Down Expand Up @@ -162,13 +169,14 @@ export const PLURALIZED_METADATA_LABEL = {
/**
* Set of possible summary keys.
*/
export const SUMMARY_KEY = {
export const SUMMARY_KEY: Record<string, keyof AzulSummaryResponse> = {
[BIOSAMPLES]: "biosampleCount",
[DONORS]: "donorCount",
[FILES]: "fileCount",
[FILE_FORMATS]: "fileFormats",
[SPECIES]: "speciesCount",
[SPECIMENS]: "specimenCount",
[TOTAL_FILE_SIZE]: "totalFileSize",
} as const;

/**
Expand All @@ -182,4 +190,5 @@ export const SUMMARY_LABEL = {
[FILE_FORMATS]: "Files",
[SPECIES]: "Species",
[SPECIMENS]: "Specimens",
[TOTAL_FILE_SIZE]: "",
};
1 change: 1 addition & 0 deletions app/components/Index/common/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ export enum SUMMARY {
FILES = "FILES",
SPECIES = "SPECIES",
SPECIMENS = "SPECIMENS",
TOTAL_FILE_SIZE = "TOTAL_FILE_SIZE",
}
3 changes: 1 addition & 2 deletions app/components/Index/common/indexTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AzulSummaryResponse } from "@databiosphere/findable-ui/lib/apis/azul/common/entities";
import { formatCountSize } from "@databiosphere/findable-ui/lib/utils/formatCountSize";
import {
BIND_SUMMARY_RESPONSE,
PLURALIZED_METADATA_LABEL,
Expand Down Expand Up @@ -30,7 +29,7 @@ export function mapSummary(
): [string, string][] {
return summaries.map((summary) => {
const summaryBinderFn = BIND_SUMMARY_RESPONSE[summary];
const count = formatCountSize(summaryBinderFn(summaryResponse));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatCountSize removed and added to each summaryBinderFn so that formatFileSize able to used for totalFileSize formatting.

const count = summaryBinderFn(summaryResponse);
const label = SUMMARY_LABEL[summary];
return [count, label];
});
Expand Down
2 changes: 2 additions & 0 deletions e2e/anvil/anvil-index-export-button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ test.describe("AnVIL Data Explorer Export", () => {
// Test that each summary item is present in the export summary
// with corresponding count.
for (const [label, count] of summary) {
// Total file size summary item has no label.
if (!label) continue;
const summaryItem = exportSummaryLocator
.locator("> div")
.filter({ hasText: label });
Expand Down
4 changes: 2 additions & 2 deletions site-config/anvil-cmg/dev/index/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SUMMARY } from "app/components/Index/common/entities";

// Template constants
const { BIOSAMPLES, DONORS, FILE_FORMATS } = SUMMARY;
const { BIOSAMPLES, DONORS, FILE_FORMATS, TOTAL_FILE_SIZE } = SUMMARY;

/**
* Summary display order.
*/
export const SUMMARIES = [BIOSAMPLES, DONORS, FILE_FORMATS];
export const SUMMARIES = [BIOSAMPLES, DONORS, FILE_FORMATS, TOTAL_FILE_SIZE];
Loading