chore: enable multiple measures to be selected in a map - #150
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new app prop handling and componentDidUpdate type dereferencing can throw at runtime and should be corrected before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Re-enables multi-measure selection behavior for the Map block’s measure selector UI, while also adjusting map type handling during block updates to better tolerate missing/empty type lists.
Changes:
- Adds a
supportsMultipleMeasuresswitch to render multi-select toggles vs single-select behavior in the Measures panel. - Refines
currentTypeselection logic inAPIConfig.componentDidUpdateto avoid failing whentypesis empty. - Adds React
keyusage for measure rows in grouped rendering.
File summaries
| File | Description |
|---|---|
| plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx | Updates measures UI to conditionally support multi-select and improves list rendering. |
| plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js | Adjusts type lookup logic during updates to be more defensive when resolving the current type. |
Review details
Suppressed comments (1)
plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx:63
- The grouped
<PanelBody>elements are rendered from an array but don’t have akeyprop, which will trigger React key warnings and can lead to incorrect reconciliation when groups change.
[...new Set(allMeasures.map(p => getTranslation(p.group)))].map(g => {
return (<PanelBody title={g}>
{allMeasures.filter(f => getTranslation(f.group) === g).map(m => <PanelRow key={m.value}>
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🔵 Needs a closer look
There are confirmed runtime-crash paths in APIConfig.componentDidUpdate due to unguarded types.filter(...) and dereferencing a potentially-null prevTypeObject.
Review details
Suppressed comments (3)
Previously missed (1) — in code that hasn't changed since the last review.
plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx:66
- The grouped measures
map(g => ...)returns a<PanelBody>without akey, which will trigger React key warnings and can cause unstable panel rendering when groups change.
plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js:142
typesis now guarded forcurrentType, butprevTypeObjectstill callstypes.filter(...)unconditionally. Iftypesis everundefined/empty (which the new guard suggests can happen), this will throw before the guard is reached.
const prevTypeObject = 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
plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js:145
prevTypeObjectcan benull(e.g., previous type no longer present intypes), but this dereferencesprevTypeObject.supportsunconditionally and will throw.
if (prevTypeObject.supports.singleMeasure != currentType.supports.singleMeasure || (currentType.supports.singleMeasure == false && dimension2 != "none")) {
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
There are confirmed runtime crash risks (null/undefined access) and a missing React list key in modified code paths that should be fixed before approval.
Review details
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx:67
- The elements generated from the groups map are missing a React
keyprop, which will produce list rendering warnings and can cause unstable UI updates in the editor.
plugins/wp-react-blocks-plugin/blocks/map/APIConfig.js:147
componentDidUpdatestill has null/undefined hazards:prevTypeObjectusestypes.filter(...)without guardingtypes, andif (prevTypeObject.supports)will throw whenprevTypeObjectis null. This can crash the block whentypesis missing (e.g., older saved blocks) or when the previous type isn't present in thetypeslist.
const prevTypeObject = 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.supports.singleMeasure != currentType.supports.singleMeasure || (currentType.supports.singleMeasure == false && dimension2 != "none")) {
setAttributes({measures: [], filters: []})
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🟡 Changes recommended
There are confirmed correctness issues (missing React list key and a type-change path that can leave stale filters/measures) that should be addressed before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
plugins/wp-react-blocks-plugin/blocks/map/Measures.jsx:66
- The group created inside the map() loop is missing a React
key, which can cause unstable rendering and console warnings when groups change.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
Description
Re-enable Multiple measures to be selected in a map.
Type of change
fix:)feat:)BREAKING CHANGE:)refactor:/chore:)docs:)Affected package(s)
@devgateway/dvz-wp-commons@devgateway/create-wp-customizer@devgateway/upgrade-wp-customizerplugins/wp-react-blocks-pluginplugins/wp-react-custom-apiplugins/wp-react-custom-rest-menuChecklist
pnpm buildpasses locally