Skip to content

fix: loosen item source mapping requirements for CTAs#1261

Open
jwartofsky-yext wants to merge 4 commits into
mainfrom
loosenItemMappingRequirements
Open

fix: loosen item source mapping requirements for CTAs#1261
jwartofsky-yext wants to merge 4 commits into
mainfrom
loosenItemMappingRequirements

Conversation

@jwartofsky-yext

@jwartofsky-yext jwartofsky-yext commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@jwartofsky-yext jwartofsky-yext self-assigned this Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This change adds a new ITEM_SOURCE_TYPE_COMPATIBILITY lookup mapping entity field types to compatible fallback types, currently mapping type.cta to type.string and type.rich_text_v2. The getNestedItemSourceTypes function is updated to expand filter.types on entity fields using this compatibility map, rather than returning the listed types as-is. New test cases in createItemSource.test.ts and createSlottedItemSource.test.ts verify that a cta-filtered mapping field produces an expanded itemSourceTypes list including the compatible types.

Suggested reviewers: asanehisa

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: loosening CTA item source mapping requirements.
Description check ✅ Passed The description matches the PR changes and explains the relaxed CTA mapping behavior.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch loosenItemMappingRequirements

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/visual-editor/src/utils/itemSource/itemSourceFieldTransforms.ts (1)

201-213: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Potential duplicate entries when filter.types overlaps compatible types.

If a caller sets filter.types to something like ["type.cta", "type.string"], the flatMap expansion produces ["type.cta", "type.string", "type.rich_text_v2", "type.string"]type.string appears twice, once from the explicit selection and once from the CTA compatibility expansion. Depending on how downstream consumers (e.g. dropdown rendering, type matching) iterate itemSourceTypes, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 99d3414 and ffad2bb.

📒 Files selected for processing (3)
  • packages/visual-editor/src/utils/itemSource/createItemSource.test.ts
  • packages/visual-editor/src/utils/itemSource/createSlottedItemSource.test.ts
  • packages/visual-editor/src/utils/itemSource/itemSourceFieldTransforms.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant