Skip to content

Commit cd8b42e

Browse files
authored
feat: add a total file size summary to the summary statistics line for the anvil explorer (#4495) (#4571)
1 parent 417aa7d commit cd8b42e

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

app/components/Index/common/constants.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
calculateSummaryTotalCellCount,
66
getSummaryCount,
77
} from "./utils";
8+
import { formatCountSize } from "@databiosphere/findable-ui/lib/utils/formatCountSize";
9+
import { formatFileSize } from "@databiosphere/findable-ui/lib/utils/formatFileSize";
810

911
// Template constants
1012
const {
@@ -53,24 +55,29 @@ const {
5355
FILES,
5456
SPECIES,
5557
SPECIMENS,
58+
TOTAL_FILE_SIZE,
5659
} = SUMMARY;
5760

5861
/**
5962
* Functions binding summary response API to summary count.
6063
*/
6164
export const BIND_SUMMARY_RESPONSE = {
62-
[BIOSAMPLES]: (r: AzulSummaryResponse): number =>
63-
getSummaryCount(r, SUMMARY_KEY.BIOSAMPLES),
64-
[DONORS]: (r: AzulSummaryResponse): number =>
65-
getSummaryCount(r, SUMMARY_KEY.DONORS),
66-
[ESTIMATED_CELLS]: calculateSummaryTotalCellCount,
67-
[FILES]: (r: AzulSummaryResponse): number =>
68-
getSummaryCount(r, SUMMARY_KEY.FILES),
69-
[FILE_FORMATS]: calculateSummaryFileFormatsCount,
70-
[SPECIES]: (r: AzulSummaryResponse): number =>
71-
getSummaryCount(r, SUMMARY_KEY.SPECIES),
72-
[SPECIMENS]: (r: AzulSummaryResponse): number =>
73-
getSummaryCount(r, SUMMARY_KEY.SPECIMENS),
65+
[BIOSAMPLES]: (r: AzulSummaryResponse): string =>
66+
formatCountSize(getSummaryCount(r, SUMMARY_KEY.BIOSAMPLES)),
67+
[DONORS]: (r: AzulSummaryResponse): string =>
68+
formatCountSize(getSummaryCount(r, SUMMARY_KEY.DONORS)),
69+
[ESTIMATED_CELLS]: (r: AzulSummaryResponse): string =>
70+
formatCountSize(calculateSummaryTotalCellCount(r)),
71+
[FILES]: (r: AzulSummaryResponse): string =>
72+
formatCountSize(getSummaryCount(r, SUMMARY_KEY.FILES)),
73+
[FILE_FORMATS]: (r: AzulSummaryResponse): string =>
74+
formatCountSize(calculateSummaryFileFormatsCount(r)),
75+
[SPECIES]: (r: AzulSummaryResponse): string =>
76+
formatCountSize(getSummaryCount(r, SUMMARY_KEY.SPECIES)),
77+
[SPECIMENS]: (r: AzulSummaryResponse): string =>
78+
formatCountSize(getSummaryCount(r, SUMMARY_KEY.SPECIMENS)),
79+
[TOTAL_FILE_SIZE]: (r: AzulSummaryResponse): string =>
80+
formatFileSize(getSummaryCount(r, SUMMARY_KEY.TOTAL_FILE_SIZE)),
7481
};
7582

7683
export const NETWORK_KEYS = [
@@ -162,13 +169,14 @@ export const PLURALIZED_METADATA_LABEL = {
162169
/**
163170
* Set of possible summary keys.
164171
*/
165-
export const SUMMARY_KEY = {
172+
export const SUMMARY_KEY: Record<string, keyof AzulSummaryResponse> = {
166173
[BIOSAMPLES]: "biosampleCount",
167174
[DONORS]: "donorCount",
168175
[FILES]: "fileCount",
169176
[FILE_FORMATS]: "fileFormats",
170177
[SPECIES]: "speciesCount",
171178
[SPECIMENS]: "specimenCount",
179+
[TOTAL_FILE_SIZE]: "totalFileSize",
172180
} as const;
173181

174182
/**
@@ -182,4 +190,5 @@ export const SUMMARY_LABEL = {
182190
[FILE_FORMATS]: "Files",
183191
[SPECIES]: "Species",
184192
[SPECIMENS]: "Specimens",
193+
[TOTAL_FILE_SIZE]: "",
185194
};

app/components/Index/common/entities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ export enum SUMMARY {
5656
FILES = "FILES",
5757
SPECIES = "SPECIES",
5858
SPECIMENS = "SPECIMENS",
59+
TOTAL_FILE_SIZE = "TOTAL_FILE_SIZE",
5960
}

app/components/Index/common/indexTransformer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AzulSummaryResponse } from "@databiosphere/findable-ui/lib/apis/azul/common/entities";
2-
import { formatCountSize } from "@databiosphere/findable-ui/lib/utils/formatCountSize";
32
import {
43
BIND_SUMMARY_RESPONSE,
54
PLURALIZED_METADATA_LABEL,
@@ -30,7 +29,7 @@ export function mapSummary(
3029
): [string, string][] {
3130
return summaries.map((summary) => {
3231
const summaryBinderFn = BIND_SUMMARY_RESPONSE[summary];
33-
const count = formatCountSize(summaryBinderFn(summaryResponse));
32+
const count = summaryBinderFn(summaryResponse);
3433
const label = SUMMARY_LABEL[summary];
3534
return [count, label];
3635
});

e2e/anvil/anvil-index-export-button.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ test.describe("AnVIL Data Explorer Export", () => {
6060
// Test that each summary item is present in the export summary
6161
// with corresponding count.
6262
for (const [label, count] of summary) {
63+
// Total file size summary item has no label.
64+
if (!label) continue;
6365
const summaryItem = exportSummaryLocator
6466
.locator("> div")
6567
.filter({ hasText: label });
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { SUMMARY } from "app/components/Index/common/entities";
22

33
// Template constants
4-
const { BIOSAMPLES, DONORS, FILE_FORMATS } = SUMMARY;
4+
const { BIOSAMPLES, DONORS, FILE_FORMATS, TOTAL_FILE_SIZE } = SUMMARY;
55

66
/**
77
* Summary display order.
88
*/
9-
export const SUMMARIES = [BIOSAMPLES, DONORS, FILE_FORMATS];
9+
export const SUMMARIES = [BIOSAMPLES, DONORS, FILE_FORMATS, TOTAL_FILE_SIZE];

0 commit comments

Comments
 (0)