-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
241 lines (234 loc) · 10.5 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import React from 'react'
import { useHistory } from 'react-router-dom'
import DataQuery from '../../modules/data-query'
import { NETWORKS_MIN, NETWORK, EXPLORER_NETWORK_CHARTS } from '../../graphql/queries'
import {
NoneMessage,
ExplorerHeaderBar,
ExplorerLayout,
ExplorerTableLayout,
ExplorerTabsLayout,
ExplorerEntityLayout,
ExplorerSectionLayout,
ScrollButton,
iconLink,
ExplorerCoverageMap,
variableIcon,
ExplorerHeaderCharts,
} from '../../modules/explorer-page'
import formatAndFilterObjectKeys from '../../lib/format-filter-obj-keys'
import { List, ListItem } from 'react-md'
import {
Table,
GlobalStateContext,
ChartState,
FormattedObject,
} from '../../modules/shared-components'
import { networkCharts } from './network-charts'
import { DOWNLOADS_ENDPOINT } from '../../config'
import getSitesExtent from '../../lib/get-sites-extent'
const mappings = {}
const networksDataDefinitions = {
id: { show: true, order: 0, label: 'ID' },
title: { show: true, order: 1, label: 'Title' },
acronym: { show: true, order: 2, label: 'Acronym' },
type: { show: true, order: 3, label: 'Type' },
status: { show: true, order: 4, label: 'Status' },
start_year: { show: true, order: 5, label: 'Start Year' },
end_year: { show: true, order: 6, label: 'End Year' },
__typename: { show: false },
}
export default props => {
const history = useHistory()
return (
<DataQuery query={NETWORKS_MIN}>
{({ networks }) => {
return (
<GlobalStateContext.Consumer>
{({
africaOnly,
updateGlobalState,
selectedNetworks,
currentNetwork,
selectedVariables,
}) => {
return (
<>
{/* This div is used for the site tour */}
<div id="networks-overview-anchor" style={{ position: 'absolute', top: 20 }} />
<ChartState>
<ExplorerHeaderBar
selectedIds={selectedNetworks}
resetFn={() => updateGlobalState({ selectedNetworks: [] })}
{...props}
/>
<ExplorerHeaderCharts
query={EXPLORER_NETWORK_CHARTS}
chartDefinitions={networkCharts}
variables={{
ids:
selectedNetworks.length > 0 ? selectedNetworks : networks.map(n => n.id),
}}
/>
</ChartState>
<ExplorerLayout>
<ExplorerTableLayout id="networks-table">
<Table
actions={[
<ScrollButton
key={1}
disabled={selectedNetworks.length > 0 ? false : true}
/>,
]}
baseId={'networks-table'}
searchbar={true}
className={'fixed-table'}
defaultPaginationRows={5}
selectedIds={selectedNetworks}
dataDefinitions={networksDataDefinitions}
data={networks}
toggleSelect={({ id }) =>
updateGlobalState(
{
selectedNetworks: selectedNetworks.includes(id)
? [...selectedNetworks].filter(vId => vId !== id)
: [...new Set([...selectedNetworks, id])],
},
{ currentIndex: 'currentNetwork', selectedIds: 'selectedNetworks' }
)
}
/>
</ExplorerTableLayout>
<ExplorerTabsLayout
currentIndex={currentNetwork}
updateCurrentIndex={i => updateGlobalState({ currentNetwork: i })}
id="networks-overview"
selectedIds={selectedNetworks}
{...props}
>
{({ id }) => (
<DataQuery
query={NETWORK}
variables={{ id, extent: getSitesExtent(africaOnly) }}
>
{({ network }) => (
<ExplorerEntityLayout
title={network.title}
authors={network.acronym}
abstract={network.abstract}
clickClose={() =>
updateGlobalState(
{
selectedNetworks: selectedNetworks.filter(
sId => sId !== network.id
),
},
{
currentIndex: 'currentNetwork',
selectedIds: 'selectedNetworks',
}
)
}
href={encodeURI(
`${DOWNLOADS_ENDPOINT}/NETWORKS?filename=NETWORK-${new Date()}.json&ids=${[
network.id,
].join(',')}`
)}
clickEdit={() => history.push(`/networks/${network.id}`)}
>
<ExplorerSectionLayout
sections={[
// General information
{
title: 'Additional Information',
subTitle: 'All available fields',
component: (
<FormattedObject
object={formatAndFilterObjectKeys(
network,
mappings,
([key, val]) =>
['abstract', '__typename'].includes(key) ||
typeof val === 'object'
? false
: true
)}
/>
),
},
// Related variables
{
title: 'Variables',
subTitle: 'Measured by this network',
component: network.variables[0] ? (
<div>
<List>
{[...network.variables]
.sort((a, b) =>
a.name > b.name ? 1 : b.name > a.name ? -1 : 0
)
.map((variable, i) => (
<ListItem
onClick={() =>
updateGlobalState(
{
selectedVariables: [
...new Set([
...selectedVariables,
variable.id,
]),
],
},
{
currentIndex: 'currentVariable',
selectedIds: 'selectedVariables',
},
() => history.push('/variables')
)
}
className="add-on-hover"
key={i}
rightIcon={variableIcon}
leftIcon={iconLink}
primaryText={`${variable.name}`}
/>
))}
</List>
</div>
) : (
<NoneMessage />
),
},
// Coverage map
{
title: 'Spatial Coverage',
subTitle: 'Of this network',
component: network.coverage_spatial ? (
<ExplorerCoverageMap geoJson={network.coverage_spatial} />
) : (
<NoneMessage />
),
style: { height: '500px' },
grid: network.coverage_spatial
? {
size: 12,
}
: {},
},
]}
/>
</ExplorerEntityLayout>
)}
</DataQuery>
)}
</ExplorerTabsLayout>
</ExplorerLayout>
</>
)
}}
</GlobalStateContext.Consumer>
)
}}
</DataQuery>
)
}