Skip to content

Commit 06f8de0

Browse files
committed
feat: anvil explorer - add files.data_modality to the facets and tables (#4618)
1 parent 19f089d commit 06f8de0

File tree

10 files changed

+85
-29
lines changed

10 files changed

+85
-29
lines changed

app/apis/azul/anvil-cmg/common/responses.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ import {
2020
LibraryEntityResponse,
2121
} from "./entities";
2222

23+
/**
24+
* Model of response returned from /index/files or /index/samples or index/projects API endpoint.
25+
*/
26+
export type EntityResponse =
27+
| ActivitiesResponse
28+
| BioSamplesResponse
29+
| DatasetsResponse
30+
| DonorsResponse
31+
| FilesResponse;
32+
2333
/**
2434
* Model of response returned from the /index/activities API endpoint.
2535
*/

app/apis/azul/anvil-cmg/common/transformers.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ import {
55
KeyValues,
66
Value,
77
} from "@databiosphere/findable-ui/lib/components/common/KeyValuePairs/keyValuePairs";
8-
import { MetadataValue } from "@databiosphere/findable-ui/lib/components/Table/components/TableCell/components/NTagCell/nTagCell";
98
import { humanFileSize } from "../../../../utils/fileSize";
109
import {
1110
processAggregatedOrArrayValue,
1211
processEntityValue,
1312
processNumberEntityValue,
1413
} from "../../common/utils";
1514
import {
16-
AggregatedActivityResponse,
1715
AggregatedBioSampleResponse,
1816
AggregatedDatasetResponse,
1917
AggregatedDiagnosisResponse,
@@ -116,28 +114,6 @@ export function getDatasetDetails(
116114
return details;
117115
}
118116

119-
/**
120-
* Maps data modality from index/activities API response.
121-
* @param response - Response model return from index/activities API.
122-
* @returns a list of data modalities.
123-
*/
124-
export function getActivityDataModalities(
125-
response: ActivityEntityResponse
126-
): MetadataValue[] {
127-
return processAggregatedOrArrayValue(response.activities, "data_modality");
128-
}
129-
130-
/**
131-
* Maps data modalities from aggregated activities values returned from endpoints other than index/activities.
132-
* @param response - Response model return from Azul that includes aggregated activities.
133-
* @returns Data modalities.
134-
*/
135-
export function getAggregatedActivityDataModalities(
136-
response: AggregatedActivityResponse
137-
): MetadataValue[] {
138-
return processAggregatedOrArrayValue(response.activities, "data_modality");
139-
}
140-
141117
/**
142118
* Maps dataset id from the core dataset entity returned from the index/datasets endpoint.
143119
* @param response - Response model return from datasets or dataset API endpoints.

app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ import {
6565
} from "../../../../apis/azul/anvil-cmg/common/entities";
6666
import {
6767
DatasetsResponse,
68+
EntityResponse,
6869
FilesResponse,
6970
SummaryResponse,
7071
} from "../../../../apis/azul/anvil-cmg/common/responses";
7172
import {
72-
getActivityDataModalities,
7373
getActivityType,
7474
getAggregatedBioSampleTypes,
7575
getAggregatedDatasetIds,
@@ -97,6 +97,7 @@ import {
9797
getReportedEthnicities,
9898
} from "../../../../apis/azul/anvil-cmg/common/transformers";
9999
import {
100+
processAggregatedOrArrayValue,
100101
processEntityArrayValue,
101102
processEntityValue,
102103
} from "../../../../apis/azul/common/utils";
@@ -124,6 +125,20 @@ export const buildActivityType = (
124125
};
125126
};
126127

128+
/**
129+
* Build props for aggregated data modality NTagCell component from the given response.
130+
* @param response - Response model return from API.
131+
* @returns model to be used as props for the NTagCell component.
132+
*/
133+
export const buildAggregatedDataModality = (
134+
response: Exclude<EntityResponse, FilesResponse>
135+
): React.ComponentProps<typeof C.NTagCell> => {
136+
return {
137+
label: getPluralizedMetadataLabel(METADATA_KEY.DATA_MODALITY),
138+
values: processAggregatedOrArrayValue(response.files, "data_modality"),
139+
};
140+
};
141+
127142
/**
128143
* Build props for dataset-related export warning Alert component.
129144
* @param _ - Unused.
@@ -267,16 +282,16 @@ export const buildConsentGroup = (
267282
};
268283

269284
/**
270-
* Build props for data modality NTagCell component from the given activities response.
271-
* @param response - Response model return from index/activities API.
285+
* Build props for data modality NTagCell component from the given response.
286+
* @param response - Response model return from API.
272287
* @returns model to be used as props for the NTagCell component.
273288
*/
274289
export const buildDataModality = (
275-
response: ActivityEntityResponse
290+
response: FilesResponse
276291
): React.ComponentProps<typeof C.NTagCell> => {
277292
return {
278293
label: getPluralizedMetadataLabel(METADATA_KEY.DATA_MODALITY),
279-
values: getActivityDataModalities(response),
294+
values: processEntityArrayValue(response.files, "data_modality"),
280295
};
281296
};
282297

site-config/anvil-cmg/category.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const ANVIL_CMG_CATEGORY_KEY = {
2020
DONOR_PHENOTYPIC_SEX: "donors.phenotypic_sex",
2121
DONOR_REPORTED_ETHNICITY: "donors.reported_ethnicity",
2222
DRS_URI: "files.drs_uri",
23+
FILE_DATA_MODALITY: "files.data_modality",
2324
FILE_FILE_FORMAT: "files.file_format",
2425
FILE_FILE_NAME: "files.file_name",
2526
FILE_FILE_SIZE: "files.file_size",
@@ -50,6 +51,7 @@ export const ANVIL_CMG_CATEGORY_LABEL = {
5051
DONOR_PHENOTYPIC_SEX: "Phenotypic Sex",
5152
DONOR_REPORTED_ETHNICITY: "Reported Ethnicity",
5253
DRS_URI: "DRS URI",
54+
FILE_DATA_MODALITY: "Data Modality",
5355
FILE_FILE_FORMAT: "File Format",
5456
FILE_FILE_NAME: "Name",
5557
FILE_FILE_SIZE: "Size",

site-config/anvil-cmg/dev/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ export function makeConfig(
113113
key: ANVIL_CMG_CATEGORY_KEY.FILE_FILE_FORMAT,
114114
label: ANVIL_CMG_CATEGORY_LABEL.FILE_FILE_FORMAT,
115115
},
116+
{
117+
key: ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY,
118+
label: ANVIL_CMG_CATEGORY_LABEL.FILE_DATA_MODALITY,
119+
},
116120
],
117121
label: "File",
118122
},

site-config/anvil-cmg/dev/index/activitiesEntityConfig.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,23 @@ export const activitiesEntityConfig: EntityConfig<ActivitiesResponse> = {
103103
id: ANVIL_CMG_CATEGORY_KEY.DATASET_TITLE,
104104
width: { max: "1fr", min: "200px" },
105105
},
106+
{
107+
componentConfig: {
108+
component: C.NTagCell,
109+
viewBuilder: V.buildAggregatedDataModality,
110+
} as ComponentConfig<typeof C.NTagCell>,
111+
header: ANVIL_CMG_CATEGORY_LABEL.FILE_DATA_MODALITY,
112+
id: ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY,
113+
width: { max: "1fr", min: "200px" },
114+
},
106115
],
107116
tableOptions: {
108117
initialState: {
109118
columnVisibility: {
110119
[ANVIL_CMG_CATEGORY_LABEL.DONOR_PHENOTYPIC_SEX]: false,
111120
[ANVIL_CMG_CATEGORY_KEY.DONOR_REPORTED_ETHNICITY]: false,
112121
[ANVIL_CMG_CATEGORY_KEY.DIAGNOSE_DISEASE]: false,
122+
[ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY]: false,
113123
},
114124
sorting: [
115125
{

site-config/anvil-cmg/dev/index/biosamplesEntityConfig.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,22 @@ export const biosamplesEntityConfig: EntityConfig<BioSamplesResponse> = {
103103
id: ANVIL_CMG_CATEGORY_KEY.DATASET_TITLE,
104104
width: { max: "1fr", min: "200px" },
105105
},
106+
{
107+
componentConfig: {
108+
component: C.NTagCell,
109+
viewBuilder: V.buildAggregatedDataModality,
110+
} as ComponentConfig<typeof C.NTagCell>,
111+
header: ANVIL_CMG_CATEGORY_LABEL.FILE_DATA_MODALITY,
112+
id: ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY,
113+
width: { max: "1fr", min: "200px" },
114+
},
106115
],
107116
tableOptions: {
108117
initialState: {
109118
columnVisibility: {
110119
[ANVIL_CMG_CATEGORY_KEY.DONOR_PHENOTYPIC_SEX]: false,
111120
[ANVIL_CMG_CATEGORY_KEY.DONOR_REPORTED_ETHNICITY]: false,
121+
[ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY]: false,
112122
},
113123
sorting: [
114124
{

site-config/anvil-cmg/dev/index/datasetsEntityConfig.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,22 @@ export const datasetsEntityConfig: EntityConfig<DatasetsResponse> = {
121121
id: ANVIL_CMG_CATEGORY_KEY.DIAGNOSE_DISEASE,
122122
width: { max: "1fr", min: "200px" },
123123
},
124+
{
125+
componentConfig: {
126+
component: C.NTagCell,
127+
viewBuilder: V.buildAggregatedDataModality,
128+
} as ComponentConfig<typeof C.NTagCell>,
129+
header: ANVIL_CMG_CATEGORY_LABEL.FILE_DATA_MODALITY,
130+
id: ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY,
131+
width: { max: "1fr", min: "200px" },
132+
},
124133
],
125134
tableOptions: {
126135
initialState: {
127136
columnVisibility: {
128137
[ANVIL_CMG_CATEGORY_KEY.DONOR_PHENOTYPIC_SEX]: false,
129138
[ANVIL_CMG_CATEGORY_KEY.DONOR_REPORTED_ETHNICITY]: false,
139+
[ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY]: false,
130140
},
131141
sorting: [
132142
{

site-config/anvil-cmg/dev/index/donorsEntityConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ export const donorsEntityConfig: EntityConfig<DonorsResponse> = {
8585
id: ANVIL_CMG_CATEGORY_KEY.DATASET_TITLE,
8686
width: { max: "1fr", min: "200px" },
8787
},
88+
{
89+
componentConfig: {
90+
component: C.NTagCell,
91+
viewBuilder: V.buildAggregatedDataModality,
92+
} as ComponentConfig<typeof C.NTagCell>,
93+
header: ANVIL_CMG_CATEGORY_LABEL.FILE_DATA_MODALITY,
94+
id: ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY,
95+
width: { max: "1fr", min: "200px" },
96+
},
8897
],
8998
tableOptions: {
9099
initialState: {

site-config/anvil-cmg/dev/index/filesEntityConfig.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ export const filesEntityConfig: EntityConfig<FilesResponse> = {
128128
id: ANVIL_CMG_CATEGORY_KEY.DATASET_TITLE,
129129
width: { max: "1fr", min: "240px" },
130130
},
131+
{
132+
componentConfig: {
133+
component: C.NTagCell,
134+
viewBuilder: V.buildDataModality,
135+
} as ComponentConfig<typeof C.NTagCell>,
136+
header: ANVIL_CMG_CATEGORY_LABEL.FILE_DATA_MODALITY,
137+
id: ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY,
138+
width: { max: "1fr", min: "200px" },
139+
},
131140
],
132141
tableOptions: {
133142
initialState: {
@@ -136,6 +145,7 @@ export const filesEntityConfig: EntityConfig<FilesResponse> = {
136145
[ANVIL_CMG_CATEGORY_KEY.DONOR_PHENOTYPIC_SEX]: false,
137146
[ANVIL_CMG_CATEGORY_KEY.DONOR_REPORTED_ETHNICITY]: false,
138147
[ANVIL_CMG_CATEGORY_KEY.DIAGNOSE_DISEASE]: false,
148+
[ANVIL_CMG_CATEGORY_KEY.FILE_DATA_MODALITY]: false,
139149
},
140150
sorting: [
141151
{

0 commit comments

Comments
 (0)