1
1
import React , { useState , useEffect } from 'react' ;
2
+ import PropTypes from 'prop-types' ;
2
3
import { getComparator } from '../network-editor/pathway-table' ;
3
4
import { Select , MenuItem } from '@material-ui/core' ;
4
5
import { Table , TableBody , TableCell , TableContainer , TableHead , TableRow , Paper } from '@material-ui/core' ;
@@ -17,34 +18,49 @@ const useStyles = makeStyles((theme) => ({
17
18
} ) ) ;
18
19
19
20
20
- export function Report ( ) {
21
+ async function fetchReport ( secret ) {
22
+ try {
23
+ const countRes = await fetch ( `/api/report/count/${ secret } ` ) ;
24
+ if ( ! countRes . ok ) {
25
+ return 'error' ;
26
+ }
27
+ const networkRes = await fetch ( `/api/report/networks/${ secret } ` ) ;
28
+ if ( ! networkRes . ok ) {
29
+ return 'error' ;
30
+ }
31
+
32
+ const counts = await countRes . json ( ) ;
33
+ const networks = await networkRes . json ( ) ;
34
+
35
+ return { counts, networks } ;
36
+ } catch ( err ) {
37
+ console . log ( err ) ;
38
+ return 'error' ;
39
+ }
40
+ }
41
+
42
+
43
+ export function Report ( { secret } ) {
21
44
const classes = useStyles ( ) ;
45
+
22
46
const [ report , setReport ] = useState ( null ) ;
23
47
const [ order , setOrder ] = useState ( 'desc' ) ;
24
48
const [ orderBy , setOrderBy ] = useState ( 'creationTime' ) ;
25
49
26
50
useEffect ( ( ) => {
27
- Promise . all ( [
28
- fetch ( '/api/report/count' ) . then ( res => res . json ( ) ) ,
29
- fetch ( '/api/report/networks' ) . then ( res => res . json ( ) )
30
- ] )
31
- . then ( ( [ counts , networks ] ) => {
32
- const report = { counts, networks } ;
33
- console . log ( 'report' , report ) ;
34
- setReport ( report ) ;
35
- } )
36
- . catch ( ( error ) => console . log ( error ) ) ;
51
+ fetchReport ( secret ) . then ( setReport ) ;
37
52
} , [ ] ) ;
38
53
39
-
40
54
if ( ! report ) {
41
55
return < div > Loading... </ div > ;
56
+ } else if ( report === 'error' ) {
57
+ return < div > Error fetching report. </ div > ;
42
58
}
43
59
44
60
const comparator = getComparator ( order , orderBy ) ;
45
61
const sortedNetworks = report . networks . sort ( comparator ) ;
46
62
47
- return < div >
63
+ return < div style = { { padding : '10px' } } >
48
64
< h1 > EnrichmentMap:RNA-Seq - Usage Report</ h1 >
49
65
< h3 > Demo Networks: { report . counts . demo } </ h3 >
50
66
< h3 > User Created Networks ({ report . counts . user } ):</ h3 >
@@ -73,7 +89,7 @@ export function Report() {
73
89
< TableCell align = "right" > < b > Type</ b > </ TableCell >
74
90
< TableCell align = "right" > < b > Creation Time</ b > </ TableCell >
75
91
< TableCell align = "right" > < b > Last Access Time</ b > </ TableCell >
76
- < TableCell align = "right" > < b > Open </ b > </ TableCell >
92
+ < TableCell align = "right" > </ TableCell >
77
93
</ TableRow >
78
94
</ TableHead >
79
95
< TableBody >
@@ -101,4 +117,8 @@ export function Report() {
101
117
</ div > ;
102
118
}
103
119
120
+ Report . propTypes = {
121
+ secret : PropTypes . string ,
122
+ } ;
123
+
104
124
export default Report ;
0 commit comments