-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathviewModelBuilders.ts
1556 lines (1467 loc) · 51.2 KB
/
viewModelBuilders.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {
LABEL,
MANIFEST_DOWNLOAD_FORMAT,
} from "@databiosphere/findable-ui/lib/apis/azul/common/entities";
import {
Filters,
SelectedFilter,
} from "@databiosphere/findable-ui/lib/common/entities";
import { ALERT_PROPS } from "@databiosphere/findable-ui/lib/components/common/Alert/constants";
import { Breadcrumb } from "@databiosphere/findable-ui/lib/components/common/Breadcrumbs/breadcrumbs";
import { CallToAction } from "@databiosphere/findable-ui/lib/components/common/Button/components/CallToActionButton/callToActionButton";
import { STATUS_BADGE_COLOR } from "@databiosphere/findable-ui/lib/components/common/StatusBadge/statusBadge";
import {
FileSummaryFacet,
FileSummaryTerm,
FormFacet,
} from "@databiosphere/findable-ui/lib/components/Export/common/entities";
import { CurrentQuery } from "@databiosphere/findable-ui/lib/components/Export/components/ExportSummary/components/ExportCurrentQuery/exportCurrentQuery";
import { Summary } from "@databiosphere/findable-ui/lib/components/Export/components/ExportSummary/components/ExportSelectedDataSummary/exportSelectedDataSummary";
import { ANCHOR_TARGET } from "@databiosphere/findable-ui/lib/components/Links/common/entities";
import { ViewContext } from "@databiosphere/findable-ui/lib/config/entities";
import {
FILE_MANIFEST_TYPE,
FileFacet,
} from "@databiosphere/findable-ui/lib/hooks/useFileManifest/common/entities";
import {
findFacet,
isFacetTermSelected,
sortTerms,
} from "@databiosphere/findable-ui/lib/hooks/useFileManifest/common/utils";
import { FileManifestState } from "@databiosphere/findable-ui/lib/providers/fileManifestState";
import { SIZE } from "@databiosphere/findable-ui/lib/styles/common/constants/size";
import { CategoryKeyLabel } from "@databiosphere/findable-ui/lib/viewModelBuilders/common/entities";
import {
mapCategoryKeyLabel,
sanitizeString,
} from "@databiosphere/findable-ui/lib/viewModelBuilders/common/utils";
import {
ChipProps as MChipProps,
FadeProps as MFadeProps,
} from "@mui/material";
import React, { ReactNode } from "react";
import {
ANVIL_CMG_CATEGORY_KEY,
ANVIL_CMG_CATEGORY_LABEL,
DATASET_RESPONSE,
} from "../../../../../site-config/anvil-cmg/category";
import {
ROUTE_EXPORT_TO_TERRA,
ROUTE_MANIFEST_DOWNLOAD,
} from "../../../../../site-config/anvil-cmg/dev/export/constants";
import { URL_DATASETS } from "../../../../../site-config/anvil/dev/config";
import {
AggregatedBioSampleResponse,
AggregatedDatasetResponse,
AggregatedDiagnosisResponse,
AggregatedDonorResponse,
} from "../../../../apis/azul/anvil-cmg/common/aggregatedEntities";
import {
ActivityEntityResponse,
BioSampleEntityResponse,
DonorEntityResponse,
FileEntityResponse,
FileFormat,
LibraryEntityResponse,
} from "../../../../apis/azul/anvil-cmg/common/entities";
import {
DatasetsResponse,
FilesResponse,
SummaryResponse,
} from "../../../../apis/azul/anvil-cmg/common/responses";
import {
getActivityDataModalities,
getActivityType,
getAggregatedBioSampleTypes,
getAggregatedDatasetIds,
getAggregatedDatasetTitles,
getAggregatedDiagnoses,
getAggregatedOrganismTypes,
getAggregatedPhenotypicSexes,
getAggregatedReportedEthnicities,
getAnatomicalSite,
getBioSampleId,
getBioSampleType,
getConsentGroup,
getDatasetDetails,
getDatasetEntryId,
getDocumentId,
getDonorId,
getFileDataModalities,
getFileFormat,
getFileName,
getFileSize,
getLibraryId,
getOrganismType,
getPhenotypicSex,
getPrepMaterialName,
getReportedEthnicities,
} from "../../../../apis/azul/anvil-cmg/common/transformers";
import {
processEntityArrayValue,
processEntityValue,
} from "../../../../apis/azul/common/utils";
import * as C from "../../../../components";
import * as MDX from "../../../../components/common/MDXContent/anvil-cmg";
import { Description } from "../../../../components/Detail/components/MDX/components/Description/description";
import { ExportMethod } from "../../../../components/Export/components/AnVILExplorer/ExportMethod/exportMethod";
import { METADATA_KEY } from "../../../../components/Index/common/entities";
import { getPluralizedMetadataLabel } from "../../../../components/Index/common/indexTransformer";
import { FEATURE_FLAGS } from "../../../common/contants";
import { Unused, Void } from "../../../common/entities";
import { SUMMARY_DISPLAY_TEXT } from "./summaryMapper/constants";
import { mapExportSummary } from "./summaryMapper/summaryMapper";
import { ExportEntity } from "app/components/Export/components/AnVILExplorer/components/ExportEntity/exportEntity";
import { RequestAccess } from "../../../../components/Detail/components/AnVILCMG/components/RequestAccess/requestAccess";
/**
* Build props for activity type BasicCell component from the given activities response.
* @param response - Response model return from activities API.
* @returns model to be used as props for the BasicCell component.
*/
export const buildActivityType = (
response: ActivityEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getActivityType(response),
};
};
/**
* Build props for dataset-related export warning Alert component.
* @param _ - Unused.
* @param viewContext - View context.
* @returns model to be used as props for the Alert component.
*/
export const buildAlertDatasetExportWarning = (
_: Unused,
viewContext: ViewContext<Unused>
): React.ComponentProps<typeof MDX.Alert> => {
const content = isUserAuthenticated(viewContext)
? "To export this dataset, please request access."
: "To export this dataset, please sign in and, if necessary, request access.";
return {
...ALERT_PROPS.STANDARD_WARNING,
component: C.FluidPaper,
content,
};
};
/**
* Build props for entity related download manifest warning Alert component.
* @param _ - Unused.
* @param viewContext - View context.
* @returns model to be used as props for the Alert component.
*/
export const buildAlertDatasetManifestDownloadWarning = (
_: Unused,
viewContext: ViewContext<Unused>
): React.ComponentProps<typeof MDX.Alert> => {
const content = isUserAuthenticated(viewContext)
? "To download this dataset manifest, please request access."
: "To download this dataset manifest, please sign in and, if necessary, request access.";
return {
...ALERT_PROPS.STANDARD_WARNING,
component: C.FluidPaper,
content,
};
};
/**
* Build props for dataset-related export warning Alert component.
* @param _ - Unused.
* @param viewContext - View context.
* @returns model to be used as props for the Alert component.
*/
export const buildAlertDatasetTerraExportWarning = (
_: Unused,
viewContext: ViewContext<Unused>
): React.ComponentProps<typeof MDX.Alert> => {
const {
exploreState: { featureFlagState },
} = viewContext;
const content = featureFlagState?.includes(FEATURE_FLAGS.VERBATIM)
? isUserAuthenticated(viewContext)
? "To export this dataset, please request access."
: "To export this dataset, please sign in and, if necessary, request access."
: "Export functionality is currently under development. Check back soon for updates.";
return {
...ALERT_PROPS.STANDARD_WARNING,
component: C.FluidPaper,
content,
};
};
/**
* Build props for list view access warning Alert component.
* @param _ - Unused.
* @param viewContext - View context.
* @returns model to be used as props for the Alert component.
*/
export const buildAlertEntityListWarning = (
_: Unused,
viewContext: ViewContext<unknown>
): React.ComponentProps<typeof MDX.AlertEntityListWarning> => {
return {
...ALERT_PROPS.STANDARD_WARNING,
component: C.FluidPaper,
entityName: viewContext.entityConfig.label,
};
};
/**
* Build props for export warning Alert component.
* @param _ - Unused.
* @param viewContext - View context.
* @returns model to be used as props for the Alert component.
*/
export const buildAlertExportWarning = (
_: Unused,
viewContext: ViewContext<unknown>
): React.ComponentProps<typeof MDX.AlertExportWarning> => {
const isAuthenticated = isUserAuthenticated(viewContext);
return {
...ALERT_PROPS.STANDARD_WARNING,
component: C.FluidPaper,
content: isAuthenticated ? null : MDX.AlertExportWarningContent({}),
size: isAuthenticated ? SIZE.MEDIUM : SIZE.LARGE,
};
};
/**
* Build props for anatomical site BasicCell component from the given index/biosamples response.
* @param response - Response model return from index/biosamples API.
* @returns model to be used as props for the BasicCell component.
*/
export const buildAnatomicalSite = (
response: BioSampleEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getAnatomicalSite(response),
};
};
/**
* Build props for biosample id BasicCell component from the given index/biosamples response.
* @param response - Response model return from index/biosamples API.
* @returns model to be used as props for the BasicCell component.
*/
export const buildBioSampleId = (
response: BioSampleEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getBioSampleId(response),
};
};
/**
* Build props for biosample type BasicCell component from the given index/biosamples response.
* @param response - Response model return from index/biosamples API.
* @returns model to be used as props for the BasicCell component.
*/
export const buildBioSampleType = (
response: BioSampleEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getBioSampleType(response),
};
};
/**
* Build biosample types NTagCell component from the given entity response.
* @param response - Response model return from Azul that includes aggregated biosamples.
* @returns model to be used as props for the NTagCell component.
*/
export const buildBioSampleTypes = (
response: AggregatedBioSampleResponse
): React.ComponentProps<typeof C.NTagCell> => {
return {
label: getPluralizedMetadataLabel(METADATA_KEY.BIOSAMPLE_TYPE),
values: getAggregatedBioSampleTypes(response),
};
};
/**
* Build props for consent group BasicCell component from the given datasets response.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the BasicCell component.
*/
export const buildConsentGroup = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getConsentGroup(datasetsResponse),
};
};
/**
* Build props for data modality NTagCell component from the given activities response.
* @param response - Response model return from index/activities API.
* @returns model to be used as props for the NTagCell component.
*/
export const buildDataModality = (
response: ActivityEntityResponse
): React.ComponentProps<typeof C.NTagCell> => {
return {
label: getPluralizedMetadataLabel(METADATA_KEY.DATA_MODALITY),
values: getActivityDataModalities(response),
};
};
/**
* Build dataset StatusBadge component from the given datasets response.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the StatusBadge component.
*/
export const buildDatasetAccess = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.StatusBadge> => {
const isAccessGranted = isDatasetAccessible(datasetsResponse);
const color = isAccessGranted
? STATUS_BADGE_COLOR.SUCCESS
: STATUS_BADGE_COLOR.WARNING;
const label = isAccessGranted ? "Granted" : "Required";
return {
color,
label,
};
};
/**
* Returns AccessibilityBadge component from the given datasets response.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the AccessibilityBadge component.
*/
export function buildDatasetAccessibilityBadge(
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.AccessibilityBadge> {
const badgeProps = getDatasetStatusBadge(datasetsResponse);
const fadeProps = getAccessibleTransition(datasetsResponse);
return { badgeProps, fadeProps };
}
/**
* Build props for Description component from the given entity response.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the Description component.
*/
export const buildDatasetDescription = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof Description> => {
return {
content:
processEntityValue(
datasetsResponse.datasets,
"description",
LABEL.EMPTY
) || "To be provided.",
};
};
/**
* Build props for Details component from the given datasets response.
* TODO revisit - separate from entity builder, generalize modeling/component?, revisit transformer
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the Details component.
*/
export const buildDatasetDetails = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.Details> => {
return {
keyValuePairs: getDatasetDetails(datasetsResponse),
title: "Dataset Details",
};
};
/**
* Build base breadcrumbs for dataset export. Includes link to all datasets and
* the selected dataset.
* @param datasetsResponse - Response model return from datasets API.
* @returns array of breadcrumbs to be used by dataset export and dataset export method pages.
*/
export function buildDatasetExportBreadcrumbs(
datasetsResponse: DatasetsResponse
): Breadcrumb[] {
const datasetPath = buildDatasetPath(datasetsResponse);
const datasetTitle = getDatasetTitle(datasetsResponse);
return [
{ path: URL_DATASETS, text: "Datasets" },
{ path: datasetPath, text: datasetTitle },
];
}
/**
* Build props for dataset export BackPageHero component.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the BackPageHero component.
*/
export function buildDatasetExportHero(
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.BackPageHero> {
return {
breadcrumbs: [
...buildDatasetExportBreadcrumbs(datasetsResponse),
{ path: "", text: "Choose Export Method" },
],
title: getDatasetTitle(datasetsResponse),
};
}
/**
* Returns breadcrumbs and title for dataset export method Hero component.
* @param datasetsResponse - Response model return from datasets API.
* @param title - Short export method description (e.g. Request File Manifest).
* @returns model to be used as props for the Hero component.
*/
function getDatasetExportMethodHero(
datasetsResponse: DatasetsResponse,
title: string
): React.ComponentProps<typeof C.BackPageHero> {
const datasetPath = buildDatasetPath(datasetsResponse);
return {
breadcrumbs: [
...buildDatasetExportBreadcrumbs(datasetsResponse),
{ path: `${datasetPath}/export`, text: "Choose Export Method" },
{ path: "", text: title },
],
title: getDatasetTitle(datasetsResponse),
};
}
/**
* Build props for dataset manifest download BackPageHero component.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the BackPageHero component.
*/
export const buildDatasetExportMethodHeroManifestDownload = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.BackPageHero> => {
const title = "File Manifest";
return getDatasetExportMethodHero(datasetsResponse, title);
};
/**
* Build props for dataset manifest download BackPageHero component.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the BackPageHero component.
*/
export const buildDatasetExportMethodHeroTerraExport = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.BackPageHero> => {
const title = "Analyze in Terra";
return getDatasetExportMethodHero(datasetsResponse, title);
};
/**
* Build props for ExportMethod component for display of the dataset manifest download section.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the dataset file manifest export method component.
*/
export const buildDatasetExportMethodManifestDownload = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.ExportMethod> => {
const datasetPath = buildDatasetPath(datasetsResponse);
return {
buttonLabel: "Request File Manifest",
description:
"Request a file manifest suitable for downloading this dataset to your HPC cluster or local machine.",
route: `${datasetPath}${ROUTE_MANIFEST_DOWNLOAD}`,
title: "Download a File Manifest with Metadata",
};
};
/**
* Build props for either the ExportEntity component for the display of the choose export methods or
* the AnVILManifestDownloadEntity component for the display of the manifest download method.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the ExportEntity component.
*/
export const buildDatasetExportPropsWithFilter = (
datasetsResponse: DatasetsResponse
):
| React.ComponentProps<typeof ExportEntity>
| typeof C.AnVILManifestDownloadEntity => {
return {
filters: getExportEntityFilters(datasetsResponse),
};
};
/**
* Build props for ExportMethod component for display of the export to terra metadata section.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the dataset Terra export method component.
*/
export const buildDatasetExportMethodTerra = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof ExportMethod> => {
const datasetPath = buildDatasetPath(datasetsResponse);
return {
buttonLabel: "Analyze in Terra",
description:
"Terra is a biomedical research platform to analyze data using workflows, Jupyter Notebooks, RStudio, and Galaxy.",
route: `${datasetPath}${ROUTE_EXPORT_TO_TERRA}`,
title: "Export Dataset Data and Metadata to Terra Workspace",
};
};
/**
* Build props for BackPageHero component from the given datasets response.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the BackPageHero component.
*/
export const buildDatasetHero = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.BackPageHero> => {
return {
actions: getDatasetRequestAccess(datasetsResponse),
breadcrumbs: getDatasetBreadcrumbs(datasetsResponse),
callToAction: getDatasetCallToAction(datasetsResponse),
title: getDatasetTitle(datasetsResponse),
};
};
/**
* Build dataset ID NTagCell component from the given entity response.
* @param response - Response model return from Azul that includes aggregated datasets.
* @returns model to be used as props for theNTagCell component.
*/
export const buildDatasetIds = (
response: AggregatedDatasetResponse
): React.ComponentProps<typeof C.NTagCell> => {
return {
label: getPluralizedMetadataLabel(METADATA_KEY.DATASET_NAME),
values: getAggregatedDatasetIds(response),
};
};
/**
* Build path to dataset from the given datasets response.
* @param datasetsResponse - Response model return from datasets API.
* @returns path to the dataset.
*/
export function buildDatasetPath(datasetsResponse: DatasetsResponse): string {
const datasetId = getDatasetEntryId(datasetsResponse);
return `${URL_DATASETS}/${datasetId}`;
}
/**
* Build props for dataset ExportToTerra component.
* @param datasetsResponse - Response model return from datasets API.
* @param viewContext - View context.
* @returns model to be used as props for the ExportToTerra component.
*/
export const builDatasetTerraExport = (
datasetsResponse: DatasetsResponse,
viewContext: ViewContext<DatasetsResponse>
): React.ComponentProps<typeof C.ExportToTerra> => {
const { fileManifestState } = viewContext;
// Get the initial filters.
const filters = getExportEntityFilters(datasetsResponse);
// Grab the form facet.
const formFacet = getFormFacets(fileManifestState);
return {
ExportForm: C.ExportToTerraForm,
ExportToTerraStart: MDX.ExportToTerraStart,
ExportToTerraSuccess: MDX.ExportToTerraSuccess,
fileManifestState,
fileManifestType: FILE_MANIFEST_TYPE.ENTITY_EXPORT_TO_TERRA,
fileSummaryFacetName: ANVIL_CMG_CATEGORY_KEY.FILE_FILE_FORMAT,
filters,
formFacet,
manifestDownloadFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
manifestDownloadFormats: [MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB],
};
};
/**
* Build dataset title Link component from the given datasets response.
* @param datasetsResponse - Response model return from datasets API.
* @returns model to be used as props for the Link component.
*/
export const buildDatasetTitle = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.Link> => {
return {
label: getDatasetTitle(datasetsResponse),
url: `/datasets/${getDatasetEntryId(datasetsResponse)}`,
};
};
/**
* Build dataset ID NTagCell component from the given entity response.
* @param response - Response model return from Azul that includes aggregated datasets.
* @returns model to be used as props for the NTagCell component.
*/
export const buildDatasetTitles = (
response: AggregatedDatasetResponse
): React.ComponentProps<typeof C.NTagCell> => {
return {
label: getPluralizedMetadataLabel(METADATA_KEY.DATASET_NAME),
values: getAggregatedDatasetTitles(response),
};
};
/**
* Build props for diagnosis type NTagCell component from the given entity response.
* @param response - Response model return from Azul that includes aggregated diagnoses.
* @returns model to be used as props for the NTagCell component.
*/
export const buildDiagnoses = (
response: AggregatedDiagnosisResponse
): React.ComponentProps<typeof C.NTagCell> => {
return {
label: getPluralizedMetadataLabel(METADATA_KEY.DIAGNOSIS),
values: getAggregatedDiagnoses(response),
};
};
/**
* Build props for donor ID BasicCell component from the given donors response.
* @param response - Response model return from index/donors API endpoint.
* @returns model to be used as props for the BasicCell component.
*/
export const buildDonorId = (
response: DonorEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getDonorId(response),
};
};
/**
* Build props for document ID BasicCell component from the given activities response.
* @param response - Response model return from activities API.
* @returns model to be used as props for the BasicCell component.
*/
export const buildDocumentId = (
response: ActivityEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getDocumentId(response),
};
};
/**
* Build props for DRS URI CopyCell component from the given files response.
* @param filesResponse - Response model return from index/files API endpoint.
* @returns model to be used as props for the CopyCell component.
*/
export const buildDRSURI = (
filesResponse: FilesResponse
): React.ComponentProps<typeof C.CopyCell> => {
return {
value: processEntityValue(filesResponse.files, "drs_uri"),
};
};
/**
* Build props for ExportCurrentQuery component.
* @param datasetsResponse - Response model returned from datasets API.
* @param viewContext - View context.
* @returns model to be used as props for the ExportCurrentQuery component.
*/
export const buildExportCurrentQuery = (
datasetsResponse: DatasetsResponse,
viewContext: ViewContext<DatasetsResponse>
): React.ComponentProps<typeof C.ExportCurrentQuery> => {
return {
isLoading: viewContext.fileManifestState.isFacetsLoading,
queries: getExportCurrentQueries(
getExportCurrentQuerySelectedFilters(datasetsResponse, viewContext)
),
};
};
/**
* Build props for export BackPageHero component.
* @param _ - Void.
* @param viewContext - View context.
* @returns model to be used as props for the BackPageHero component.
*/
export function buildExportHero(
_: Void,
viewContext: ViewContext<Void>
): React.ComponentProps<typeof C.BackPageHero> {
const { exploreState } = viewContext;
const { tabValue } = exploreState || {};
return {
breadcrumbs: [
{ path: `/${tabValue}`, text: "Explore" },
{ path: "", text: "Export Selected Data" },
],
title: "Choose Export Method",
};
}
/**
* Build props for manifest download BackPageHero component.
* @param _ - Void.
* @param viewContext - View context.
* @returns model to be used as props for the BackPageHero component.
*/
export const buildExportMethodHeroManifestDownload = (
_: Void,
viewContext: ViewContext<Void>
): React.ComponentProps<typeof C.BackPageHero> => {
const title = "Request File Manifest";
const {
exploreState: { tabValue },
} = viewContext;
return getExportMethodHero(tabValue, title);
};
/**
* Build props for export to terra BackPageHero component.
* @param _ - Void.
* @param viewContext - View context.
* @returns model to be used as props for the BackPageHero component.
*/
export const buildExportMethodHeroTerra = (
_: Void,
viewContext: ViewContext<Void>
): React.ComponentProps<typeof C.BackPageHero> => {
const title = "Export to Terra";
const {
exploreState: { tabValue },
} = viewContext;
return getExportMethodHero(tabValue, title);
};
/**
* Build props for ExportMethod component for display of the manifest download section.
* @param _ - Void.
* @param viewContext - View context.
* @returns model to be used as props for the ExportMethod component.
*/
export const buildExportMethodManifestDownload = (
_: Void,
viewContext: ViewContext<Void>
): React.ComponentProps<typeof C.ExportMethod> => {
return {
...getExportMethodAccessibility(viewContext),
buttonLabel: "Request File Manifest",
description:
"Request a file manifest for the current query containing the full list of selected files and the metadata for each file.",
route: ROUTE_MANIFEST_DOWNLOAD,
title: "Download a File Manifest with Metadata for the Selected Data",
};
};
/**
* Build props for ExportMethod component for display of the export to terra metadata section.
* @param _ - Void.
* @param viewContext - View context.
* @returns model to be used as props for the ExportMethod component.
*/
export const buildExportMethodTerra = (
_: Void,
viewContext: ViewContext<Void>
): React.ComponentProps<typeof ExportMethod> => {
return {
...getExportMethodAccessibility(viewContext),
buttonLabel: "Analyze in Terra",
description:
"Terra is a biomedical research platform to analyze data using workflows, Jupyter Notebooks, RStudio, and Galaxy.",
route: ROUTE_EXPORT_TO_TERRA,
title: "Export Study Data and Metadata to Terra Workspace",
};
};
/**
* Build props for ExportSelectedDataSummary component.
* @param _ - Void.
* @param viewContext - View context.
* @returns model to be used as props for the ExportSelectedDataSummary component.
*/
export const buildExportSelectedDataSummary = (
_: Void,
viewContext: ViewContext<Void>
): React.ComponentProps<typeof C.ExportSelectedDataSummary> => {
const {
fileManifestState: {
filesFacets,
isFacetsLoading,
isSummaryLoading,
summary,
},
} = viewContext;
return {
isLoading: isFacetsLoading || isSummaryLoading,
summaries: getExportSelectedDataSummary(filesFacets, summary),
};
};
/**
* Build props for ExportToTerra component.
* @param _ - Void.
* @param viewContext - View context.
* @returns model to be used as props for the ExportToTerra component.
*/
export const buildExportToTerra = (
_: Void,
viewContext: ViewContext<Void>
): React.ComponentProps<typeof C.ExportToTerra> => {
const {
exploreState: { filterState },
fileManifestState,
} = viewContext;
// Grab the form facet.
const formFacet = getFormFacets(fileManifestState);
return {
ExportForm: C.ExportToTerraForm,
ExportToTerraStart: MDX.ExportToTerraStart,
ExportToTerraSuccess: MDX.ExportToTerraSuccess,
fileManifestState,
fileManifestType: FILE_MANIFEST_TYPE.EXPORT_TO_TERRA,
fileSummaryFacetName: ANVIL_CMG_CATEGORY_KEY.FILE_FILE_FORMAT,
filters: filterState,
formFacet,
manifestDownloadFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
manifestDownloadFormats: [MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB],
};
};
/**
* Build props for file data modality NTagCell component from the given files response.
* @param response - Response model return from index/files API endpoint.
* @returns model to be used as props for the NTagCell component.
*/
export const buildFileDataModality = (
response: FileEntityResponse
): React.ComponentProps<typeof C.NTagCell> => {
return {
label: getPluralizedMetadataLabel(METADATA_KEY.DATA_MODALITY),
values: getFileDataModalities(response),
};
};
/**
* Build props for file download AzulFileDownload component.
* @param response - Response model returned from index/files API endpoint.
* @returns model to be used as props for the AzulFileDownload component.
*/
export const buildFileDownload = (
response: FilesResponse
): React.ComponentProps<typeof C.AzulFileDownload> => {
const dataset = response.datasets[0];
return {
entityName: processEntityValue(response.files, "file_name"),
relatedEntityId: dataset.dataset_id[0],
relatedEntityName: dataset.title[0],
url: processEntityValue(response.files, "url", LABEL.EMPTY),
};
};
/**
* Build props for file ID BasicCell component from the given files response.
* @param response - Response model return from index/files API endpoint.
* @returns model to be used as props for the BasicCell component.
*/
export const buildFileName = (
response: FileEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getFileName(response),
};
};
/**
* Build props for file format BasicCell component from the given files response.
* @param response - Response model return from index/files API endpoint.
* @returns model to be used as props for the BasicCell component.
*/
export const buildFileFormat = (
response: FileEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getFileFormat(response),
};
};
/**
* Build props for file size BasicCell component from the given files response.
* @param response - Response model return from index/files API endpoint.
* @returns model to be used as props for the BasicCell component.
*/
export const buildFileSize = (
response: FileEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getFileSize(response),
};
};
/**
* Build props for library ID BasicCell component from the given libraries response.
* @param response - Response model return from index/libraries API endpoint.
* @returns model to be used as props for the BasicCell component.
*/
export const buildLibraryId = (
response: LibraryEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getLibraryId(response),
};
};
/**
* Build props for ManifestDownload component.
* @param _ - Void.
* @param viewContext - View context.
* @returns model to be used as props for the ManifestDownload component.
*/
export const buildManifestDownload = (
_: Void,
viewContext: ViewContext<Void>
): React.ComponentProps<typeof C.ManifestDownload> => {
const {
exploreState: { filterState },
fileManifestState,
} = viewContext;
// Get the form facets.
const formFacet = getFormFacets(fileManifestState);
return {
ManifestDownloadForm: C.ManifestDownloadForm,
ManifestDownloadStart: MDX.ManifestDownloadStart,
ManifestDownloadSuccess: MDX.ManifestDownloadSuccess,
fileManifestState,
fileManifestType: FILE_MANIFEST_TYPE.DOWNLOAD_MANIFEST,
fileSummaryFacetName: ANVIL_CMG_CATEGORY_KEY.FILE_FILE_FORMAT,
filters: filterState,
formFacet,
};
};
/**
* Build props for organism type BasicCell component from the given donors response.
* @param response - Response model return from index/donors API endpoint.
* @returns model to be used as props for the BasicCell component.
*/
export const buildOrganismType = (
response: DonorEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getOrganismType(response),
};
};
/**
* Build props for organism type NTagCell component from the given entity response.
* @param response - Response model return from Azul that includes aggregated donors.
* @returns model to be used as props for the NTagCell component.
*/
export const buildOrganismTypes = (
response: AggregatedDonorResponse
): React.ComponentProps<typeof C.NTagCell> => {
return {
label: getPluralizedMetadataLabel(METADATA_KEY.ORGANISM_TYPE),
values: getAggregatedOrganismTypes(response),
};
};
/**
* Build props for phenotypic sex BasicCell component from the given donors response.
* @param response - Response model return from index/donors API endpoint.
* @returns model to be used as props for the BasicCell component.
*/
export const buildPhenotypicSex = (
response: DonorEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getPhenotypicSex(response),
};
};
/**
* Build props for phenotypic sex NTagCell component from the given donors response.
* @param response - Response model return from index/donors API endpoint.
* @returns model to be used as props for the NTagCell component.
*/
export const buildPhenotypicSexes = (
response: AggregatedDonorResponse
): React.ComponentProps<typeof C.NTagCell> => {
return {
label: getPluralizedMetadataLabel(METADATA_KEY.PHENOTYPIC_SEX),
values: getAggregatedPhenotypicSexes(response),
};
};
/**
* Build props for prep material name BasicCell component from the given libraries response.
* @param response - Response model return from index/libraries API endpoint.
* @returns model to be used as props for the BasicCell component.
*/
export const buildPrepMaterialName = (
response: LibraryEntityResponse
): React.ComponentProps<typeof C.BasicCell> => {
return {
value: getPrepMaterialName(response),
};
};