forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminApp.tsx
324 lines (318 loc) · 13.7 KB
/
AdminApp.tsx
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import * as React from "react"
import { Admin } from "./Admin"
import { ChartEditorPage } from "./ChartEditorPage"
import { action } from "mobx"
import { observer } from "mobx-react"
import { ChartIndexPage } from "./ChartIndexPage"
import { UsersIndexPage } from "./UsersIndexPage"
import { DatasetsIndexPage } from "./DatasetsIndexPage"
import { CountryStandardizerPage } from "./CountryStandardizerPage"
import { UserEditPage } from "./UserEditPage"
import { VariableEditPage } from "./VariableEditPage"
import { VariablesIndexPage } from "./VariablesIndexPage"
import { DatasetEditPage } from "./DatasetEditPage"
import { SourceEditPage } from "./SourceEditPage"
import { RedirectsIndexPage } from "./RedirectsIndexPage"
import { TagEditPage } from "./TagEditPage"
import { TagsIndexPage } from "./TagsIndexPage"
import { PostsIndexPage } from "./PostsIndexPage"
import { TestIndexPage } from "./TestIndexPage"
import { ImportPage } from "./ImportPage"
import { NotFoundPage } from "./NotFoundPage"
import { PostEditorPage } from "./PostEditorPage"
import { NewsletterPage } from "./NewsletterPage"
import { DeployStatusPage } from "./DeployStatusPage"
import { SuggestedChartRevisionApproverPage } from "./SuggestedChartRevisionApproverPage"
import { SuggestedChartRevisionListPage } from "./SuggestedChartRevisionListPage"
import {
BrowserRouter as Router,
Route,
Switch,
Redirect,
} from "react-router-dom"
import { LoadingBlocker, Modal } from "./Forms"
import { AdminAppContext } from "./AdminAppContext"
import { Base64 } from "js-base64"
import { ExplorerCreatePage } from "../explorerAdminClient/ExplorerCreatePage"
import { ExplorersIndexPage } from "../explorerAdminClient/ExplorersListPage"
import { EXPLORERS_ROUTE_FOLDER } from "../explorer/ExplorerConstants"
import { AdminLayout } from "./AdminLayout"
@observer
class AdminErrorMessage extends React.Component<{ admin: Admin }> {
render(): JSX.Element | null {
const { admin } = this.props
const error = admin.errorMessage
return error ? (
<Modal
className="errorMessage"
onClose={action(() => {
error.isFatal
? window.location.reload()
: (admin.errorMessage = undefined)
})}
>
<div className="modal-header">
<div>
<h5
className="modal-title"
style={error.isFatal ? { color: "red" } : undefined}
>
{error.title}
</h5>
{error.isFatal && (
<p>
Please screenshot this error message and report
it in{" "}
<a href="https://owid.slack.com/messages/tech-issues/">
#tech-issues
</a>
</p>
)}
</div>
</div>
<div className="modal-body">
<pre dangerouslySetInnerHTML={{ __html: error.content }} />
</div>
</Modal>
) : null
}
}
@observer
class AdminLoader extends React.Component<{ admin: Admin }> {
render(): JSX.Element | null {
const { admin } = this.props
return admin.showLoadingIndicator ? <LoadingBlocker /> : null
}
}
@observer
export class AdminApp extends React.Component<{
admin: Admin
gitCmsBranchName: string
}> {
get childContext() {
return { admin: this.props.admin }
}
render(): JSX.Element {
const { admin, gitCmsBranchName } = this.props
return (
<AdminAppContext.Provider value={this.childContext}>
<Router basename={admin.basePath}>
<div className="AdminApp">
<AdminErrorMessage admin={admin} />
<AdminLoader admin={admin} />
<Switch>
<Route
exact
path="/charts/create/:config"
render={({ match }) => (
<ChartEditorPage
grapherConfig={JSON.parse(
Base64.decode(match.params.config)
)}
/>
)}
/>
<Route
exact
path="/charts/create"
component={ChartEditorPage}
/>
<Route
exact
path="/charts/:chartId/edit"
render={({ match }) => (
<ChartEditorPage
grapherId={parseInt(
match.params.chartId
)}
/>
)}
/>
<Route
exact
path="/charts/:chartId/edit/:config"
render={({ match }) => (
<ChartEditorPage
grapherConfig={JSON.parse(
Base64.decode(match.params.config)
)}
/>
)}
/>
<Route
exact
path="/charts"
component={ChartIndexPage}
/>
<Route
exact
path={`/${EXPLORERS_ROUTE_FOLDER}/:slug`}
render={({ match }) => (
<AdminLayout title="Create Explorer">
<ExplorerCreatePage
slug={match.params.slug}
gitCmsBranchName={gitCmsBranchName}
manager={admin}
/>
</AdminLayout>
)}
/>
<Route
exact
path={`/${EXPLORERS_ROUTE_FOLDER}`}
render={({ match }) => (
<AdminLayout title="Explorers">
<ExplorersIndexPage />
</AdminLayout>
)}
/>
<Route
exact
path="/users/:userId"
render={({ match }) => (
<UserEditPage
userId={parseInt(match.params.userId)}
/>
)}
/>
<Route
exact
path="/users"
component={UsersIndexPage}
/>
<Route
exact
path="/import"
component={ImportPage}
/>
<Route
exact
path="/variables/:variableId"
render={({ match }) => (
<VariableEditPage
variableId={parseInt(
match.params.variableId
)}
/>
)}
/>
<Route
exact
path="/variables"
component={VariablesIndexPage}
/>
<Route
exact
path="/datasets/:datasetId"
render={({ match }) => (
<DatasetEditPage
datasetId={parseInt(
match.params.datasetId
)}
/>
)}
/>
<Route
exact
path="/datasets"
component={DatasetsIndexPage}
/>
<Route
exact
path="/sources/:sourceId"
render={({ match }) => (
<SourceEditPage
sourceId={parseInt(
match.params.sourceId
)}
/>
)}
/>
<Route
exact
path="/standardize"
component={CountryStandardizerPage}
/>
<Route
exact
path="/redirects"
component={RedirectsIndexPage}
/>
<Route
exact
path="/tags/:tagId"
render={({ match }) => (
<TagEditPage
tagId={parseInt(match.params.tagId)}
/>
)}
/>
<Route
exact
path="/tags"
component={TagsIndexPage}
/>
<Route
exact
path="/posts"
component={PostsIndexPage}
/>
<Route
exact
path="/posts/:postId/edit"
render={({ match }) => (
<PostEditorPage
postId={parseInt(match.params.postId)}
/>
)}
/>
<Route
exact
path="/test"
component={TestIndexPage}
/>
<Route
exact
path="/deploys"
component={DeployStatusPage}
/>
<Route
exact
path="/newsletter"
component={NewsletterPage}
/>
<Route
exact
path="/suggested-chart-revisions"
component={SuggestedChartRevisionListPage}
/>
<Route
exact
path="/suggested-chart-revisions/review"
component={SuggestedChartRevisionApproverPage}
/>
<Route
exact
path="/suggested-chart-revisions/review/:suggestedChartRevisionId"
render={({ match }) => (
<SuggestedChartRevisionApproverPage
suggestedChartRevisionId={parseInt(
match.params
.suggestedChartRevisionId
)}
/>
)}
/>
<Route
exact
path="/"
render={() => <Redirect to="/charts" />}
/>
<Route component={NotFoundPage} />
</Switch>
</div>
</Router>
</AdminAppContext.Provider>
)
}
}