From f742582003ee55ec5dc9c24693793af9731d008f Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Thu, 3 Sep 2026 11:37:11 +0300 Subject: [PATCH 1/4] chore: enable multiple measures to be selected in a map --- .../wp-react-blocks-plugin/blocks/map/APIConfig.js | 4 +++- .../wp-react-blocks-plugin/blocks/map/Measures.jsx | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js b/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js index 34126642f..3a359a6eb 100644 --- a/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js +++ b/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js @@ -137,7 +137,9 @@ export class APIConfig extends Component { const prevTypeObject = types.filter(t => t.value === prevType).length > 0 ? types.filter(t => t.value === prevType)[0] : null - const currentType = types.filter(t => t.value === type).length > 0 ? types.filter(t => t.value === type)[0] : null + const currentType = types && types.length > 0 + ? types.find(t => t.value === type) + : null if (type != prevType && currentType) { if (prevTypeObject.supports.singleMeasure != currentType.supports.singleMeasure || (currentType.supports.singleMeasure == false && dimension2 != "none")) { diff --git a/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx b/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx index 2ad9fd61b..2f0639060 100644 --- a/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx +++ b/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx @@ -6,6 +6,7 @@ import {getTranslation} from '@devgateway/dvz-wp-commons'; const Measures = (props) => { const { currentType, + app, onMeasuresChange, onSetSingleMeasure, allMeasures, @@ -17,6 +18,9 @@ const Measures = (props) => { } } = props + const supportsMultipleMeasures = app !== 'csv' || + (currentType && currentType.supports && currentType.supports.singleMeasure === false) + const MeasureToggle = ({measure}) => { return ( { { [...new Set(allMeasures.map(p => getTranslation(p.group)))].map(g => { return ( - {allMeasures.filter(f => getTranslation(f.group) === g).map(m => )} + {allMeasures.filter(f => getTranslation(f.group) === g).map(m => + {supportsMultipleMeasures ? + : + + } + )} ) } From 3275b59191f857231895882db0d67bce4193894c Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Thu, 3 Sep 2026 11:49:07 +0300 Subject: [PATCH 2/4] chore: add toggle to toggle multiple measures --- .../blocks/map/Measures.jsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx b/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx index 2f0639060..25ca2834b 100644 --- a/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx +++ b/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx @@ -5,21 +5,18 @@ import {getTranslation} from '@devgateway/dvz-wp-commons'; const Measures = (props) => { const { - currentType, - app, onMeasuresChange, onSetSingleMeasure, allMeasures, setAttributes, attributes: { measures, - dimension2, - customMeasureLabels + customMeasureLabels, + hasMultipleMeasures } } = props - const supportsMultipleMeasures = app !== 'csv' || - (currentType && currentType.supports && currentType.supports.singleMeasure === false) + const supportsMultipleMeasures = hasMultipleMeasures const MeasureToggle = ({measure}) => { @@ -57,6 +54,13 @@ const Measures = (props) => { return <> + + setAttributes({hasMultipleMeasures: value, measures: []})} + /> + { [...new Set(allMeasures.map(p => getTranslation(p.group)))].map(g => { return ( From 1c19d249134d3485bf87befa70404e3433856f67 Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Thu, 3 Sep 2026 11:58:23 +0300 Subject: [PATCH 3/4] chore: check for potentially missing object keys before referencing them --- plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js b/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js index 3a359a6eb..37d03e29c 100644 --- a/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js +++ b/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js @@ -142,10 +142,12 @@ export class APIConfig extends Component { : null if (type != prevType && currentType) { - if (prevTypeObject.supports.singleMeasure != currentType.supports.singleMeasure || (currentType.supports.singleMeasure == false && dimension2 != "none")) { - setAttributes({measures: [], filters: []}) - } else { - setAttributes({filters: []}) + if (prevTypeObject.supports) { + if (prevTypeObject.supports.singleMeasure != currentType.supports.singleMeasure || (currentType.supports.singleMeasure == false && dimension2 != "none")) { + setAttributes({measures: [], filters: []}) + } else { + setAttributes({filters: []}) + } } } From f2980e835d15c1fec595aa345a286729d42cf778 Mon Sep 17 00:00:00 2001 From: Timothy Mugo Date: Thu, 3 Sep 2026 12:02:21 +0300 Subject: [PATCH 4/4] chore: check for potentially missing object keys before referencing them --- plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js b/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js index 37d03e29c..dbf1cf3ac 100644 --- a/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js +++ b/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js @@ -136,13 +136,13 @@ export class APIConfig extends Component { const {attributes: {type: prevType, dimension2:prevDimension2}} = prevProps - const prevTypeObject = types.filter(t => t.value === prevType).length > 0 ? types.filter(t => t.value === prevType)[0] : null + const prevTypeObject = types && types.filter(t => t.value === prevType).length > 0 ? types.filter(t => t.value === prevType)[0] : null const currentType = types && types.length > 0 ? types.find(t => t.value === type) : null if (type != prevType && currentType) { - if (prevTypeObject.supports) { + if (prevTypeObject && prevTypeObject.supports) { if (prevTypeObject.supports.singleMeasure != currentType.supports.singleMeasure || (currentType.supports.singleMeasure == false && dimension2 != "none")) { setAttributes({measures: [], filters: []}) } else {