Skip to content

Commit 078f8e2

Browse files
committed
add "Files & Links" tab with review changes
1 parent 16a699e commit 078f8e2

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/pages/studyView/resources/FilesAndLinks.tsx

+20-17
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface IFilesLinksTable {
2424
}
2525

2626
class FilesLinksTableComponent extends LazyMobXTable<{
27-
[id: string]: string;
27+
[id: string]: string | number;
2828
}> {}
2929

3030
const RECORD_LIMIT = 500;
@@ -70,20 +70,24 @@ async function fetchFilesLinksData(
7070
0
7171
);
7272

73+
// get unique patient Ids from clinical data to get their resources
74+
// via fetchResourceDataOfPatient.
7375
const patientIds = new Map<string, string>();
74-
_.forEach(sampleClinicalDataResponse.data, (data, uniqueSampleId) => {
76+
_.forEach(sampleClinicalDataResponse.data, data => {
7577
_.forEach(data, item => {
7678
patientIds.set(item.patientId, item.studyId);
7779
});
7880
});
7981

82+
// get all resources for patients.
83+
// improvement: use one request for getting a page of patients
84+
// with their samples and resources.
8085
const resourcesForPatients = await fetchResourceDataOfPatient(patientIds);
81-
8286
const buildItemsAndResources = (resourceData: {
8387
[key: string]: ResourceData[];
8488
}) => {
8589
const resourcesPerPatient: { [key: string]: number } = {};
86-
const items: { [attributeId: string]: any } = [];
90+
const items: { [attributeId: string]: string | number }[] = [];
8791
_.forEach(resourceData, (data: ResourceData[]) => {
8892
_.forEach(data, (resource: ResourceData) => {
8993
items.push({
@@ -94,7 +98,7 @@ async function fetchFilesLinksData(
9498
typeOfResource: resource?.resourceDefinition?.displayName,
9599
description: resource?.resourceDefinition?.description,
96100
url: resource?.url,
97-
});
101+
} as { [attributeId: string]: string | number });
98102
});
99103

100104
if (data && data.length > 0) {
@@ -108,23 +112,25 @@ async function fetchFilesLinksData(
108112
return { resourcesPerPatient, items };
109113
};
110114

111-
const resourcesForPatientsAndSamples = {
115+
const resourcesForPatientsAndSamples: { [key: string]: ResourceData[] } = {
112116
...sampleIdResourceData,
113117
...resourcesForPatients,
114118
};
115119

116-
//we create objects with the necessary properties for each resource
117-
//calculate the total number of resources per patient.
118-
120+
// we create objects with the necessary properties for each resource
121+
// calculate the total number of resources per patient.
119122
const { resourcesPerPatient, items } = buildItemsAndResources(
120123
resourcesForPatientsAndSamples
121124
);
122-
const data = _.mapValues(items, item => {
125+
126+
// set the number of resources available per patient.
127+
_.forEach(items, item => {
123128
item.resourcesPerPatient = resourcesPerPatient[item.patientId];
124-
return item;
125129
});
126130

127-
const sortedData = _.orderBy(data, 'resourcesPerPatient', 'desc');
131+
// there is a requirement to sort initially by 'resourcesPerPatient' field
132+
// in descending order.
133+
const sortedData = _.orderBy(items, 'resourcesPerPatient', 'desc');
128134
return {
129135
totalItems: sortedData.length,
130136
data: _.values(sortedData),
@@ -161,11 +167,7 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {
161167
download: (data: { [id: string]: string }) => data[key] || '',
162168
sortBy: (data: { [id: string]: any }) => {
163169
if (data[key]) {
164-
if (isNumber) {
165-
return parseFloat(data[key]);
166-
} else {
167-
return data[key];
168-
}
170+
return data[key];
169171
}
170172
return null;
171173
},
@@ -232,6 +234,7 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {
232234
);
233235
},
234236
},
237+
235238
{
236239
...this.getDefaultColumnConfig('sampleId', 'Sample ID'),
237240
render: (data: { [id: string]: string }) => {

0 commit comments

Comments
 (0)