-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: lazily load plugin scripts and dependencies when needed (DHIS2-…
…10518) (#1546) * feat: dynamically load plugin scripts and dependencies when needed * chore: fix some tests * fix: wait for in-flight fetches of the same plugin type * fix: move visualizer props to DataVisualizerPlugin * fix: remove unused state * fix: change var name to avoid confusion between plugin and vis loading Co-authored-by: Jen Jones Arnesen <jennifer@dhis2.org>
- Loading branch information
1 parent
99a3a8a
commit c13eafe
Showing
9 changed files
with
227 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const config = { | ||
name: 'dashboard', | ||
type: 'app', | ||
coreApp: true, | ||
title: 'Dashboard', | ||
|
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
src/components/Item/VisualizationItem/Visualization/DataVisualizerPlugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { Suspense, useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { useD2 } from '@dhis2/app-runtime-adapter-d2' | ||
import { useUserSettings } from '../../../UserSettingsProvider' | ||
import LoadingMask from './LoadingMask' | ||
|
||
const VisualizationPlugin = React.lazy(() => | ||
import( | ||
/* webpackChunkName: "data-visualizer-plugin" */ /* webpackPrefetch: true */ '@dhis2/data-visualizer-plugin' | ||
) | ||
) | ||
|
||
const DataVisualizerPlugin = props => { | ||
const d2 = useD2() | ||
const { userSettings } = useUserSettings() | ||
const [visualizationLoaded, setVisualizationLoaded] = useState(false) | ||
|
||
return ( | ||
<Suspense fallback={<div />}> | ||
{!visualizationLoaded && <LoadingMask style={props.style} />} | ||
<VisualizationPlugin | ||
d2={d2} | ||
forDashboard={true} | ||
userSettings={{ | ||
displayProperty: userSettings.keyAnalysisDisplayProperty, | ||
}} | ||
onLoadingComplete={() => setVisualizationLoaded(true)} | ||
{...props} | ||
/> | ||
</Suspense> | ||
) | ||
} | ||
|
||
DataVisualizerPlugin.propTypes = { | ||
style: PropTypes.object, | ||
} | ||
|
||
export default DataVisualizerPlugin |
9 changes: 7 additions & 2 deletions
9
src/components/Item/VisualizationItem/Visualization/LoadingMask.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { CircularLoader } from '@dhis2/ui' | ||
|
||
import classes from './styles/LoadingMask.module.css' | ||
|
||
const LoadingMask = () => { | ||
const LoadingMask = ({ style }) => { | ||
return ( | ||
<div className={classes.center}> | ||
<div className={classes.center} style={style}> | ||
<CircularLoader /> | ||
</div> | ||
) | ||
} | ||
|
||
LoadingMask.propTypes = { | ||
style: PropTypes.object, | ||
} | ||
|
||
export default LoadingMask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.