Skip to content

Commit

Permalink
refactor: simplify communication for offline caching
Browse files Browse the repository at this point in the history
It should be enough to just use isParentCached for knowing when to start
recording and removing the cache in the plugins.
  • Loading branch information
edoardo committed May 27, 2024
1 parent b8bc8da commit 75857e8
Showing 1 changed file with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ const IframePlugin = ({
const [error, setError] = useState(null)

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

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

const pluginType = [CHART, REPORT_TABLE].includes(activeType)
? VISUALIZATION
Expand All @@ -60,6 +55,7 @@ const IframePlugin = ({
const onError = () => setError('plugin')
const onInstallationStatusChange = useCallback(
(installationStatus) => {
console.log('DS installation status change', installationStatus)
if (isFirstOfType) {
dispatch(
acAddIframePluginStatus({
Expand All @@ -71,11 +67,6 @@ const IframePlugin = ({
},
[dispatch, isFirstOfType, pluginType]
)
const onPropsReceived = useCallback(() => {
if (recordOnNextLoad) {
setRecordOnNextLoad(false)
}
}, [recordOnNextLoad])

const pluginProps = useMemo(
() => ({
Expand All @@ -85,15 +76,13 @@ const IframePlugin = ({
visualization,
onError,
onInstallationStatusChange,
onPropsReceived,

// For caching: ---
// Add user & dashboard IDs to cache ID to avoid removing a cached
// plugin that might be used in another dashboard also
// TODO: May also want user ID too for multi-user situations
cacheId: `${dashboardId}-${itemId}`,
isParentCached: isCached,
recordOnNextLoad,
}),
[
userSettings,
Expand All @@ -102,8 +91,6 @@ const IframePlugin = ({
itemId,
isCached,
onInstallationStatusChange,
onPropsReceived,
recordOnNextLoad,
]
)

Expand Down

0 comments on commit 75857e8

Please sign in to comment.