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
6 changes: 3 additions & 3 deletions app/apis/azul/anvil-cmg/common/aggregatedEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface AggregatedDatasetResponse {
* /index/libraries).
*/
export interface AggregatedDonor {
organism_type: string[];
organism_type: (string | null)[];
phenotypic_sex: string[];
reported_ethnicity: string[];
}
Expand Down Expand Up @@ -89,8 +89,8 @@ export interface AggregatedDiagnosisResponse {
* /index/libraries).
*/
export interface AggregatedFile {
data_modality: string[];
file_format: string;
data_modality: (string | null)[];
file_format: string[];
file_id: string;
file_type: string;
}
Expand Down
45 changes: 43 additions & 2 deletions app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,13 @@ export function buildDatasetPath(datasetsResponse: DatasetsResponse): string {
* @param viewContext - View context.
* @returns model to be used as props for the ExportToTerra component.
*/
export const builDatasetTerraExport = (
export const buildDatasetTerraExport = (
datasetsResponse: DatasetsResponse,
viewContext: ViewContext<DatasetsResponse>
): React.ComponentProps<typeof C.ExportToTerra> => {
const { fileManifestState } = viewContext;
// Get the initial filters.
const filters = getExportEntityFilters(datasetsResponse);
const filters = getExportTerraEntityFilters(datasetsResponse);
// Grab the form facet.
const formFacet = getFormFacets(fileManifestState);
return {
Expand Down Expand Up @@ -1262,6 +1262,31 @@ export function getExportSelectedDataSummary(
]);
}

/**
* Returns the export to terra entity filters for the given datasets response.
* Includes dataset ID, donor organism type, and file format.
* @param datasetsResponse - Response model return from datasets API.
* @returns export to terra entity filters.
*/
function getExportTerraEntityFilters(
datasetsResponse: DatasetsResponse
): Filters {
return [
...getExportEntityFilters(datasetsResponse),
{
categoryKey: ANVIL_CMG_CATEGORY_KEY.DONOR_ORGANISM_TYPE,
value: processRawEntityArrayValue(
datasetsResponse.donors,
"organism_type"
),
},
{
categoryKey: ANVIL_CMG_CATEGORY_KEY.FILE_FILE_FORMAT,
value: processRawEntityArrayValue(datasetsResponse.files, "file_format"),
},
];
}

/**
* Returns the file summary facet, where facet terms are generated from the file summary.
* @param fileFacet - File facet.
Expand Down Expand Up @@ -1432,6 +1457,22 @@ function mapCurrentQuery(
];
}

/**
* Processes entities and extracts unique string or null values
* from a specified key that holds an array of (string | null)[].
* @param responseValues - Response model return from API.
* @param key - The key whose values (arrays of string or null) will be processed.
* @returns A unique list of string or null values.
*/
function processRawEntityArrayValue<
T extends Record<K, (string | null)[]>,
K extends keyof T,
>(responseValues: T[], key: K): (string | null)[] {
const flatValues = responseValues.flatMap((value) => value[key]);
const uniqueValues = new Set(flatValues);
return [...uniqueValues];
}

/**
* Renders configuration component children when the given authentication state is not authenticated.
* @param _ - Unused.
Expand Down
2 changes: 1 addition & 1 deletion site-config/anvil-cmg/dev/detail/dataset/export/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const exportConfig: ExportConfig = {
children: [
{
component: C.ExportToTerra,
viewBuilder: V.builDatasetTerraExport,
viewBuilder: V.buildDatasetTerraExport,
} as ComponentConfig<typeof C.ExportToTerra>,
],
component: C.BackPageContentMainColumn,
Expand Down
Loading