Fix targeted-block docs: row labels and stale code example#946
Open
sirugh wants to merge 2 commits into
Open
Conversation
The example tables and reference list used `segments`, `groups`, and `cartRules` as row labels. readBlockConfig() normalizes row labels via toClassName(), which only replaces non-alphanumeric characters, so single camelCase words don't get a dash inserted: `cartRules` becomes `cartrules`, not `cart-rules`. The block's decorate() function destructures `customer-segments`, `customer-groups`, and `cart-rules`, so none of the documented labels matched — following the doc as written meant the block silently never activated. Row labels are now `Customer Segments`, `Customer Groups`, and `Cart Rules` (space-separated, consistent with how other multi-word settings are documented elsewhere in this repo, e.g. section-metadata's `Column Width`), which normalize to the keys the code actually reads.
Same root cause as the previous commit: this code example destructured segments/groups/cartRules straight off blockConfig and passed them directly into personalizationData. The actual block in aem-boilerplate-commerce reads 'customer-segments'/'customer-groups'/'cart-rules' (matching the row labels authors type in da.live) and runs each value through prepareIds(), which splits the comma-separated list and base64-encodes each ID with btoa() before handing it to the TargetedBlock container. The example was missing that step entirely, so copying it verbatim would pass raw, un-encoded IDs into personalizationData.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
targeted-blockexample tables and reference list usedsegments,groups, andcartRulesas row labels.readBlockConfig()normalizes row labels viatoClassName(), which lowercases and replaces non-alphanumeric characters with-. A single camelCase word likecartRuleshas no non-alphanumeric character to replace, so it normalizes tocartrules, notcart-rules.blocks/targeted-block/targeted-block.jsdestructurescustomer-segments,customer-groups, andcart-rulesfrom the config — none of which matched the documented labels, so following the doc as written means the block's targeting conditions are silently never read. Updated row labels toCustomer Segments,Customer Groups, andCart Rules, which normalize correctly.TargetedBlockcontainer docs'decorate()code example had the same root cause: it destructuredsegments/groups/cartRulesstraight offblockConfigand passed them directly intopersonalizationData, skipping theprepareIds()step the real block uses to split each comma-separated value and base64-encode (btoa) every ID. Updated the example to matchaem-boilerplate-commerce/blocks/targeted-block/targeted-block.js.Test plan
Customer Segments/Customer Groups/Cart Rulesnormalize tocustomer-segments/customer-groups/cart-rulesviatoClassName()inaem-boilerplate-commerce/scripts/aem.jsdecorate()example matches currentaem-boilerplate-commerce/blocks/targeted-block/targeted-block.js