diff --git a/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js b/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js index 34126642..dbf1cf3a 100644 --- a/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js +++ b/plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js @@ -136,14 +136,18 @@ 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 currentType = types.filter(t => t.value === type).length > 0 ? types.filter(t => t.value === type)[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.singleMeasure != currentType.supports.singleMeasure || (currentType.supports.singleMeasure == false && dimension2 != "none")) { - setAttributes({measures: [], filters: []}) - } else { - setAttributes({filters: []}) + if (prevTypeObject && prevTypeObject.supports) { + if (prevTypeObject.supports.singleMeasure != currentType.supports.singleMeasure || (currentType.supports.singleMeasure == false && dimension2 != "none")) { + setAttributes({measures: [], filters: []}) + } else { + setAttributes({filters: []}) + } } } diff --git a/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx b/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx index 2ad9fd61..25ca2834 100644 --- a/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx +++ b/plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx @@ -5,18 +5,19 @@ import {getTranslation} from '@devgateway/dvz-wp-commons'; const Measures = (props) => { const { - currentType, onMeasuresChange, onSetSingleMeasure, allMeasures, setAttributes, attributes: { measures, - dimension2, - customMeasureLabels + customMeasureLabels, + hasMultipleMeasures } } = props + const supportsMultipleMeasures = hasMultipleMeasures + const MeasureToggle = ({measure}) => { return ( { return <> + + setAttributes({hasMultipleMeasures: value, measures: []})} + /> + { [...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 ? + : + + } + )} ) }