Skip to content

Commit 04840ec

Browse files
Adapt single dataset view to new model (#227)
1 parent 20f5637 commit 04840ec

18 files changed

+214
-237
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "data-portal-ui",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"private": true,
55
"dependencies": {
66
"@fortawesome/fontawesome-svg-core": "~6.4.2",

src/components/browse/dataset/datasetAccordion/datasetAccordion.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ const DatasetAccordion = (props: DataSetListProps) => {
2626
}
2727
};
2828

29-
if (
30-
summary !== null &&
31-
summary !== undefined &&
32-
summaryMap.get(summary.accession) === null
33-
) {
29+
if (summary && summaryMap.get(summary.accession) === null) {
3430
setSummaryMap(summaryMap.set(summary.accession, summary));
3531
}
3632

src/components/browse/dataset/datasetAccordion/datasetSummary/datasetFiles.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const DatasetFiles = (props: DataSetFilesProps) => {
2020
<p className="mb-0">
2121
<strong>File summary</strong>
2222
</p>
23-
{props.files !== null ? (
23+
{props.files ? (
2424
<div>
2525
<p className="mb-0">
2626
<strong>{props.files.count}</strong> Files

src/components/browse/dataset/datasetAccordion/datasetSummary/datasetStudies.tsx

+8-11
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,30 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
55
import { faBook } from "@fortawesome/free-solid-svg-icons";
66

77
interface DataSetStudiesProps {
8-
study: StudySummaryModel | null;
8+
studies: StudySummaryModel | null;
99
}
1010

1111
/** Dataset summary section displays the studies of which the dataset is a part. */
1212
const DatasetStudies = (props: DataSetStudiesProps) => {
13+
const stats = props.studies?.stats || { title: [], accession: [] };
1314
return (
1415
<DatasetDetailsLayout
1516
icon={<FontAwesomeIcon icon={faBook} />}
1617
content={
17-
props.study !== null ? (
18+
stats ? (
1819
<div>
1920
<p className="mb-0">
2021
<strong>Part of studies:&nbsp;</strong>
21-
{props.study.stats.title !== null
22-
? props.study.stats.title.map((x) => (
23-
<span key={x}>{x}.&nbsp;</span>
24-
))
25-
: props.study.stats.accession.map((x) => (
26-
<span key={x}>{x}.&nbsp;</span>
27-
))}
22+
{stats.title
23+
? stats.title.map((x) => <span key={x}>{x}.&nbsp;</span>)
24+
: stats.accession.map((x) => <span key={x}>{x}.&nbsp;</span>)}
2825
</p>
2926
<p className="mb-0">
3027
<strong>
3128
Accession ID
32-
{props.study.stats?.accession?.length > 1 ? "s" : ""}:
29+
{stats.accession.length > 1 ? "s" : ""}:
3330
</strong>
34-
{props.study.stats?.accession?.map((x) => (
31+
{stats.accession.map((x) => (
3532
<span className="mb-0 d-block" key={x}>
3633
{x}
3734
</span>

src/components/browse/dataset/datasetAccordion/datasetSummary/datasetSummary.tsx

+4-11
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,9 @@ const DatasetSummary = (props: DataSetDetailsProps) => {
2626
const handleClose = () => setShow(false);
2727

2828
var dacFormLink: string | null = null;
29-
/*if (props.details && props.details.has_data_access_policy.data_request_form) {
30-
dacFormLink = props.details.has_data_access_policy.data_request_form;
31-
}*/
3229

3330
const handleOpen = () => {
34-
setCopyEmail(
35-
props.summary !== null && props.summary
36-
? props.summary.dac_email
37-
38-
);
31+
setCopyEmail(props.summary?.dac_email || "[email protected]");
3932
setShow(true);
4033
};
4134

@@ -45,7 +38,7 @@ const DatasetSummary = (props: DataSetDetailsProps) => {
4538
<div className="fs-7">
4639
<div className="pe-0 px-0 px-md-2 pt-md-1">
4740
<div className="float-end ps-0 ps-md-4 ms-1">
48-
{props.summary !== null && props.summary !== undefined ? (
41+
{props.summary ? (
4942
<>
5043
<RequestAccessButton
5144
accession={props.hit.content.accession}
@@ -112,11 +105,11 @@ const DatasetSummary = (props: DataSetDetailsProps) => {
112105
))}
113106
</p>
114107
</div>
115-
{props.summary !== null && props.summary !== undefined ? (
108+
{props.summary ? (
116109
<div>
117110
<Row className="pt-3">
118111
<Col xs={12} md={6} lg={12} xl={6}>
119-
<DatasetStudies study={props.summary.studies_summary} />
112+
<DatasetStudies studies={props.summary.studies_summary} />
120113
<DatasetSamples samples={props.summary.samples_summary} />
121114
</Col>
122115
<Col>

src/components/browse/dataset/datasetHeader.tsx

+10-12
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,28 @@ const DatasetHeader = (props: DatasetHeaderProps) => {
3636
getData();
3737
}, []);
3838

39-
var listOfAllFacets: FacetModel[] | null = null;
40-
if (searchResults !== null) {
41-
if ((searchResults.hits && searchResults.hits.length > 0) || searchResults.count === -1) {
42-
listOfAllFacets = searchResults.facets;
43-
} else {
44-
listOfAllFacets = [];
45-
}
46-
}
39+
const listOfAllFacets: FacetModel[] =
40+
searchResults &&
41+
((searchResults.hits && searchResults.hits.length > 0) ||
42+
searchResults.count === -1)
43+
? searchResults.facets
44+
: [];
4745

4846
const getFilterParamsList = () => {
4947
let filterParamsList = [];
5048
let searchParams = props.searchParams.get("f");
51-
if (searchParams !== undefined && searchParams !== null) {
49+
if (searchParams) {
5250
let searchParamsList = searchParams.split(";");
5351
for (var item of searchParamsList) {
5452
const itemKey = item.split(":")[0];
5553
var itemPretty = itemKey + "|" + item.replace(":", ": ");
56-
if (listOfAllFacets !== null) {
54+
if (listOfAllFacets) {
5755
const findResult: FacetModel | undefined = listOfAllFacets.find(
5856
(x) => x.key === itemKey
5957
);
60-
if (findResult !== undefined) {
58+
if (findResult) {
6159
var facetName = findResult.name;
62-
if (facetName !== undefined) {
60+
if (facetName) {
6361
itemPretty =
6462
findResult.key + "|" + facetName + ": " + item.split(":")[1];
6563
}

src/components/browse/shared.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { querySearchService } from "../../api/browse";
2626
*/
2727
export const getFilterParams = (filterString: string | null) => {
2828
let facetFilterModelList: FacetFilterModel[] = [];
29-
if (filterString != null) {
29+
if (filterString) {
3030
let filterStringList = filterString.split(";");
3131
for (var item of filterStringList) {
3232
let filterItem: FacetFilterModel = {

src/components/browse/singleDatasetView/singleDatasetView.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ const SingleDatasetView = () => {
5555

5656
const handleOpen = () => {
5757
setCopyEmail(
58-
details !== null && details
59-
? details.data_access_policy.data_access_committee.email
60-
58+
details?.data_access_policy?.data_access_committee?.email ||
59+
6160
);
6261
setShow(true);
6362
};

src/components/browse/singleDatasetView/singleDatasetViewAccordion/singleDatasetViewAccordion.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface SingleDatasetViewAccordionProps {
1212

1313
/** Section at the end of dataset details page consisting of three collapsible summary tables. */
1414
const SingleDatasetViewAccordion = (props: SingleDatasetViewAccordionProps) => {
15-
const all_files = Object.keys(props.details)
15+
const allFiles = Object.keys(props.details)
1616
.filter((key) => key.endsWith("_files"))
1717
.flatMap((key: string) => {
1818
const files = (props.details as any)[key];
@@ -21,12 +21,10 @@ const SingleDatasetViewAccordion = (props: SingleDatasetViewAccordionProps) => {
2121
return files.map((file: any) => ({ ...file, file_category }));
2222
});
2323

24-
const fileSize = all_files.reduce((a, c) => a + c.size, 0);
25-
2624
let Tables: SDSVTableDefinition[] = [
2725
ExperimentsTable(props),
2826
SamplesTable(props),
29-
FilesTable({ all_files }, fileSize),
27+
FilesTable({ allFiles }),
3028
];
3129

3230
return (

src/components/browse/singleDatasetView/singleDatasetViewAccordion/tables/experimentsTable.ts

+7-16
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,17 @@ export const ExperimentsTable = (props: ExperimentsTableProps) => {
2525
order: 0,
2626
});
2727

28+
const experiments = props.details.sequencing_experiments || [];
29+
2830
const experimentsTable: TableFields[] = [
2931
{
3032
header: "Experiment ID",
31-
data:
32-
props.details.sequencing_experiments !== undefined
33-
? props.details.sequencing_experiments?.map((x) => x.alias)
34-
: [],
33+
data: experiments.map((x) => x.alias),
3534
cssClasses: "w-25 text-wrap text-break",
3635
},
3736
{
3837
header: "Description",
39-
data:
40-
props.details.sequencing_experiments !== undefined
41-
? props.details.sequencing_experiments?.map((x) => x.description)
42-
: [],
38+
data: experiments?.map((x) => x.description),
4339
cssClasses: "text-wrap text-break",
4440
},
4541
];
@@ -50,14 +46,9 @@ export const ExperimentsTable = (props: ExperimentsTableProps) => {
5046

5147
const experimentsTableDef: SDSVTableDefinition = {
5248
table: experimentsTable,
53-
buttonText:
54-
props.details.sequencing_experiments !== null
55-
? "Experiment Summary (" +
56-
(props.details.sequencing_experiments !== undefined
57-
? props.details.sequencing_experiments.length
58-
: 0) +
59-
" experiments)"
60-
: "Experiment Summary",
49+
buttonText: experiments
50+
? "Experiment Summary (" + experiments.length + " experiments)"
51+
: "Experiment Summary (0 experiments)",
6152
sortDefinition: sortDefinition,
6253
setSortDefinition: setSortDefinition,
6354
sortedData: sortedData,

src/components/browse/singleDatasetView/singleDatasetViewAccordion/tables/filesTable.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ import {
66
} from "../../../../../utils/sortButton";
77

88
interface FilesTableProps {
9-
all_files: any[];
9+
allFiles: any[];
1010
}
1111

1212
/**
1313
* This function creates the schema for the file summary table,
1414
* which is one of three tables in the dataset details view.
1515
* @param props - Object containing the data and details.
16-
* @param fileSize - File size in bytes to be displayed on table
1716
* @returns The table definition object that includes table content, button text and definitions.
1817
*/
19-
export const FilesTable = (props: FilesTableProps, fileSize: number) => {
18+
export const FilesTable = (props: FilesTableProps) => {
2019
const [sortDefinition, setSortDefinition] = useState<{
2120
key: number;
2221
order: number;
@@ -25,25 +24,27 @@ export const FilesTable = (props: FilesTableProps, fileSize: number) => {
2524
order: 0,
2625
});
2726

27+
const allFiles = props.allFiles || [];
28+
2829
let filesTable: TableFields[] = [
2930
{
3031
header: "File ID",
31-
data: props.all_files.map((x) => x.accession),
32+
data: allFiles.map((x) => x.accession),
3233
cssClasses: "text-break",
3334
},
3435
{
3536
header: "File name",
36-
data: props.all_files.map((x) => x.name),
37+
data: allFiles.map((x) => x.name),
3738
cssClasses: "text-break",
3839
},
3940
{
4041
header: "File Type",
41-
data: props.all_files.map((x) => x.format?.toUpperCase()),
42+
data: allFiles.map((x) => x.format?.toUpperCase()),
4243
cssClasses: "",
4344
},
4445
{
4546
header: "File Origin",
46-
data: props.all_files.map((x) => x.file_category),
47+
data: allFiles.map((x) => x.file_category),
4748
cssClasses: "",
4849
},
4950
];
@@ -54,10 +55,9 @@ export const FilesTable = (props: FilesTableProps, fileSize: number) => {
5455

5556
const filesTableDef: SDSVTableDefinition = {
5657
table: filesTable,
57-
buttonText:
58-
props.all_files !== null
59-
? "File Summary (" + props.all_files.length + " files)"
60-
: "File Summary",
58+
buttonText: allFiles
59+
? "File Summary (" + allFiles.length + " files)"
60+
: "File Summary (0 files)",
6161
sortDefinition: sortDefinition,
6262
setSortDefinition: setSortDefinition,
6363
sortedData: sortedData,

src/components/browse/singleDatasetView/singleDatasetViewAccordion/tables/samplesTable.ts

+24-14
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,47 @@ export const SamplesTable = (props: SamplesTableProps) => {
2525
order: 0,
2626
});
2727

28+
const samples = props.details.samples || [];
29+
2830
const samplesTable: TableFields[] = [
2931
{
3032
header: "Sample ID",
31-
data: props.details.samples.map((x) => x.alias),
33+
data: samples.map((x) => x.accession),
3234
cssClasses: "",
3335
},
3436
{
3537
header: "Description",
36-
data: props.details.samples.map((x) => x.description),
38+
data: samples.map((x) => x.description),
3739
cssClasses: "text-wrap text-break",
3840
},
3941
{
4042
header: "Status",
41-
data: props.details.samples.map((x) => x.condition.case_control_status),
43+
data: samples.map(
44+
(x) => (x.case_control_status || "").toLowerCase() || "N/A"
45+
),
46+
cssClasses: "text-capitalize",
47+
},
48+
{
49+
header: "Sex",
50+
data: samples.map((x) => (x.individual.sex || "").toLowerCase() || "N/A"),
4251
cssClasses: "text-capitalize",
4352
},
4453
{
4554
header: "Phenotype",
46-
data: props.details.samples.map((x) =>
47-
x.biospecimen.individual.phenotypic_features !== null
48-
? x.biospecimen.individual.phenotypic_features[0]
49-
: "N/A"
55+
data: samples.map(
56+
(x) =>
57+
(x.individual.phenotypic_features_terms || []).join(", ") || "N/A"
5058
),
59+
cssClasses: "text-wrap text-break",
60+
},
61+
{
62+
header: "Biospecimen type",
63+
data: samples.map((x) => x.biospecimen_type || "N/A"),
5164
cssClasses: "",
5265
},
5366
{
5467
header: "Tissue",
55-
data: props.details.samples.map((x) =>
56-
x.biospecimen !== null ? x.biospecimen.tissue : "N/A"
57-
),
68+
data: samples.map((x) => x.biospecimen_tissue_term || "N/A"),
5869
cssClasses: "text-capitalize",
5970
},
6071
];
@@ -65,10 +76,9 @@ export const SamplesTable = (props: SamplesTableProps) => {
6576

6677
const samplesTableDef: SDSVTableDefinition = {
6778
table: samplesTable,
68-
buttonText:
69-
props.details.samples !== null
70-
? "Sample Summary (" + props.details.samples.length + " samples)"
71-
: "Sample Summary",
79+
buttonText: samples
80+
? "Sample Summary (" + samples.length + " samples)"
81+
: "Sample Summary (0 samples)",
7282
sortDefinition: sortDefinition,
7383
setSortDefinition: setSortDefinition,
7484
sortedData: sortedData,

0 commit comments

Comments
 (0)