Skip to content

Commit

Permalink
fix: support outlier table plugin (DHIS2-16751)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Feb 16, 2024
1 parent 7a12d98 commit 5b7f9d8
Show file tree
Hide file tree
Showing 3 changed files with 458 additions and 442 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@dhis2/d2-ui-interpretations": "^7.4.3",
"@dhis2/d2-ui-mentions-wrapper": "^7.4.3",
"@dhis2/d2-ui-rich-text": "^7.4.3",
"@dhis2/ui": "^8.14.0",
"@dhis2/ui": "^9.2.0",
"@krakenjs/post-robot": "^11.0.0",
"classnames": "^2.3.2",
"d2": "^31.10.0",
Expand Down Expand Up @@ -64,5 +64,8 @@
"moduleNameMapper": {
"^.+\\.(css|sass|scss)$": "identity-obj-proxy"
}
},
"resolutions": {
"@dhis2/ui": "^9.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { VIS_TYPE_OUTLIER_TABLE } from '@dhis2/analytics'

Check failure on line 1 in src/components/Item/VisualizationItem/ItemContextMenu/ViewAsMenuItems.js

View workflow job for this annotation

GitHub Actions / lint

VIS_TYPE_OUTLIER_TABLE not found in '@dhis2/analytics'

Check failure on line 1 in src/components/Item/VisualizationItem/ItemContextMenu/ViewAsMenuItems.js

View workflow job for this annotation

GitHub Actions / lint

VIS_TYPE_OUTLIER_TABLE not found in '@dhis2/analytics'

Check failure on line 1 in src/components/Item/VisualizationItem/ItemContextMenu/ViewAsMenuItems.js

View workflow job for this annotation

GitHub Actions / lint

VIS_TYPE_OUTLIER_TABLE not found in '@dhis2/analytics'
import i18n from '@dhis2/d2-i18n'
import { IconVisualizationColumn16, IconTable16, IconWorld16 } from '@dhis2/ui'
import PropTypes from 'prop-types'
Expand Down Expand Up @@ -31,17 +32,31 @@ const ViewAsMenuItems = ({

const onViewMap = () => onActiveTypeChanged(MAP)

const notSupported = type === MAP && !getThematicMapViews(visualization)
const notSupported =
(type === MAP && !getThematicMapViews(visualization)) ||
(type === CHART && visualization.type === VIS_TYPE_OUTLIER_TABLE)

const getNotSupportedMessage = (viewAs) => {
if (type === MAP && !getThematicMapViews(visualization)) {
return viewAs === 'chart'
? i18n.t("This map can't be displayed as a chart")
: i18n.t("This map can't be displayed as a table")
}

if (type === CHART && visualization.type === VIS_TYPE_OUTLIER_TABLE) {
return viewAs === 'table'
? i18n.t("This visualization can't be displayed as a table")
: i18n.t("This visualization can't be displayed as a map")
}

return null
}

return (
<>
{![CHART, EVENT_CHART].includes(activeType) && (
<MenuItem
tooltip={
notSupported
? i18n.t("This map can't be displayed as a chart")
: null
}
tooltip={getNotSupportedMessage('chart')}
label={i18n.t('View as Chart')}
onClick={onViewChart}
disabled={notSupported}
Expand All @@ -52,11 +67,7 @@ const ViewAsMenuItems = ({
activeType
) && (
<MenuItem
tooltip={
notSupported
? i18n.t("This map can't be displayed as a table")
: null
}
tooltip={getNotSupportedMessage('table')}
label={i18n.t('View as Table')}
onClick={onViewTable}
disabled={notSupported}
Expand All @@ -65,8 +76,10 @@ const ViewAsMenuItems = ({
)}
{hasMapView(type) && activeType !== MAP && (
<MenuItem
tooltip={getNotSupportedMessage('map')}
label={i18n.t('View as Map')}
onClick={onViewMap}
disabled={notSupported}
icon={<IconWorld16 />}
/>
)}
Expand Down
Loading

0 comments on commit 5b7f9d8

Please sign in to comment.