Skip to content

Commit d652095

Browse files
committed
1 parent 4da583c commit d652095

3 files changed

Lines changed: 36 additions & 33 deletions

File tree

src/common/loadRoutes.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/common/plugins/loader.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export async function loadUsageDashboard() {
2+
try {
3+
// webpack won't try to resolve this at build time
4+
// eslint-disable-next-line global-require, import/no-unresolved
5+
/*eslint no-undef: 0*/
6+
const mod = await import("ocl-analytics-web");
7+
/*eslint no-console: 0*/
8+
return mod.UsageDashboard || mod.default || null;
9+
} catch (e) {
10+
return null;
11+
}
12+
}

src/components/app/App.jsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import ImportHome from '../imports/ImportHome'
3737
import ConceptsComparison from '../concepts/ConceptsComparison'
3838
import MappingsComparison from '../mappings/MappingsComparison'
3939
import CheckAuth from './CheckAuth'
40-
import { loadUsageDashboard } from "../../common/loadRoutes";
40+
import { loadUsageDashboard } from "../../common/plugins/loader";
4141
import UserChip from '../users/UserChip'
4242
import UserTooltip from '../users/UserTooltip'
4343

@@ -63,12 +63,14 @@ const SessionUserRoute = ({component: Component, ...rest}) => (
6363
/>
6464
)
6565

66-
const StaffUserRoute = ({component: Component, componentProps={}, ...rest}) => (
66+
const StaffUserRoute = ({component: Component, componentProps={}, ...rest}) => {
67+
return (
6768
<Route
6869
{...rest}
6970
render={props => getCurrentUser()?.is_staff ? <Component {...props} {...componentProps} /> : <Error404 />}
7071
/>
71-
)
72+
)
73+
}
7274

7375
const App = props => {
7476
const [networkError, setNetworkError] = React.useState(false)
@@ -133,7 +135,10 @@ const App = props => {
133135
const [UsageDashboard, setUsageDashboard] = React.useState(null);
134136

135137
React.useEffect(() => {
136-
ANALYTICS_URL ? loadUsageDashboard().then(setUsageDashboard) : null
138+
if(ANALYTICS_URL)
139+
loadUsageDashboard().then(comp => {
140+
setUsageDashboard(() => comp)
141+
})
137142
}, []);
138143

139144
const repoTabs = ['concepts', 'mappings', 'versions', 'summary', 'about', 'references']
@@ -170,6 +175,21 @@ const App = props => {
170175
}}
171176
/>
172177
}
178+
{
179+
UsageDashboard &&
180+
<StaffUserRoute
181+
exact
182+
path='/admin/users/:user'
183+
component={UsageDashboard}
184+
componentProps={{
185+
APIService: APIService,
186+
currentUser: getCurrentUser(),
187+
ANALYTICS_URL: ANALYTICS_URL,
188+
UserChip: UserChip,
189+
UserTooltip: UserTooltip
190+
}}
191+
/>
192+
}
173193
<AuthenticationRequiredRoute exact path={`/:ownerType(users|orgs)/:owner/sources/:repo/:repoVersion/concepts/$match`} component={RepoConceptsMatch} />
174194
<AuthenticationRequiredRoute exact path={`/:ownerType(users|orgs)/:owner/repos/new/:step?`} component={RepoCreate} />
175195
<AuthenticationRequiredRoute exact path={`/:ownerType(users|orgs)/:owner/:repoType(sources|collections)/:repo/edit/:step?`} component={RepoCreate} />

0 commit comments

Comments
 (0)