From 435147b3e6203fd55bb1a03f979a23e5b15a787c Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Wed, 21 Jun 2023 16:15:01 +0200 Subject: [PATCH] chore: cleanup code and added TODO comments --- .../Visualization/IframePlugin.js | 46 ++----------------- 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/src/components/Item/VisualizationItem/Visualization/IframePlugin.js b/src/components/Item/VisualizationItem/Visualization/IframePlugin.js index 936dd7106..43403fa1c 100644 --- a/src/components/Item/VisualizationItem/Visualization/IframePlugin.js +++ b/src/components/Item/VisualizationItem/Visualization/IframePlugin.js @@ -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' @@ -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( @@ -77,8 +73,6 @@ const IframePlugin = ({ [dispatch, isFirstOfType, pluginType] ) - // const installationStatus = iframePluginStatus[pluginType] - const pluginProps = useMemo( () => ({ isVisualizationLoaded: true, @@ -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 @@ -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) @@ -258,16 +229,7 @@ const IframePlugin = ({ return (
{iframeSrc ? ( - + ) : null}
)