Skip to content

Commit

Permalink
refactor: propagate d2 needed to check installed apps
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Mar 2, 2023
1 parent d9a7f0b commit df797dd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
10 changes: 8 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ msgstr "Maps with Earth Engine layers cannot be displayed when offline"
msgid "Unable to load the plugin for this item"
msgstr "Unable to load the plugin for this item"

msgid "The plugin for rendering this item is not available"
msgstr "The plugin for rendering this item is not available"

msgid "Install the {{appName}} app from the App Hub"
msgstr "Install the {{appName}} app from the App Hub"

msgid "No data to display"
msgstr "No data to display"

Expand Down Expand Up @@ -143,8 +149,8 @@ msgstr "Event reports"
msgid "Event charts"
msgstr "Event charts"

msgid "Event visualizations"
msgstr "Event visualizations"
msgid "Line lists"
msgstr "Line lists"

msgid "Apps"
msgstr "Apps"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const DefaultPlugin = ({
load(item, visualization, {
credentials,
activeType,
d2,
options,
})

Expand All @@ -56,6 +57,7 @@ const DefaultPlugin = ({
load(item, visualization, {
credentials,
activeType,
d2,
options,
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useOnlineStatus } from '@dhis2/app-runtime'
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React, { useState, useEffect } from 'react'
Expand All @@ -23,6 +24,7 @@ const MapPlugin = ({
itemFilters,
...props
}) => {
const { d2 } = useD2()
const { offline } = useOnlineStatus()
const [initialized, setInitialized] = useState(false)

Expand Down Expand Up @@ -89,7 +91,7 @@ const MapPlugin = ({
}

const vis = getVisualization()
return pluginIsAvailable(MAP) ? (
return pluginIsAvailable(MAP, d2) ? (
<>
<DefaultPlugin
options={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import i18n from '@dhis2/d2-i18n'
import { Button, Cover, IconInfo24, colors } from '@dhis2/ui'
import uniqueId from 'lodash/uniqueId.js'
Expand Down Expand Up @@ -25,7 +26,7 @@ import getFilteredVisualization from './getFilteredVisualization.js'
import getVisualizationConfig from './getVisualizationConfig.js'
import IframePlugin from './IframePlugin.js'
import LegacyPlugin from './LegacyPlugin.js'
import MapPlugin from './MapPlugin.js'
//import MapPlugin from './MapPlugin.js'
import NoVisualizationMessage from './NoVisualizationMessage.js'
import { pluginIsAvailable } from './plugin.js'
import classes from './styles/Visualization.module.css'
Expand All @@ -43,6 +44,8 @@ const Visualization = ({
onClickNoFiltersOverlay,
...rest
}) => {
const { d2 } = useD2()

const memoizedGetFilteredVisualization = memoizeOne(
getFilteredVisualization
)
Expand Down Expand Up @@ -130,7 +133,7 @@ const Visualization = ({
)
}
default: {
return pluginIsAvailable(activeType || item.type) ? (
return pluginIsAvailable(activeType || item.type, d2) ? (
<LegacyPlugin
item={item}
activeType={activeType}
Expand Down
12 changes: 7 additions & 5 deletions src/components/Item/VisualizationItem/Visualization/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const getPluginLaunchUrl = (type, d2) => {
if (appKey) {
const appDetails = apps.find((app) => app.key === appKey)

return appDetails?.pluginLaunchUrl
// TODO replace with the plugin url
// return appDetails?.pluginLaunchUrl
return appDetails?.launchUrl
}
}

Expand Down Expand Up @@ -81,8 +83,8 @@ export const pluginIsAvailable = (type, d2) =>
Boolean(getPluginLaunchUrl(type, d2)) ||
itemTypeToGlobalVariable[type]

const loadPlugin = async (type, config, credentials) => {
if (!pluginIsAvailable(type)) {
const loadPlugin = async (type, config, credentials, d2) => {
if (!pluginIsAvailable(type, d2)) {
return
}

Expand All @@ -104,7 +106,7 @@ const loadPlugin = async (type, config, credentials) => {
export const load = async (
item,
visualization,
{ credentials, activeType, options = {} }
{ credentials, activeType, d2, options = {} }
) => {
const config = {
...visualization,
Expand All @@ -113,7 +115,7 @@ export const load = async (
}

const type = activeType || item.type
await loadPlugin(type, config, credentials)
await loadPlugin(type, config, credentials, d2)
}

export const unmount = async (item, activeType) => {
Expand Down

0 comments on commit df797dd

Please sign in to comment.