diff --git a/src/components/Item/VisualizationItem/Visualization/__tests__/Visualization.spec.js b/src/components/Item/VisualizationItem/Visualization/__tests__/Visualization.spec.js
index 57901ef4b..d9281decd 100644
--- a/src/components/Item/VisualizationItem/Visualization/__tests__/Visualization.spec.js
+++ b/src/components/Item/VisualizationItem/Visualization/__tests__/Visualization.spec.js
@@ -4,16 +4,14 @@ import { Provider } from 'react-redux'
import configureMockStore from 'redux-mock-store'
import Visualization from '../Visualization.js'
-jest.mock('@dhis2/app-runtime-adapter-d2', () => {
- return {
- useD2: jest.fn(() => ({
- d2: {
- currentUser: { username: 'rainbowDash' },
- system: { installedApps: {} },
- },
- })),
- }
-})
+jest.mock('@dhis2/analytics', () => ({
+ useCachedDataQuery: () => ({
+ currentUser: {
+ username: 'rainbowDash',
+ id: 'r3nb0d5h',
+ },
+ }),
+}))
jest.mock(
'../LegacyPlugin',
diff --git a/src/components/Item/VisualizationItem/Visualization/plugin.js b/src/components/Item/VisualizationItem/Visualization/plugin.js
index 28cad71b6..ee3acd610 100644
--- a/src/components/Item/VisualizationItem/Visualization/plugin.js
+++ b/src/components/Item/VisualizationItem/Visualization/plugin.js
@@ -24,10 +24,9 @@ const itemTypeToScriptPath = {
const hasIntegratedPlugin = (type) =>
[CHART, REPORT_TABLE, VISUALIZATION, MAP].includes(type)
-export const getPluginLaunchUrl = (type, d2, baseUrl) => {
+export const getPluginLaunchUrl = (type, apps, baseUrl) => {
// 1. lookup in api/apps for the "manually installed" app, this can be a new version for a core (bundled) app
// 2. fallback to default hardcoded path for the core (bundled) apps
- const apps = d2.system.installedApps
const appKey = itemTypeMap[type].appKey
const appDetails = appKey && apps.find((app) => app.key === appKey)
@@ -89,13 +88,13 @@ const fetchPlugin = async (type, baseUrl) => {
return await scriptsPromise
}
-export const pluginIsAvailable = (type, d2) =>
+export const pluginIsAvailable = (type, apps) =>
hasIntegratedPlugin(type) ||
- Boolean(getPluginLaunchUrl(type, d2)) ||
+ Boolean(getPluginLaunchUrl(type, apps)) ||
Boolean(itemTypeToGlobalVariable[type])
-const loadPlugin = async ({ type, config, credentials, d2 }) => {
- if (!pluginIsAvailable(type, d2)) {
+const loadPlugin = async ({ type, config, credentials }) => {
+ if (!pluginIsAvailable(type)) {
return
}
@@ -117,7 +116,7 @@ const loadPlugin = async ({ type, config, credentials, d2 }) => {
export const load = async (
item,
visualization,
- { credentials, activeType, d2, options = {} }
+ { credentials, activeType, options = {} }
) => {
const config = {
...visualization,
@@ -126,7 +125,7 @@ export const load = async (
}
const type = activeType || item.type
- await loadPlugin({ type, config, credentials, d2 })
+ await loadPlugin({ type, config, credentials })
}
export const unmount = async (item, activeType) => {
diff --git a/src/components/__tests__/App.spec.js b/src/components/__tests__/App.spec.js
index 11aeee081..2850169f8 100644
--- a/src/components/__tests__/App.spec.js
+++ b/src/components/__tests__/App.spec.js
@@ -8,7 +8,15 @@ import { apiFetchDashboards } from '../../api/fetchAllDashboards.js'
import App from '../App.js'
import { useSystemSettings } from '../SystemSettingsProvider.js'
-jest.mock('@dhis2/analytics')
+jest.mock('@dhis2/analytics', () => ({
+ useCachedDataQuery: () => ({
+ currentUser: {
+ username: 'rainbowDash',
+ id: 'r3nb0d5h',
+ },
+ }),
+ getDimensionById: jest.fn(),
+}))
jest.mock('@dhis2/app-runtime', () => ({
useDhis2ConnectionStatus: jest.fn(() => ({
isConnected: true,
@@ -52,15 +60,6 @@ jest.mock(
}
)
-jest.mock('@dhis2/app-runtime-adapter-d2', () => {
- return {
- useD2: jest.fn(() => ({
- d2: {
- currentUser: { username: 'rainbowDash' },
- },
- })),
- }
-})
jest.mock('../../pages/view', () => {
return {
ViewDashboard: function Mock() {
diff --git a/src/modules/useCacheableSection.js b/src/modules/useCacheableSection.js
index 1c4521392..f68d9884d 100644
--- a/src/modules/useCacheableSection.js
+++ b/src/modules/useCacheableSection.js
@@ -1,12 +1,12 @@
+import { useCachedDataQuery } from '@dhis2/analytics'
import { useCacheableSection as useCacheableSectionAppRuntime } from '@dhis2/app-runtime'
-import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import getCacheableSectionId from './getCacheableSectionId.js'
export const useCacheableSection = (dashboardId) => {
- const { d2 } = useD2()
+ const { currentUser } = useCachedDataQuery()
const cacheableSectionProps = useCacheableSectionAppRuntime(
- getCacheableSectionId(d2.currentUser.id, dashboardId)
+ getCacheableSectionId(currentUser.id, dashboardId)
)
return { ...cacheableSectionProps }
}
diff --git a/src/pages/edit/__tests__/ActionsBar.spec.js b/src/pages/edit/__tests__/ActionsBar.spec.js
index c076036fb..b3332f910 100644
--- a/src/pages/edit/__tests__/ActionsBar.spec.js
+++ b/src/pages/edit/__tests__/ActionsBar.spec.js
@@ -1,4 +1,3 @@
-import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { render } from '@testing-library/react'
import React from 'react'
import { Provider } from 'react-redux'
@@ -8,7 +7,6 @@ import ActionsBar from '../ActionsBar.js'
const mockStore = configureMockStore()
-jest.mock('@dhis2/app-runtime-adapter-d2')
jest.mock('@dhis2/app-runtime')
/* eslint-disable react/prop-types */
@@ -38,6 +36,12 @@ jest.mock('@dhis2/analytics', () => {
OfflineTooltip: function Mock({ children }) {
return
{children}
},
+ useCachedDataQuery: () => ({
+ currentUser: {
+ username: 'rainbowDash',
+ id: 'r3nb0d5h',
+ },
+ }),
}
})
/* eslint-enable react/prop-types */
@@ -60,12 +64,6 @@ jest.mock(
)
/* eslint-enable react/prop-types */
-useD2.mockReturnValue({
- d2: {
- currentUser: 'rainbowDash',
- },
-})
-
jest.mock('@dhis2/app-runtime', () => ({
useDhis2ConnectionStatus: jest.fn(() => ({
isConnected: true,
diff --git a/src/pages/view/CacheableViewDashboard.js b/src/pages/view/CacheableViewDashboard.js
index f2fade1b1..27e43f322 100644
--- a/src/pages/view/CacheableViewDashboard.js
+++ b/src/pages/view/CacheableViewDashboard.js
@@ -1,5 +1,5 @@
+import { useCachedDataQuery } from '@dhis2/analytics'
import { CacheableSection } from '@dhis2/app-runtime'
-import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import i18n from '@dhis2/d2-i18n'
import isEmpty from 'lodash/isEmpty.js'
import PropTypes from 'prop-types'
@@ -23,7 +23,7 @@ const CacheableViewDashboard = ({
dashboardsIsEmpty,
}) => {
const [dashboardsBarExpanded, setDashboardsBarExpanded] = useState(false)
- const { d2 } = useD2()
+ const { currentUser } = useCachedDataQuery()
if (!dashboardsLoaded) {
return
@@ -51,14 +51,14 @@ const CacheableViewDashboard = ({
)
}
- const cacheSectionId = getCacheableSectionId(d2.currentUser.id, id)
+ const cacheSectionId = getCacheableSectionId(currentUser.id, id)
return (
}>
)
diff --git a/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js b/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js
index dc55c9091..1164dca2d 100644
--- a/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js
+++ b/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js
@@ -8,13 +8,11 @@ const mockStore = configureMockStore()
const store = { selected: { id: 'dashboard1' } }
-jest.mock('@dhis2/app-runtime-adapter-d2', () => ({
- useD2: () => ({
- d2: {
- currentUser: {
- username: 'rainbowDash',
- id: 'r3nb0d5h',
- },
+jest.mock('@dhis2/analytics', () => ({
+ useCachedDataQuery: () => ({
+ currentUser: {
+ username: 'rainbowDash',
+ id: 'r3nb0d5h',
},
}),
}))
diff --git a/src/pages/view/ViewDashboard.js b/src/pages/view/ViewDashboard.js
index 286db9ffb..62baa8438 100644
--- a/src/pages/view/ViewDashboard.js
+++ b/src/pages/view/ViewDashboard.js
@@ -1,4 +1,4 @@
-import { useDhis2ConnectionStatus } from '@dhis2/app-runtime'
+import { useDhis2ConnectionStatus, useDataEngine } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { AlertStack, AlertBar } from '@dhis2/ui'
import cx from 'classnames'
@@ -36,6 +36,7 @@ const ViewDashboard = (props) => {
const [loadFailed, setLoadFailed] = useState(false)
const { isConnected: online } = useDhis2ConnectionStatus()
const { isCached } = useCacheableSection(props.requestedId)
+ const engine = useDataEngine()
useEffect(() => {
setHeaderbarVisible(true)
@@ -55,13 +56,17 @@ const ViewDashboard = (props) => {
useEffect(() => {
if (!props.passiveViewRegistered && online) {
- apiPostDataStatistics('PASSIVE_DASHBOARD_VIEW', props.requestedId)
+ apiPostDataStatistics(
+ 'PASSIVE_DASHBOARD_VIEW',
+ props.requestedId,
+ engine
+ )
.then(() => {
props.registerPassiveView()
})
.catch((error) => console.info(error))
}
- }, [props.passiveViewRegistered])
+ }, [props.passiveViewRegistered, engine])
useEffect(() => {
const loadDashboard = async () => {
diff --git a/src/pages/view/__tests__/ViewDashboard.spec.js b/src/pages/view/__tests__/ViewDashboard.spec.js
index 5ac6c8791..7821ec83b 100644
--- a/src/pages/view/__tests__/ViewDashboard.spec.js
+++ b/src/pages/view/__tests__/ViewDashboard.spec.js
@@ -8,15 +8,14 @@ import { apiPostDataStatistics } from '../../../api/dataStatistics.js'
import { apiFetchDashboard } from '../../../api/fetchDashboard.js'
import ViewDashboard from '../ViewDashboard.js'
-jest.mock('@dhis2/app-runtime-adapter-d2', () => ({
- useD2: () => ({
- d2: {
- currentUser: {
- username: 'rainbowDash',
- id: 'r3nb0d5h',
- },
+jest.mock('@dhis2/analytics', () => ({
+ useCachedDataQuery: () => ({
+ currentUser: {
+ username: 'rainbowDash',
+ id: 'r3nb0d5h',
},
}),
+ getDimensionById: jest.fn(),
}))
jest.mock('@dhis2/app-runtime', () => ({
@@ -25,6 +24,7 @@ jest.mock('@dhis2/app-runtime', () => ({
isCached: false,
recordingState: 'default',
})),
+ useDataEngine: jest.fn(),
}))
jest.mock('../../../api/fetchDashboard')