@@ -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.
0 commit comments