1
1
import { useCacheableSection , CacheableSection } from '@dhis2/app-runtime'
2
2
import { CenteredContent , CircularLoader , Layer } from '@dhis2/ui'
3
- import postRobot from '@krakenjs/post-robot'
4
3
import PropTypes from 'prop-types'
5
4
import React , { useEffect } from 'react'
6
5
import { Visualization } from './components/Visualization/Visualization.js'
@@ -34,17 +33,6 @@ const CacheableSectionWrapper = ({
34
33
// eslint-disable-next-line react-hooks/exhaustive-deps
35
34
} , [ cacheNow ] )
36
35
37
- useEffect ( ( ) => {
38
- const listener = postRobot . on (
39
- 'removeCachedData' ,
40
- // todo: check domain too; differs based on deployment env though
41
- { window : window . parent } ,
42
- ( ) => remove ( )
43
- )
44
-
45
- return ( ) => listener . cancel ( )
46
- } , [ remove ] )
47
-
48
36
useEffect ( ( ) => {
49
37
// Synchronize cache state on load or prop update
50
38
// -- a back-up to imperative `removeCachedData`
@@ -69,7 +57,8 @@ CacheableSectionWrapper.propTypes = {
69
57
}
70
58
71
59
const PluginWrapper = ( props ) => {
72
- const { onInstallationStatusChange, ...propsFromParent } = props
60
+ const { onInstallationStatusChange, onPropsReceived, ...propsFromParent } =
61
+ props
73
62
74
63
useEffect ( ( ) => {
75
64
// Get & send PWA installation status now
@@ -78,27 +67,34 @@ const PluginWrapper = (props) => {
78
67
} ) . then ( onInstallationStatusChange )
79
68
} , [ onInstallationStatusChange ] )
80
69
81
- return propsFromParent ? (
82
- < div
83
- style = { {
84
- display : 'flex' ,
85
- height : '100%' ,
86
- overflow : 'hidden' ,
87
- } }
88
- >
89
- < CacheableSectionWrapper
90
- id = { propsFromParent . cacheId }
91
- cacheNow = { propsFromParent . recordOnNextLoad }
92
- isParentCached = { propsFromParent . isParentCached }
70
+ if ( propsFromParent ) {
71
+ onPropsReceived ( )
72
+
73
+ return (
74
+ < div
75
+ style = { {
76
+ display : 'flex' ,
77
+ height : '100%' ,
78
+ overflow : 'hidden' ,
79
+ } }
93
80
>
94
- < Visualization { ...propsFromParent } />
95
- </ CacheableSectionWrapper >
96
- </ div >
97
- ) : null
81
+ < CacheableSectionWrapper
82
+ id = { propsFromParent . cacheId }
83
+ cacheNow = { propsFromParent . recordOnNextLoad }
84
+ isParentCached = { propsFromParent . isParentCached }
85
+ >
86
+ < Visualization { ...propsFromParent } />
87
+ </ CacheableSectionWrapper >
88
+ </ div >
89
+ )
90
+ } else {
91
+ return null
92
+ }
98
93
}
99
94
100
95
PluginWrapper . propTypes = {
101
96
onInstallationStatusChange : PropTypes . func ,
97
+ onPropsReceived : PropTypes . func ,
102
98
}
103
99
104
100
export default PluginWrapper
0 commit comments