From 82a52ee21ab283faebedff216ddb57c721b9a4aa Mon Sep 17 00:00:00 2001 From: Martin Ohlson Date: Mon, 30 Aug 2021 10:39:47 +0200 Subject: [PATCH 1/8] fix: update d2config schema --- src/AppWrapper.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AppWrapper.js b/src/AppWrapper.js index d428d3d7a..74d22a1d4 100644 --- a/src/AppWrapper.js +++ b/src/AppWrapper.js @@ -12,10 +12,9 @@ import './locales' const d2Config = { schemas: [ - 'chart', + 'visualization', 'map', 'report', - 'reportTable', 'eventChart', 'eventReport', 'dashboard', From 77be88e3ab967b5ed0a638fda09324f582532eb6 Mon Sep 17 00:00:00 2001 From: Martin Ohlson Date: Tue, 31 Aug 2021 09:55:15 +0200 Subject: [PATCH 2/8] fix: visualization metadata --- src/api/metadata.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/api/metadata.js b/src/api/metadata.js index 67f1113d0..6d5fc89b4 100644 --- a/src/api/metadata.js +++ b/src/api/metadata.js @@ -68,10 +68,7 @@ export const getFavoriteFields = ({ withDimensions, withOptions }) => { } export const getFavoritesFields = () => [ - `reportTable[${getFavoriteFields({ withDimensions: false }).join(',')}]`, - `chart[${['type', ...getFavoriteFields({ withDimensions: false })].join( - ',' - )}]`, + `visualization[${getFavoriteFields({ withDimensions: false }).join(',')}]`, `map[${getFavoriteFields({ withDimensions: false }).join(',')}]`, `eventReport[${getFavoriteFields({ withDimensions: false }).join(',')}]`, `eventChart[${getFavoriteFields({ withDimensions: false }).join(',')}]`, From e28f379527d38758a6edaeea6d38960773de8dce Mon Sep 17 00:00:00 2001 From: Martin Ohlson Date: Tue, 31 Aug 2021 09:56:11 +0200 Subject: [PATCH 3/8] fix: visualization propName --- src/modules/item.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/item.js b/src/modules/item.js index 6824add88..e5efd3b7f 100644 --- a/src/modules/item.js +++ b/src/modules/item.js @@ -10,8 +10,7 @@ export const getVisualizationFromItem = item => { return ( item[propName] || - item.reportTable || - item.chart || + item.visualization || item.map || item.eventReport || item.eventChart || From a7de14dddb7fd2f68ea18b8c393d107c5f00b465 Mon Sep 17 00:00:00 2001 From: Martin Ohlson Date: Tue, 31 Aug 2021 11:28:51 +0200 Subject: [PATCH 4/8] fix: reenable the dot menu --- .../Item/VisualizationItem/Visualization/plugin.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/Item/VisualizationItem/Visualization/plugin.js b/src/components/Item/VisualizationItem/Visualization/plugin.js index 84749e056..a1601ed55 100644 --- a/src/components/Item/VisualizationItem/Visualization/plugin.js +++ b/src/components/Item/VisualizationItem/Visualization/plugin.js @@ -1,9 +1,8 @@ import { - REPORT_TABLE, - CHART, MAP, EVENT_REPORT, EVENT_CHART, + VISUALIZATION, } from '../../../../modules/itemTypes' import getVisualizationContainerDomId from '../getVisualizationContainerDomId' import { loadExternalScript } from './loadExternalScript' @@ -21,7 +20,7 @@ const itemTypeToScriptPath = { [EVENT_CHART]: '/dhis-web-event-visualizer/eventchart.js', } -const hasIntegratedPlugin = type => [CHART, REPORT_TABLE].includes(type) +const hasIntegratedPlugin = type => type === VISUALIZATION export const getPlugin = async type => { if (hasIntegratedPlugin(type)) { From 74193f8f172f0384d0970531ed2127738e247e6b Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Tue, 31 Aug 2021 15:28:07 +0200 Subject: [PATCH 5/8] fix: View As works but tests broken --- src/api/metadata.js | 1 + src/components/Item/VisualizationItem/Item.js | 9 ++++++--- .../ItemContextMenu/ItemContextMenu.js | 8 ++++++-- .../Visualization/Visualization.js | 5 ++++- .../Item/VisualizationItem/Visualization/plugin.js | 7 +++++-- src/modules/itemTypes.js | 13 +++++++++++++ 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/api/metadata.js b/src/api/metadata.js index 6d5fc89b4..920fb4fd8 100644 --- a/src/api/metadata.js +++ b/src/api/metadata.js @@ -34,6 +34,7 @@ export const getAxesFields = ({ withItems }) => [ export const getFavoriteFields = ({ withDimensions, withOptions }) => { return arrayClean([ `${getIdNameFields({ rename: true }).join(',')}`, + 'type', 'displayDescription~rename(description)', withDimensions ? `${getAxesFields({ withItems: true }).join(',')}` : ``, withOptions diff --git a/src/components/Item/VisualizationItem/Item.js b/src/components/Item/VisualizationItem/Item.js index cdbb426cb..580e096aa 100644 --- a/src/components/Item/VisualizationItem/Item.js +++ b/src/components/Item/VisualizationItem/Item.js @@ -14,7 +14,10 @@ import { } from '../../../modules/dashboardModes' import { getItemHeightPx } from '../../../modules/gridUtil' import { getVisualizationId, getVisualizationName } from '../../../modules/item' -import { getDataStatisticsName } from '../../../modules/itemTypes' +import { + getDataStatisticsName, + getItemTypeForVis, +} from '../../../modules/itemTypes' import { sGetIsEditing } from '../../../reducers/editDashboard' import { sGetItemActiveType } from '../../../reducers/itemActiveTypes' import { @@ -131,9 +134,9 @@ class Item extends Component { getActiveType = () => { if (this.props.isEditing) { - return this.props.item.type + return getItemTypeForVis(this.props.item) } - return this.props.activeType || this.props.item.type + return this.props.activeType || getItemTypeForVis(this.props.item) } getAvailableHeight = ({ width, height }) => { diff --git a/src/components/Item/VisualizationItem/ItemContextMenu/ItemContextMenu.js b/src/components/Item/VisualizationItem/ItemContextMenu/ItemContextMenu.js index 003542ff9..d0e3b6600 100644 --- a/src/components/Item/VisualizationItem/ItemContextMenu/ItemContextMenu.js +++ b/src/components/Item/VisualizationItem/ItemContextMenu/ItemContextMenu.js @@ -22,7 +22,11 @@ import { import PropTypes from 'prop-types' import React, { useState, createRef } from 'react' import { getVisualizationId } from '../../../../modules/item' -import { getAppName, itemTypeMap } from '../../../../modules/itemTypes' +import { + getAppName, + itemTypeMap, + getItemTypeForVis, +} from '../../../../modules/itemTypes' import { isSmallScreen } from '../../../../modules/smallScreen' import { useSystemSettings } from '../../../SystemSettingsProvider' import { useWindowDimensions } from '../../../WindowDimensionsProvider' @@ -122,7 +126,7 @@ const ItemContextMenu = props => { {canViewAs && !loadItemFailed && ( <> type === VISUALIZATION +const hasIntegratedPlugin = type => + [CHART, REPORT_TABLE, VISUALIZATION].includes(type) export const getPlugin = async type => { if (hasIntegratedPlugin(type)) { diff --git a/src/modules/itemTypes.js b/src/modules/itemTypes.js index b52665936..4d955af9c 100644 --- a/src/modules/itemTypes.js +++ b/src/modules/itemTypes.js @@ -1,3 +1,4 @@ +import { VIS_TYPE_PIVOT_TABLE } from '@dhis2/analytics' import i18n from '@dhis2/d2-i18n' import { IconApps24, @@ -44,6 +45,17 @@ export const getDefaultItemCount = itemType => itemTypeMap[itemType].defaultItemCount || 5 export const getAppName = itemType => itemTypeMap[itemType].appName || '' +export const getItemTypeForVis = item => { + if (item.type === VISUALIZATION) { + if (item.visualization.type === VIS_TYPE_PIVOT_TABLE) { + return REPORT_TABLE + } else { + return CHART + } + } + return item.type +} + // Item type map export const itemTypeMap = { [VISUALIZATION]: { @@ -51,6 +63,7 @@ export const itemTypeMap = { endPointName: 'visualizations', propName: 'visualization', pluralTitle: i18n.t('Visualizations'), + domainType: DOMAIN_TYPE_AGGREGATE, isVisualizationType: true, appUrl: id => `dhis-web-data-visualizer/#/${id}`, appName: 'Data Visualizer', From 02fa1c29854bca73215441a90c100308752406a5 Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Tue, 31 Aug 2021 15:40:46 +0200 Subject: [PATCH 6/8] fix: tests --- .../__tests__/Visualization.spec.js | 22 +++++++++++-------- .../VisualizationItem/__tests__/Item.spec.js | 9 ++++---- src/modules/__tests__/item.spec.js | 16 +++++--------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/components/Item/VisualizationItem/Visualization/__tests__/Visualization.spec.js b/src/components/Item/VisualizationItem/Visualization/__tests__/Visualization.spec.js index 990b1c0cd..2c504bc2d 100644 --- a/src/components/Item/VisualizationItem/Visualization/__tests__/Visualization.spec.js +++ b/src/components/Item/VisualizationItem/Visualization/__tests__/Visualization.spec.js @@ -57,8 +57,8 @@ test('renders a VisualizationPlugin for CHART', () => { { { { item={{ id: 'rainbow', type: 'EVENT_CHART', - chart: { id: 'rainbowVis' }, + eventChart: { id: 'rainbowVis' }, }} activeType="EVENT_CHART" itemFilters={{}} @@ -148,7 +148,7 @@ test('renders a DefaultPlugin when activeType is EVENT_REPORT', () => { item={{ id: 'rainbow', type: 'EVENT_REPORT', - chart: { id: 'rainbowVis' }, + eventReport: { id: 'rainbowVis' }, }} activeType="EVENT_REPORT" itemFilters={{}} @@ -166,7 +166,11 @@ test('renders NoVisMessage when no visualization', () => { const { container } = render( { } const item = { - type: 'CHART', - chart: { + type: 'VISUALIZATION', + visualization: { id: 'fancychart', name: 'Fancy Chart', + type: 'COLUMN', }, } @@ -86,8 +87,8 @@ test('Visualization/Item renders edit mode', async () => { } const item = { - type: 'CHART', - chart: { + type: 'VISUALIZATION', + visualization: { id: 'fancychart', name: 'Fancy Chart', }, diff --git a/src/modules/__tests__/item.spec.js b/src/modules/__tests__/item.spec.js index c724ce1f3..f2fe14380 100644 --- a/src/modules/__tests__/item.spec.js +++ b/src/modules/__tests__/item.spec.js @@ -1,17 +1,11 @@ import { getVisualizationFromItem } from '../item' -import { - REPORT_TABLE, - CHART, - MAP, - EVENT_REPORT, - EVENT_CHART, -} from '../itemTypes' +import { VISUALIZATION, MAP, EVENT_REPORT, EVENT_CHART } from '../itemTypes' test('getVisualizationFromItem for chart', () => { const vis = 'chart visualization' const item = { - type: CHART, - chart: vis, + type: VISUALIZATION, + visualization: vis, } expect(getVisualizationFromItem(item)).toEqual(vis) @@ -20,8 +14,8 @@ test('getVisualizationFromItem for chart', () => { test('getVisualizationFromItem for table', () => { const vis = 'table visualization' const item = { - type: REPORT_TABLE, - reportTable: vis, + type: VISUALIZATION, + visualization: vis, } expect(getVisualizationFromItem(item)).toEqual(vis) From 29f1ab3d36f643c320b08f325d65bda66c4fa456 Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Tue, 31 Aug 2021 16:02:27 +0200 Subject: [PATCH 7/8] fix: add missing prop --- src/modules/itemTypes.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/itemTypes.js b/src/modules/itemTypes.js index 4d955af9c..00c20cad0 100644 --- a/src/modules/itemTypes.js +++ b/src/modules/itemTypes.js @@ -61,6 +61,7 @@ export const itemTypeMap = { [VISUALIZATION]: { id: VISUALIZATION, endPointName: 'visualizations', + dataStatisticsName: 'VISUALIZATION_VIEW', propName: 'visualization', pluralTitle: i18n.t('Visualizations'), domainType: DOMAIN_TYPE_AGGREGATE, From fe957d6282b4ba04958eb9074def33852fe4ddfe Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Tue, 31 Aug 2021 16:05:55 +0200 Subject: [PATCH 8/8] fix: simplify --- .../Item/VisualizationItem/Visualization/Visualization.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/Item/VisualizationItem/Visualization/Visualization.js b/src/components/Item/VisualizationItem/Visualization/Visualization.js index 681574008..36a32d0d8 100644 --- a/src/components/Item/VisualizationItem/Visualization/Visualization.js +++ b/src/components/Item/VisualizationItem/Visualization/Visualization.js @@ -55,11 +55,9 @@ class Visualization extends React.Component { style.width = this.props.availableWidth } - const originalType = getItemTypeForVis(item) - const visualizationConfig = this.memoizedGetVisualizationConfig( visualization, - originalType, + getItemTypeForVis(item), activeType )