Skip to content

Commit

Permalink
chore: cleanup code and added TODO comments
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Jun 21, 2023
1 parent 0305950 commit 435147b
Showing 1 changed file with 4 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useConfig, Plugin } from '@dhis2/app-runtime'
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { CenteredContent, CircularLoader } from '@dhis2/ui'
//import postRobot from '@krakenjs/post-robot'
import PropTypes from 'prop-types'
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { useDispatch, useSelector, shallowEqual } from 'react-redux'
Expand Down Expand Up @@ -44,26 +43,23 @@ const IframePlugin = ({
const { baseUrl } = useConfig()

const { userSettings } = useUserSettings()
// const iframeRef = useRef()
const [error, setError] = useState(null)

// When this mounts, check if the dashboard is recording
const { isCached, recordingState } = useCacheableSection(dashboardId)
const recordOnNextLoad = recordingState === 'recording'

// TODO set this to false after first props transfer with true flag
const recordOnNextLoad = recordingState === 'recording'
// const [recordOnNextLoad, setRecordOnNextLoad] = useState(
// recordingState === 'recording'
// )

// const prevPluginRef = useRef()
//
const pluginType = [CHART, REPORT_TABLE].includes(activeType)
? VISUALIZATION
: activeType

const onError = () => setError('plugin')
const onInstallationStatusChange = useCallback(
//(event) => {
(installationStatus) => {
if (isFirstOfType) {
dispatch(
Expand All @@ -77,8 +73,6 @@ const IframePlugin = ({
[dispatch, isFirstOfType, pluginType]
)

// const installationStatus = iframePluginStatus[pluginType]

const pluginProps = useMemo(
() => ({
isVisualizationLoaded: true,
Expand Down Expand Up @@ -128,7 +122,7 @@ const IframePlugin = ({

const iframeSrc = getIframeSrc()

// TODO figure out how to send this message via Plugin
// TODO figure out how to send this message via Plugin without re-rendering
// useEffect(() => {
// // Tell plugin to remove cached data if this dashboard has been removed
// // from offline storage
Expand Down Expand Up @@ -188,29 +182,6 @@ const IframePlugin = ({
installationStatus,
isFirstOfType,
])
useEffect(() => {
if (iframeRef?.current) {
const listener = postRobot.on(
'installationStatus',
{
window: iframeRef.current.contentWindow,
},
(event) => {
if (isFirstOfType) {
dispatch(
acAddIframePluginStatus({
pluginType,
status: event.data.installationStatus,
})
)
}
}
)
return () => listener.cancel()
}
}, [pluginType, dispatch, visualization, iframePluginStatus, isFirstOfType])
*/
useEffect(() => {
setError(null)
Expand Down Expand Up @@ -258,16 +229,7 @@ const IframePlugin = ({
return (
<div className={classes.wrapper}>
{iframeSrc ? (
<Plugin
pluginSource={iframeSrc}
{...pluginProps}
// preserve dimensions if provided
//style={{
// width: style.width || '100%',
// height: style.height || '100%',
// border: 'none',
//}}
/>
<Plugin pluginSource={iframeSrc} {...pluginProps} />
) : null}
</div>
)
Expand Down

0 comments on commit 435147b

Please sign in to comment.