-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathApp.jsx
More file actions
209 lines (196 loc) · 5.51 KB
/
App.jsx
File metadata and controls
209 lines (196 loc) · 5.51 KB
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
import { useDataQuery, useConfig } from '@dhis2/app-runtime'
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { CssVariables, CenteredContent, CircularLoader } from '@dhis2/ui'
import React from 'react'
// to ensure that i18n is first imported from locales/index, i18n is imported before App
// eslint-disable-next-line import/order
import i18n from './locales/index.js'
import App from './app.component.jsx'
import 'material-design-icons-iconfont'
import configOptionStore from './configOptionStore.js'
const query = {
indicatorGroups: {
resource: 'indicatorGroups',
params: {
paging: false,
fields: 'id,displayName',
order: 'displayName:asc',
},
},
dataElementGroups: {
resource: 'dataElementGroups',
params: {
paging: false,
fields: 'id,displayName',
order: 'displayName:asc',
},
},
userGroups: {
resource: 'userGroups',
params: {
paging: false,
fields: 'id,displayName',
order: 'displayName:asc',
},
},
organisationUnitLevels: {
resource: 'organisationUnitLevels',
params: {
paging: false,
fields: 'id,level,displayName',
order: 'level:asc',
},
},
organisationUnitGroupSets: {
resource: 'organisationUnitGroupSets',
params: {
paging: false,
fields: 'id,displayName',
},
},
basemaps: {
resource: 'externalMapLayers',
params: {
paging: false,
fields: 'id,displayName',
filter: ['mapLayerPosition:eq:BASEMAP'],
},
},
userRoles: {
resource: 'userRoles',
params: {
paging: false,
fields: 'id,displayName',
order: 'displayName:asc',
},
},
organisationUnits: {
resource: 'organisationUnits',
params: {
paging: false,
fields: 'id,displayName',
filter: ['level:in:[1,2]'],
},
},
apps: {
resource: 'action::menu/getModules',
},
flags: {
resource: 'system/flags',
},
styles: {
resource: 'system/styles',
},
uiLocales: {
resource: 'locales/ui',
},
dbLocales: {
resource: 'locales/db',
},
userSettingsNoFallback: {
resource: 'userSettings',
params: {
useFallback: false,
},
},
}
const AppWrapper = () => {
const { d2 } = useD2()
const { apiVersion } = useConfig()
const { loading, error, data } = useDataQuery(query)
if (error) {
return (
<CenteredContent>
<p>
{i18n.t('Failed to load: {{error}}', {
error: error.message,
nsSeparator: '-:-',
})}
</p>
</CenteredContent>
)
}
if (!d2 || loading) {
return (
<CenteredContent>
<CircularLoader />
</CenteredContent>
)
}
const {
basemaps,
indicatorGroups,
dataElementGroups,
userGroups,
organisationUnitLevels,
organisationUnitGroupSets,
userRoles,
organisationUnits,
userSettingsNoFallback,
} = data
const appsModulePrefix = apiVersion >= 42 ? '' : 'app:'
const newLoginAppAvailable = apiVersion >= 41
const startModules = (data.apps.modules || []).map((module) => ({
id:
module.defaultAction.substr(0, 3) === '../'
? module.name
: appsModulePrefix + module.name,
displayName: module.displayName || module.name,
}))
const flags = (data.flags || []).map((flag) => ({
id: flag.key,
displayName: flag.name,
}))
flags.unshift({
id: 'dhis2',
displayName: i18n.t('DHIS2'),
})
if (newLoginAppAvailable) {
flags.unshift({
id: 'none',
displayName: i18n.t('No flag'),
})
}
const styles = (data.styles || []).map((style) => ({
id: style.path,
displayName: style.name,
}))
const uiLocales = (data.uiLocales || []).map((locale) => ({
id: locale.locale,
displayName:
locale.name === locale.displayName
? locale.name
: `${locale.name} — ${locale.displayName}`,
}))
const dbLocales = (data.dbLocales || []).map((locale) => ({
id: locale.locale,
displayName:
locale.name === locale.displayName
? locale.name
: `${locale.name} — ${locale.displayName}`,
}))
configOptionStore.setState({
indicatorGroups: indicatorGroups.indicatorGroups,
dataElementGroups: dataElementGroups.dataElementGroups,
userGroups: userGroups.userGroups,
organisationUnitLevels: organisationUnitLevels.organisationUnitLevels,
organisationUnitGroupSets:
organisationUnitGroupSets.organisationUnitGroupSets,
basemaps: basemaps.externalMapLayers,
userRoles: userRoles.userRoles,
organisationUnits: organisationUnits.organisationUnits,
startModules,
flags,
styles,
uiLocales,
dbLocales,
userSettingsNoFallback,
})
return (
<>
<CssVariables spacers colors />
<App d2={d2} apiVersion={apiVersion} />
</>
)
}
export default AppWrapper