1
1
import { LABEL } from "@clevercanary/data-explorer-ui/lib/apis/azul/common/entities" ;
2
- import { Filters } from "@clevercanary/data-explorer-ui/lib/common/entities" ;
2
+ import {
3
+ Filters ,
4
+ SelectedFilter ,
5
+ } from "@clevercanary/data-explorer-ui/lib/common/entities" ;
3
6
import { Breadcrumb } from "@clevercanary/data-explorer-ui/lib/components/common/Breadcrumbs/breadcrumbs" ;
4
7
import {
5
8
Key ,
@@ -424,27 +427,6 @@ export const buildEstimateCellCount = (
424
427
} ;
425
428
} ;
426
429
427
- /**
428
- * Build props for entity related ExportCurrentQuery component.
429
- * @returns model to be used as props for the ExportCurrentQuery component.
430
- */
431
- export const buildExportEntityCurrentQuery = ( ) : React . ComponentProps <
432
- typeof C . ExportCurrentQuery
433
- > => {
434
- return {
435
- getExportCurrentQueries : (
436
- filters : Filters ,
437
- filesFacets : FileFacet [ ]
438
- ) : CurrentQuery [ ] => {
439
- // Grab the project facet.
440
- const projectFacet = getSelectedProjectFacet ( filesFacets ) ;
441
- // Initialize the selected facets with the project facet.
442
- const facets = projectFacet ? [ projectFacet ] : [ ] ;
443
- return getExportCurrentQueries ( filesFacets , facets ) ;
444
- } ,
445
- } ;
446
- } ;
447
-
448
430
/**
449
431
* Build props for ExportCurrentQuery component.
450
432
* @returns model to be used as props for the ExportCurrentQuery component.
@@ -454,7 +436,7 @@ export const buildExportCurrentQuery = (): React.ComponentProps<
454
436
> => {
455
437
return {
456
438
getExportCurrentQueries : ( filters : Filters , filesFacets : FileFacet [ ] ) =>
457
- getExportCurrentQueries ( filesFacets ) ,
439
+ getExportCurrentQueries ( filters , filesFacets ) ,
458
440
} ;
459
441
} ;
460
442
@@ -1070,28 +1052,23 @@ export function getEstimatedCellCount(
1070
1052
1071
1053
/**
1072
1054
* Returns current queries from the given selected file facets.
1055
+ * @param filters - Filters.
1073
1056
* @param filesFacets - Files facets.
1074
- * @param facets - Selected facets i.e. for entity related queries.
1075
1057
* @returns current queries.
1076
1058
*/
1077
1059
export function getExportCurrentQueries (
1078
- filesFacets : FileFacet [ ] ,
1079
- facets : FileFacet [ ] = [ ]
1060
+ filters : Filters ,
1061
+ filesFacets : FileFacet [ ]
1080
1062
) : CurrentQuery [ ] {
1081
1063
const categoryKeyLabel = mapCategoryKeyLabel (
1082
1064
HCA_DCP_CATEGORY_KEY ,
1083
1065
HCA_DCP_CATEGORY_LABEL
1084
1066
) ;
1085
- // Grab all selected facets.
1086
- // Entity related current queries should always return the project facet as a selected facet as there is no equivalent
1087
- // file facet for project id.
1088
- return filesFacets
1089
- . filter ( isFacetSelected )
1090
- . reduce ( ( acc , facet ) => {
1091
- acc . push ( facet ) ;
1092
- return acc ;
1093
- } , facets )
1094
- . map ( ( facet ) => mapCurrentQuery ( facet , categoryKeyLabel ) ) ;
1067
+ // Return all selected filters, as a list of current queries.
1068
+ // Replace any selected filter projectIds with project facet terms.
1069
+ return filters
1070
+ . map ( ( filter ) => mapProjectIdToProject ( filter , filesFacets ) )
1071
+ . map ( ( filter ) => mapCurrentQuery ( filter , categoryKeyLabel ) ) ;
1095
1072
}
1096
1073
1097
1074
/**
@@ -1135,6 +1112,17 @@ function getExportMethodHero(
1135
1112
} ;
1136
1113
}
1137
1114
1115
+ /**
1116
+ * Returns file facet term names.
1117
+ * @param facet - File facet.
1118
+ * @returns file facet term names.
1119
+ */
1120
+ function getFacetTerms ( facet : FileFacet | undefined ) : string [ ] {
1121
+ return (
1122
+ facet ?. terms . map ( ( { name } ) => sanitizeString ( name ) ) || [ LABEL . UNSPECIFIED ]
1123
+ ) ;
1124
+ }
1125
+
1138
1126
/**
1139
1127
* Returns generated matrices actions column def.
1140
1128
* @returns actions column def.
@@ -1324,27 +1312,6 @@ export function getProjectBreadcrumbs(
1324
1312
return breadcrumbs ;
1325
1313
}
1326
1314
1327
- /**
1328
- * Returns project facet as a selected facet, using the project terms as the selected terms.
1329
- * @param filesFacets - Files facets.
1330
- * @returns selected project facet.
1331
- */
1332
- function getSelectedProjectFacet (
1333
- filesFacets : FileFacet [ ]
1334
- ) : FileFacet | undefined {
1335
- const projectFacet = findProjectFacet ( filesFacets ) ;
1336
- if ( ! projectFacet ) {
1337
- return ;
1338
- }
1339
- return {
1340
- ...projectFacet ,
1341
- name : HCA_DCP_CATEGORY_KEY . PROJECT ,
1342
- selected : true , // Forcing project facet to be selected.
1343
- selectedTermCount : projectFacet . terms . length , // Selected term count will be equal to the number of terms.
1344
- selectedTerms : projectFacet . terms , // Selected terms will equal all terms.
1345
- } ;
1346
- }
1347
-
1348
1315
/**
1349
1316
* Returns project file formats from the projects API response.
1350
1317
* @param projectsResponse - Response returned from projects API response.
@@ -1383,37 +1350,32 @@ function getProjectTitleUrl(projectsResponse: ProjectsResponse): string {
1383
1350
}
1384
1351
1385
1352
/**
1386
- * Returns project file facet.
1353
+ * Returns file facet for the given facet name.
1354
+ * @param facetName - Facet name.
1387
1355
* @param filesFacets - Files facets.
1388
1356
* @returns project file facet.
1389
1357
*/
1390
- function findProjectFacet ( filesFacets : FileFacet [ ] ) : FileFacet | undefined {
1391
- return filesFacets . find ( ( { name } ) => name === HCA_DCP_CATEGORY_KEY . PROJECT ) ;
1392
- }
1393
-
1394
- /**
1395
- * Returns true if the facet is selected.
1396
- * @param facet - Facet.
1397
- * @returns returns true if the facet is selected.
1398
- */
1399
- function isFacetSelected ( facet : FileFacet ) : boolean {
1400
- return facet . selected ;
1358
+ function findFacet (
1359
+ facetName : string ,
1360
+ filesFacets : FileFacet [ ]
1361
+ ) : FileFacet | undefined {
1362
+ return filesFacets . find ( ( { name } ) => name === facetName ) ;
1401
1363
}
1402
1364
1403
1365
/**
1404
1366
* Returns current query for the given facet.
1405
- * @param facet - File facet .
1367
+ * @param filter - Selected filter .
1406
1368
* @param categoryKeyLabel - Map of category key to category label.
1407
1369
* @returns current query.
1408
1370
*/
1409
1371
function mapCurrentQuery (
1410
- facet : FileFacet ,
1372
+ filter : SelectedFilter ,
1411
1373
categoryKeyLabel : CategoryKeyLabel
1412
1374
) : CurrentQuery {
1413
- const { name , selectedTerms } = facet ;
1375
+ const { categoryKey , value : values } = filter ;
1414
1376
return [
1415
- categoryKeyLabel . get ( name ) || name ,
1416
- selectedTerms . map ( ( { name } ) => sanitizeString ( name ) ) ,
1377
+ categoryKeyLabel . get ( categoryKey ) || categoryKey ,
1378
+ values . map ( ( value ) => sanitizeString ( value ) ) ,
1417
1379
] ;
1418
1380
}
1419
1381
@@ -1441,6 +1403,26 @@ function mapFileTypeCounts(
1441
1403
) ;
1442
1404
}
1443
1405
1406
+ /**
1407
+ * Returns the project facet name and terms as a selected filter in lieu of selected filter of category project id.
1408
+ * @param filter - Selected filter.
1409
+ * @param filesFacets - Files facets.
1410
+ * @returns selected filter.
1411
+ */
1412
+ function mapProjectIdToProject (
1413
+ filter : SelectedFilter ,
1414
+ filesFacets : FileFacet [ ]
1415
+ ) : SelectedFilter {
1416
+ if ( filter . categoryKey === HCA_DCP_CATEGORY_KEY . PROJECT_ID ) {
1417
+ const projectFacet = findFacet ( HCA_DCP_CATEGORY_KEY . PROJECT , filesFacets ) ;
1418
+ return {
1419
+ categoryKey : HCA_DCP_CATEGORY_KEY . PROJECT ,
1420
+ value : getFacetTerms ( projectFacet ) ,
1421
+ } ;
1422
+ }
1423
+ return filter ;
1424
+ }
1425
+
1444
1426
/**
1445
1427
* Returns the aggregated total cells from cellSuspensions for the given entity response.
1446
1428
* @param entityResponse - Response model return from entity API.
0 commit comments