Skip to content

Commit 3c7e64d

Browse files
authored
feat: make dataset detail export to terra to select all in the initial view (#4383) (#4390)
1 parent 5a7502f commit 3c7e64d

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

app/apis/azul/anvil-cmg/common/aggregatedEntities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface AggregatedDatasetResponse {
5454
* /index/libraries).
5555
*/
5656
export interface AggregatedDonor {
57-
organism_type: string[];
57+
organism_type: (string | null)[];
5858
phenotypic_sex: string[];
5959
reported_ethnicity: string[];
6060
}
@@ -89,8 +89,8 @@ export interface AggregatedDiagnosisResponse {
8989
* /index/libraries).
9090
*/
9191
export interface AggregatedFile {
92-
data_modality: string[];
93-
file_format: string;
92+
data_modality: (string | null)[];
93+
file_format: string[];
9494
file_id: string;
9595
file_type: string;
9696
}

app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,13 @@ export function buildDatasetPath(datasetsResponse: DatasetsResponse): string {
524524
* @param viewContext - View context.
525525
* @returns model to be used as props for the ExportToTerra component.
526526
*/
527-
export const builDatasetTerraExport = (
527+
export const buildDatasetTerraExport = (
528528
datasetsResponse: DatasetsResponse,
529529
viewContext: ViewContext<DatasetsResponse>
530530
): React.ComponentProps<typeof C.ExportToTerra> => {
531531
const { fileManifestState } = viewContext;
532532
// Get the initial filters.
533-
const filters = getExportEntityFilters(datasetsResponse);
533+
const filters = getExportTerraEntityFilters(datasetsResponse);
534534
// Grab the form facet.
535535
const formFacet = getFormFacets(fileManifestState);
536536
return {
@@ -1262,6 +1262,31 @@ export function getExportSelectedDataSummary(
12621262
]);
12631263
}
12641264

1265+
/**
1266+
* Returns the export to terra entity filters for the given datasets response.
1267+
* Includes dataset ID, donor organism type, and file format.
1268+
* @param datasetsResponse - Response model return from datasets API.
1269+
* @returns export to terra entity filters.
1270+
*/
1271+
function getExportTerraEntityFilters(
1272+
datasetsResponse: DatasetsResponse
1273+
): Filters {
1274+
return [
1275+
...getExportEntityFilters(datasetsResponse),
1276+
{
1277+
categoryKey: ANVIL_CMG_CATEGORY_KEY.DONOR_ORGANISM_TYPE,
1278+
value: processRawEntityArrayValue(
1279+
datasetsResponse.donors,
1280+
"organism_type"
1281+
),
1282+
},
1283+
{
1284+
categoryKey: ANVIL_CMG_CATEGORY_KEY.FILE_FILE_FORMAT,
1285+
value: processRawEntityArrayValue(datasetsResponse.files, "file_format"),
1286+
},
1287+
];
1288+
}
1289+
12651290
/**
12661291
* Returns the file summary facet, where facet terms are generated from the file summary.
12671292
* @param fileFacet - File facet.
@@ -1432,6 +1457,22 @@ function mapCurrentQuery(
14321457
];
14331458
}
14341459

1460+
/**
1461+
* Processes entities and extracts unique string or null values
1462+
* from a specified key that holds an array of (string | null)[].
1463+
* @param responseValues - Response model return from API.
1464+
* @param key - The key whose values (arrays of string or null) will be processed.
1465+
* @returns A unique list of string or null values.
1466+
*/
1467+
function processRawEntityArrayValue<
1468+
T extends Record<K, (string | null)[]>,
1469+
K extends keyof T,
1470+
>(responseValues: T[], key: K): (string | null)[] {
1471+
const flatValues = responseValues.flatMap((value) => value[key]);
1472+
const uniqueValues = new Set(flatValues);
1473+
return [...uniqueValues];
1474+
}
1475+
14351476
/**
14361477
* Renders configuration component children when the given authentication state is not authenticated.
14371478
* @param _ - Unused.

site-config/anvil-cmg/dev/detail/dataset/export/export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const exportConfig: ExportConfig = {
5454
children: [
5555
{
5656
component: C.ExportToTerra,
57-
viewBuilder: V.builDatasetTerraExport,
57+
viewBuilder: V.buildDatasetTerraExport,
5858
} as ComponentConfig<typeof C.ExportToTerra>,
5959
],
6060
component: C.BackPageContentMainColumn,

0 commit comments

Comments
 (0)