fix: loosen item source mapping requirements for CTAs#1261
fix: loosen item source mapping requirements for CTAs#1261jwartofsky-yext wants to merge 4 commits into
Conversation
Allows itemSource to select a parent field without CTAs, even if the cards require a CTA, providing that there are text or rich_text fields available. This allows a user to user a constant value to map to the CTA instead of requiring a CTA field.
WalkthroughThis change adds a new Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/visual-editor/src/utils/itemSource/itemSourceFieldTransforms.ts (1)
201-213: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winPotential duplicate entries when
filter.typesoverlaps compatible types.If a caller sets
filter.typesto something like["type.cta", "type.string"], theflatMapexpansion produces["type.cta", "type.string", "type.rich_text_v2", "type.string"]—type.stringappears twice, once from the explicit selection and once from the CTA compatibility expansion. Depending on how downstream consumers (e.g. dropdown rendering, type matching) iterateitemSourceTypes, this could surface duplicate options or redundant checks.♻️ Proposed fix to dedupe the expanded list
return field.filter.types?.length ? [ - field.filter.types.flatMap((entityFieldType) => [ - entityFieldType, - ...(ITEM_SOURCE_TYPE_COMPATIBILITY[entityFieldType] ?? []), - ]), + [ + ...new Set( + field.filter.types.flatMap((entityFieldType) => [ + entityFieldType, + ...(ITEM_SOURCE_TYPE_COMPATIBILITY[entityFieldType] ?? []), + ]) + ), + ], ] : [];🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/visual-editor/src/utils/itemSource/itemSourceFieldTransforms.ts` around lines 201 - 213, The expansion in getNestedItemSourceTypes can emit duplicate EntityFieldTypes when field.filter.types already contains a type that also appears in ITEM_SOURCE_TYPE_COMPATIBILITY output. Update the logic in getNestedItemSourceTypes to dedupe the flattened compatible-type list before returning it, while preserving the original order of first occurrence. Keep the fix localized to this helper so downstream consumers of itemSourceTypes receive a unique set of types.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/visual-editor/src/utils/itemSource/itemSourceFieldTransforms.ts`:
- Around line 201-213: The expansion in getNestedItemSourceTypes can emit
duplicate EntityFieldTypes when field.filter.types already contains a type that
also appears in ITEM_SOURCE_TYPE_COMPATIBILITY output. Update the logic in
getNestedItemSourceTypes to dedupe the flattened compatible-type list before
returning it, while preserving the original order of first occurrence. Keep the
fix localized to this helper so downstream consumers of itemSourceTypes receive
a unique set of types.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: df273088-e9cc-49fd-8b6a-cb1e468308ca
📒 Files selected for processing (3)
packages/visual-editor/src/utils/itemSource/createItemSource.test.tspackages/visual-editor/src/utils/itemSource/createSlottedItemSource.test.tspackages/visual-editor/src/utils/itemSource/itemSourceFieldTransforms.ts
Allows itemSource to select a parent field without CTAs, even if the cards require a CTA, provided that there is a text field available.
This allows a user to user a constant value to map to the CTA instead of requiring a CTA field.
Impetus: https://yext.slack.com/archives/C02UVSE7P6W/p1783433102868479
This change would allow them to use their c_productReference linked field without having to add CTAs to the Products and link them in the pageset.
They can then set the CTAs to constant value and use text to populate the fields.