Skip to content

Commit

Permalink
fix: only use cache if plugin has PWA enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Jun 19, 2024
1 parent 240de34 commit 9f1d291
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/components/DashboardPluginWrapper/DashboardPluginWrapper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { useCacheableSection, CacheableSection } from '@dhis2/app-runtime'
import {
useCacheableSection,
CacheableSection,
useConfig,
} from '@dhis2/app-runtime'
import { CenteredContent, CircularLoader, CssVariables, Layer } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useEffect } from 'react'
Expand Down Expand Up @@ -51,6 +55,8 @@ export const DashboardPluginWrapper = ({
isParentCached,
...props
}) => {
const { pwaEnabled } = useConfig()

useEffect(() => {
// Get & send PWA installation status now
getPWAInstallationStatus({
Expand All @@ -66,20 +72,28 @@ export const DashboardPluginWrapper = ({
overflow: 'hidden',
}}
>
<CacheableSectionWrapper
id={cacheId}
isParentCached={isParentCached}
>
{children(props)}
</CacheableSectionWrapper>
{pwaEnabled ? (
<CacheableSectionWrapper
id={cacheId}
isParentCached={isParentCached}
>
{children(props)}
</CacheableSectionWrapper>
) : (
children(props)
)}
<CssVariables colors spacers elevations />
</div>
) : null
}

DashboardPluginWrapper.defaultProps = {
onInstallationStatusChange: Function.prototype,
}

DashboardPluginWrapper.propTypes = {
cacheId: PropTypes.string,
children: PropTypes.func,
isParentCached: PropTypes.bool,
cacheId: PropTypes.string.isRequired,
children: PropTypes.func.isRequired,
isParentCached: PropTypes.bool.isRequired,
onInstallationStatusChange: PropTypes.func,
}

0 comments on commit 9f1d291

Please sign in to comment.