From 712c24c9821969606ab048dc7fc5df6250b8e3ea Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Mon, 2 Dec 2024 11:41:25 +0100 Subject: [PATCH] refactor: fix sonarcloud issues --- src/components/Item/AppItem/getIframeSrc.js | 38 +++++++++------------ src/components/Item/memoizeOne.js | 4 +-- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/components/Item/AppItem/getIframeSrc.js b/src/components/Item/AppItem/getIframeSrc.js index 167724c96..403077a33 100644 --- a/src/components/Item/AppItem/getIframeSrc.js +++ b/src/components/Item/AppItem/getIframeSrc.js @@ -1,33 +1,27 @@ import { FILTER_ORG_UNIT } from '../../../actions/itemFilters.js' import { getPluginOverrides } from '../../../modules/localStorage.js' -export const getIframeSrc = (appDetails = {}, item, itemFilters) => { - switch (appDetails.appType) { - case 'APP': { - // check if there is an override for the plugin - const pluginOverrides = getPluginOverrides() +export const getIframeSrc = (item, itemFilters, appDetails = {}) => { + if (appDetails.appType === 'APP') { + // check if there is an override for the plugin + const pluginOverrides = getPluginOverrides() - if (pluginOverrides && pluginOverrides[appDetails.key]) { - return pluginOverrides[appDetails.key] - } - - return appDetails.pluginLaunchUrl + if (pluginOverrides?.[appDetails.key]) { + return pluginOverrides[appDetails.key] } - default: { - let iframeSrc = `${appDetails.launchUrl}?dashboardItemId=${item.id}` - if ( - itemFilters[FILTER_ORG_UNIT] && - itemFilters[FILTER_ORG_UNIT].length - ) { - const ouIds = itemFilters[FILTER_ORG_UNIT].map(({ id, path }) => - path ? path.split('/').slice(-1)[0] : id - ) + return appDetails.pluginLaunchUrl + } else { + let iframeSrc = `${appDetails.launchUrl}?dashboardItemId=${item.id}` - iframeSrc += `&userOrgUnit=${ouIds.join(',')}` - } + if (itemFilters[FILTER_ORG_UNIT]?.length) { + const ouIds = itemFilters[FILTER_ORG_UNIT].map(({ id, path }) => + path ? path.split('/').slice(-1)[0] : id + ) - return iframeSrc + iframeSrc += `&userOrgUnit=${ouIds.join(',')}` } + + return iframeSrc } } diff --git a/src/components/Item/memoizeOne.js b/src/components/Item/memoizeOne.js index 70a38e45e..839c10f3b 100644 --- a/src/components/Item/memoizeOne.js +++ b/src/components/Item/memoizeOne.js @@ -3,8 +3,8 @@ // Inspiration: https://github.com/alexreardon/memoize-one const memoizeOne = (fn) => { - let lastArgs = undefined - let lastValue = undefined + let lastArgs + let lastValue return (...args) => { if (