@@ -16,10 +16,16 @@ import AccordionDetails from '@mui/material/AccordionDetails';
16
16
import ExpandMoreIcon from '@mui/icons-material/ExpandMore' ;
17
17
import ArrowRightIcon from '@mui/icons-material/ArrowRight' ;
18
18
import { truncateDecimals } from 'utils/format' ;
19
+ import { Alert } from '@mui/material' ;
20
+ import { NotFoundError } from 'components/Shared/NotFoundError/NotFoundError' ;
19
21
20
22
export const InteractionRecord : React . FC = ( ) => {
21
23
const interactionId = useParams ( ) . id ;
22
24
const { data } = useGetInteractionRecord ( interactionId ! ) ;
25
+ const interactionData = data ?. interaction ;
26
+
27
+ const interactionExists = interactionData !== null ;
28
+
23
29
const noData = (
24
30
< TableRow >
25
31
< TableCell style = { { borderBottom : 'none' } } > No data available.</ TableCell >
@@ -38,10 +44,10 @@ export const InteractionRecord: React.FC = () => {
38
44
< TableCell className = "attribute-value" >
39
45
< a
40
46
className = "info-link"
41
- href = { `/drugs/${ data ?. interaction ?. drug ?. conceptId } ` }
47
+ href = { `/drugs/${ interactionData ?. drug ?. conceptId } ` }
42
48
>
43
- { data ?. interaction ?. drug ?. name } [
44
- { data ?. interaction ?. drug ?. conceptId } ]
49
+ { interactionData ?. drug ?. name } [
50
+ { interactionData ?. drug ?. conceptId } ]
45
51
</ a >
46
52
</ TableCell >
47
53
</ TableRow >
@@ -50,10 +56,10 @@ export const InteractionRecord: React.FC = () => {
50
56
< TableCell className = "attribute-value" >
51
57
< a
52
58
className = "info-link"
53
- href = { `/genes/${ data ?. interaction ?. gene ?. conceptId } ` }
59
+ href = { `/genes/${ interactionData ?. gene ?. conceptId } ` }
54
60
>
55
- { data ?. interaction ?. gene ?. name } [
56
- { data ?. interaction ?. gene ?. conceptId } ]
61
+ { interactionData ?. gene ?. name } [
62
+ { interactionData ?. gene ?. conceptId } ]
57
63
</ a >
58
64
</ TableCell >
59
65
</ TableRow >
@@ -62,12 +68,12 @@ export const InteractionRecord: React.FC = () => {
62
68
Interaction Score:
63
69
</ TableCell >
64
70
< TableCell className = "attribute-value" >
65
- { truncateDecimals ( data ?. interaction ?. interactionScore , 2 ) }
71
+ { truncateDecimals ( interactionData ?. interactionScore , 2 ) }
66
72
</ TableCell >
67
73
</ TableRow >
68
74
69
- { data ?. interaction ?. interactionTypes
70
- ? data ?. interaction ?. interactionTypes ?. map ( ( attribute : any ) => {
75
+ { interactionData ?. interactionTypes
76
+ ? interactionData ?. interactionTypes ?. map ( ( attribute : any ) => {
71
77
return (
72
78
< TableRow
73
79
key = { 'Directionality ' + attribute . directionality }
@@ -93,8 +99,8 @@ export const InteractionRecord: React.FC = () => {
93
99
< Box className = "box-content" >
94
100
< Table >
95
101
< TableBody >
96
- { data ?. interaction ?. publications . length
97
- ? data ?. interaction ?. publications ?. map (
102
+ { interactionData ?. publications . length
103
+ ? interactionData ?. publications ?. map (
98
104
( pmid : any , index : number ) => {
99
105
return (
100
106
< TableRow key = { index } >
@@ -123,8 +129,8 @@ export const InteractionRecord: React.FC = () => {
123
129
< Box className = "box-content" >
124
130
< Table >
125
131
< TableBody >
126
- { data ?. interaction ?. sources . length
127
- ? data ?. interaction ?. sources ?. map (
132
+ { interactionData ?. sources . length
133
+ ? interactionData ?. sources ?. map (
128
134
( source : any , index : number ) => {
129
135
return (
130
136
< TableRow key = { index } >
@@ -143,97 +149,102 @@ export const InteractionRecord: React.FC = () => {
143
149
} ,
144
150
] ;
145
151
146
- return (
147
- data && (
148
- < Box className = "content interaction-record-container" >
149
- < Box className = "interaction-record-header" >
150
- < Box className = "symbol" >
151
- < a
152
- className = "header-link"
153
- href = { `/drugs/${ data . interaction ?. drug ?. conceptId } ` }
154
- >
155
- { data ?. interaction ?. drug ?. name }
156
- </ a > { ' ' }
157
- < ArrowRightIcon /> { ' ' }
158
- < a
159
- className = "header-link"
160
- href = { `/genes/${ data . interaction ?. gene ?. conceptId } ` }
161
- >
162
- { data ?. interaction ?. gene ?. name }
163
- </ a >
164
- </ Box >
152
+ return interactionExists ? (
153
+ < Box className = "content interaction-record-container" >
154
+ < Box className = "interaction-record-header" >
155
+ < Box className = "symbol" >
156
+ < a
157
+ className = "header-link"
158
+ href = { `/drugs/${ interactionData ?. drug ?. conceptId } ` }
159
+ >
160
+ { interactionData ?. drug ?. name }
161
+ </ a > { ' ' }
162
+ < ArrowRightIcon /> { ' ' }
163
+ < a
164
+ className = "header-link"
165
+ href = { `/genes/${ interactionData ?. gene ?. conceptId } ` }
166
+ >
167
+ { interactionData ?. gene ?. name }
168
+ </ a >
165
169
</ Box >
166
- < Box display = "flex" >
167
- < Box display = "block" width = "45% ">
168
- { sectionsMap . map ( ( section ) => {
169
- return (
170
- < Accordion key = { section . name } defaultExpanded >
171
- < AccordionSummary
172
- style = { {
173
- padding : '0 10px' ,
174
- backgroundColor : 'var(--background-light) ' ,
175
- } }
176
- expandIcon = { < ExpandMoreIcon /> }
177
- >
178
- < h3 >
179
- < b > { section . name } </ b >
180
- </ h3 >
181
- </ AccordionSummary >
182
- < AccordionDetails
183
- style = { {
184
- maxHeight : '500px' ,
185
- overflow : 'scroll ' ,
186
- padding : '5px ' ,
187
- } }
188
- >
189
- { section . sectionContent }
190
- </ AccordionDetails >
191
- </ Accordion >
192
- ) ;
193
- } ) }
194
- </ Box >
195
- < Box ml = { 1 } width = "55%" >
196
- < Accordion defaultExpanded >
197
- < AccordionSummary
198
- style = { {
199
- padding : '0 10px' ,
200
- backgroundColor : 'var(--background-light) ' ,
201
- } }
202
- expandIcon = { < ExpandMoreIcon /> }
203
- >
204
- < h3 >
205
- < b > Interaction Attributes </ b >
206
- </ h3 >
207
- </ AccordionSummary >
208
- < AccordionDetails className = "attributes-container" >
209
- < Table >
210
- < TableBody >
211
- { data ?. interaction ?. interactionAttributes . length
212
- ? data ?. interaction ?. interactionAttributes ?. map (
213
- ( attribute : any ) => {
214
- return (
215
- < TableRow
216
- key = { attribute . name + ' ' + attribute . value }
217
- >
218
- < TableCell className = "attribute-name" >
219
- { attribute . name } :
220
- </ TableCell >
221
- < TableCell className = "attribute-value" >
222
- { attribute . value }
223
- </ TableCell >
224
- </ TableRow >
225
- ) ;
226
- }
227
- )
228
- : noData }
229
- </ TableBody >
230
- </ Table >
231
- </ AccordionDetails >
232
- </ Accordion >
233
- </ Box >
170
+ </ Box >
171
+ < Box display = "flex " >
172
+ < Box display = "block" width = "45%" >
173
+ { sectionsMap . map ( ( section ) => {
174
+ return (
175
+ < Accordion key = { section . name } defaultExpanded >
176
+ < AccordionSummary
177
+ style = { {
178
+ padding : '0 10px ' ,
179
+ backgroundColor : 'var(--background-light)' ,
180
+ } }
181
+ expandIcon = { < ExpandMoreIcon /> }
182
+ >
183
+ < h3 >
184
+ < b > { section . name } </ b >
185
+ </ h3 >
186
+ </ AccordionSummary >
187
+ < AccordionDetails
188
+ style = { {
189
+ maxHeight : '500px ' ,
190
+ overflow : 'scroll ' ,
191
+ padding : '5px' ,
192
+ } }
193
+ >
194
+ { section . sectionContent }
195
+ </ AccordionDetails >
196
+ </ Accordion >
197
+ ) ;
198
+ } ) }
199
+ </ Box >
200
+ < Box ml = { 1 } width = "55%" >
201
+ < Accordion defaultExpanded >
202
+ < AccordionSummary
203
+ style = { {
204
+ padding : '0 10px ' ,
205
+ backgroundColor : 'var(--background-light)' ,
206
+ } }
207
+ expandIcon = { < ExpandMoreIcon /> }
208
+ >
209
+ < h3 >
210
+ < b > Interaction Attributes </ b >
211
+ </ h3 >
212
+ </ AccordionSummary >
213
+ < AccordionDetails className = "attributes-container" >
214
+ < Table >
215
+ < TableBody >
216
+ { interactionData ?. interactionAttributes . length
217
+ ? interactionData ?. interactionAttributes ?. map (
218
+ ( attribute : any ) => {
219
+ return (
220
+ < TableRow
221
+ key = { attribute . name + ' ' + attribute . value }
222
+ >
223
+ < TableCell className = " attribute- name" >
224
+ { attribute . name } :
225
+ </ TableCell >
226
+ < TableCell className = " attribute- value" >
227
+ { attribute . value }
228
+ </ TableCell >
229
+ </ TableRow >
230
+ ) ;
231
+ }
232
+ )
233
+ : noData }
234
+ </ TableBody >
235
+ </ Table >
236
+ </ AccordionDetails >
237
+ </ Accordion >
234
238
</ Box >
235
239
</ Box >
236
- )
240
+ </ Box >
241
+ ) : (
242
+ < Box p = { 2 } >
243
+ < Alert severity = "error" >
244
+ We could not find any results for this interaction.
245
+ </ Alert >
246
+ < NotFoundError />
247
+ </ Box >
237
248
) ;
238
249
} ;
239
250
0 commit comments