Skip to content

refactor: add 'ctaSelector' fieldType#1170

Merged
mkilpatrick merged 7 commits intomainfrom
cta
Apr 21, 2026
Merged

refactor: add 'ctaSelector' fieldType#1170
mkilpatrick merged 7 commits intomainfrom
cta

Conversation

@mkilpatrick
Copy link
Copy Markdown
Collaborator

Extracts the cta field logic out of YextField so it can be used as a true fieldType.

@github-actions
Copy link
Copy Markdown
Contributor

Warning: Component files have been updated but no migrations have been added. See https://github.com/yext/visual-editor/blob/main/packages/visual-editor/src/components/migrations/README.md for more information.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

Warning

Rate limit exceeded

@yext-bot has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 5 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 14 minutes and 5 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d986d61d-c510-49a5-a1f2-01a4281bfe75

📥 Commits

Reviewing files that changed from the base of the PR and between 5ed03e8 and 9f18ff6.

⛔ Files ignored due to path filters (1)
  • packages/visual-editor/src/components/testing/screenshots/Locator/[mobile] latest version default props.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
📒 Files selected for processing (26)
  • packages/visual-editor/locales/platform/cs/visual-editor.json
  • packages/visual-editor/locales/platform/da/visual-editor.json
  • packages/visual-editor/locales/platform/de/visual-editor.json
  • packages/visual-editor/locales/platform/en-GB/visual-editor.json
  • packages/visual-editor/locales/platform/en/visual-editor.json
  • packages/visual-editor/locales/platform/es/visual-editor.json
  • packages/visual-editor/locales/platform/et/visual-editor.json
  • packages/visual-editor/locales/platform/fi/visual-editor.json
  • packages/visual-editor/locales/platform/fr/visual-editor.json
  • packages/visual-editor/locales/platform/hr/visual-editor.json
  • packages/visual-editor/locales/platform/hu/visual-editor.json
  • packages/visual-editor/locales/platform/it/visual-editor.json
  • packages/visual-editor/locales/platform/ja/visual-editor.json
  • packages/visual-editor/locales/platform/lt/visual-editor.json
  • packages/visual-editor/locales/platform/lv/visual-editor.json
  • packages/visual-editor/locales/platform/nb/visual-editor.json
  • packages/visual-editor/locales/platform/nl/visual-editor.json
  • packages/visual-editor/locales/platform/pl/visual-editor.json
  • packages/visual-editor/locales/platform/pt/visual-editor.json
  • packages/visual-editor/locales/platform/ro/visual-editor.json
  • packages/visual-editor/locales/platform/sk/visual-editor.json
  • packages/visual-editor/locales/platform/sv/visual-editor.json
  • packages/visual-editor/locales/platform/tr/visual-editor.json
  • packages/visual-editor/locales/platform/zh-TW/visual-editor.json
  • packages/visual-editor/locales/platform/zh/visual-editor.json
  • packages/visual-editor/src/fields/CTASelectorField.tsx

Walkthrough

This pull request refactors CTA field selection in the visual editor by introducing a new dedicated CTASelectorField field type and simplifying the entity field selector infrastructure. The changes consolidate CTA-related utilities into a new ctaFieldUtils.ts module, remove the two-tier type-selector pattern from YextEntityFieldSelector, and update all CTA component configurations to use the simplified ctaSelector field type. The underlying control flow for CTA type resolution is preserved through runtime utility functions.

Sequence Diagram(s)

No sequence diagrams are applicable. These changes are primarily a refactoring that simplifies existing control flow rather than introducing new features or complex multi-component interactions.

Possibly related PRs

Suggested labels

create-dev-release

Suggested reviewers

  • briantstephan
  • benlife5
  • jwartofsky-yext
  • asanehisa
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a new 'ctaSelector' fieldType through refactoring.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of extracting CTA field logic out of YextField to make it a true fieldType.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cta

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/visual-editor/src/components/header/PrimaryHeaderSlot.tsx (1)

496-516: ⚠️ Potential issue | 🟠 Major

Make CTA visibility type-aware.

With YextCTAField, valid CTA types no longer always have both label and link: getDirections does not need a link, and presetImage can intentionally have an empty label. These checks can hide valid header CTAs on published pages.

🐛 Proposed fix
 import { type YextCTAField } from "../../fields/CTASelectorField.tsx";
+import { getCTAType } from "../../internal/utils/ctaFieldUtils.ts";
 import { YextComponentConfig, YextFields } from "../../fields/fields.ts";
@@
-    const primaryCTA = resolveComponentData(
-      data.props.slots.PrimaryCTASlot[0]?.props.data
-        .entityField as YextCTAField,
-      locale,
-      streamDocument
-    );
+    const primaryCTAField = data.props.slots.PrimaryCTASlot[0]?.props.data
+      .entityField as YextCTAField | undefined;
+    const primaryCTA = resolveComponentData(
+      primaryCTAField,
+      locale,
+      streamDocument
+    );
+    const primaryCTAType = getCTAType(primaryCTAField).ctaType;
+    const primaryCTAHasRenderableContent =
+      primaryCTAType === "getDirections"
+        ? !!primaryCTA?.label
+        : primaryCTAType === "presetImage"
+          ? !!primaryCTA?.link
+          : !!primaryCTA?.label && !!primaryCTA?.link;
     const showPrimaryCTA: boolean =
       data.props.slots.PrimaryCTASlot[0]?.props.data.show &&
-      !!primaryCTA?.label &&
-      !!primaryCTA?.link;
+      primaryCTAHasRenderableContent;
 
-    const secondaryCTA = resolveComponentData(
-      data.props.slots.SecondaryCTASlot[0]?.props.data
-        .entityField as YextCTAField,
-      locale,
-      streamDocument
-    );
+    const secondaryCTAField = data.props.slots.SecondaryCTASlot[0]?.props.data
+      .entityField as YextCTAField | undefined;
+    const secondaryCTA = resolveComponentData(
+      secondaryCTAField,
+      locale,
+      streamDocument
+    );
+    const secondaryCTAType = getCTAType(secondaryCTAField).ctaType;
+    const secondaryCTAHasRenderableContent =
+      secondaryCTAType === "getDirections"
+        ? !!secondaryCTA?.label
+        : secondaryCTAType === "presetImage"
+          ? !!secondaryCTA?.link
+          : !!secondaryCTA?.label && !!secondaryCTA?.link;
     const showSecondaryCTA: boolean =
       data.props.slots.SecondaryCTASlot[0]?.props.data.show &&
-      !!secondaryCTA?.label &&
-      !!secondaryCTA?.link;
+      secondaryCTAHasRenderableContent;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/visual-editor/src/components/header/PrimaryHeaderSlot.tsx` around
lines 496 - 516, The showPrimaryCTA/showSecondaryCTA booleans currently require
both primaryCTA?.label and primaryCTA?.link which incorrectly hides valid CTAs
for certain YextCTAField types; update the visibility logic in the
PrimaryHeaderSlot component (around resolveComponentData, primaryCTA,
showPrimaryCTA, secondaryCTA, showSecondaryCTA) to be type-aware: read the CTA
type (e.g., primaryCTA.type / secondaryCTA.type) and allow getDirections CTAs
without a link and allow presetImage CTAs to have an empty label (or otherwise
validate required fields per type), falling back to requiring label and/or link
for default CTA types. Ensure you preserve existing resolveComponentData usage
and only change the boolean checks that compute showPrimaryCTA and
showSecondaryCTA.
🧹 Nitpick comments (1)
packages/visual-editor/src/fields/CTASelectorField.tsx (1)

9-20: Avoid leaking an internal type through YextCTAField.

YextCTAField is exported, but its selectedType property references CTASelectionType from ../internal/utils/ctaFieldUtils.ts. Define the public selection type in this field module instead, and keep the internal utility import implementation-only.

♻️ Proposed refactor
 import {
   ctaTypeOptions,
-  type CTASelectionType,
 } from "../internal/utils/ctaFieldUtils.ts";
 import { type RenderEntityFieldFilter } from "../internal/utils/getFilteredEntityFields.ts";
 import { type EnhancedTranslatableCTA } from "../types/types.ts";
 import { pt, type MsgString } from "../utils/i18n/platform.ts";
 import { YextAutoField } from "./YextAutoField.tsx";
 
+export type CTASelectionType = NonNullable<EnhancedTranslatableCTA["ctaType"]>;
+
 export type YextCTAField = YextEntityField<EnhancedTranslatableCTA> & {
   selectedType?: CTASelectionType;
 };

Based on learnings, “Do not publicly export modules from packages/visual-editor/src/internal; keep the public API surface small and intentional.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/visual-editor/src/fields/CTASelectorField.tsx` around lines 9 - 20,
YextCTAField currently exposes the internal CTASelectionType; replace that leak
by declaring a public selection type in this module (e.g., export type
PublicCTASelection = /* union of allowed keys or string literals matching
ctaTypeOptions */) and change YextCTAField's selectedType to use this new
PublicCTASelection; keep the runtime import of ctaTypeOptions from
../internal/utils/ctaFieldUtils.ts for implementation, but remove any exported
type import (do not re-export CTASelectionType) and, if needed, map or derive
the public union from ctaTypeOptions values so the public API no longer
references the internal CTASelectionType symbol.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/visual-editor/src/components/header/PrimaryHeaderSlot.tsx`:
- Around line 496-516: The showPrimaryCTA/showSecondaryCTA booleans currently
require both primaryCTA?.label and primaryCTA?.link which incorrectly hides
valid CTAs for certain YextCTAField types; update the visibility logic in the
PrimaryHeaderSlot component (around resolveComponentData, primaryCTA,
showPrimaryCTA, secondaryCTA, showSecondaryCTA) to be type-aware: read the CTA
type (e.g., primaryCTA.type / secondaryCTA.type) and allow getDirections CTAs
without a link and allow presetImage CTAs to have an empty label (or otherwise
validate required fields per type), falling back to requiring label and/or link
for default CTA types. Ensure you preserve existing resolveComponentData usage
and only change the boolean checks that compute showPrimaryCTA and
showSecondaryCTA.

---

Nitpick comments:
In `@packages/visual-editor/src/fields/CTASelectorField.tsx`:
- Around line 9-20: YextCTAField currently exposes the internal
CTASelectionType; replace that leak by declaring a public selection type in this
module (e.g., export type PublicCTASelection = /* union of allowed keys or
string literals matching ctaTypeOptions */) and change YextCTAField's
selectedType to use this new PublicCTASelection; keep the runtime import of
ctaTypeOptions from ../internal/utils/ctaFieldUtils.ts for implementation, but
remove any exported type import (do not re-export CTASelectionType) and, if
needed, map or derive the public union from ctaTypeOptions values so the public
API no longer references the internal CTASelectionType symbol.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 915f70bc-a2e0-4248-ab45-7408deb73c39

📥 Commits

Reviewing files that changed from the base of the PR and between b7c0370 and 5ed03e8.

📒 Files selected for processing (15)
  • packages/visual-editor/src/components/contentBlocks/CTAGroup.tsx
  • packages/visual-editor/src/components/contentBlocks/CtaWrapper.tsx
  • packages/visual-editor/src/components/header/PrimaryHeaderSlot.tsx
  • packages/visual-editor/src/docs/components.md
  • packages/visual-editor/src/editor/YextEntityFieldSelector.test.tsx
  • packages/visual-editor/src/editor/YextEntityFieldSelector.tsx
  • packages/visual-editor/src/editor/YextField.test.tsx
  • packages/visual-editor/src/editor/YextField.tsx
  • packages/visual-editor/src/editor/yextEntityFieldUtils.ts
  • packages/visual-editor/src/fields/CTASelectorField.test.tsx
  • packages/visual-editor/src/fields/CTASelectorField.tsx
  • packages/visual-editor/src/fields/fields.ts
  • packages/visual-editor/src/fields/index.ts
  • packages/visual-editor/src/internal/puck/constant-value-fields/EnhancedCallToAction.tsx
  • packages/visual-editor/src/internal/utils/ctaFieldUtils.ts
💤 Files with no reviewable changes (2)
  • packages/visual-editor/src/editor/YextField.tsx
  • packages/visual-editor/src/editor/yextEntityFieldUtils.ts

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

⚠️ Deleted Translation Keys Detected

🔤 Deleted Translation Keys

noAvailableTypes

Key Languages Removed
noAvailableTypes cs,da de,en en-GB,es et,fi fr,hr hu,it ja,lt lv,nb nl,pl pt,ro sk,sv tr,zh zh-TW

noTypesFoundMsg

Key Languages Removed
noTypesFoundMsg cs,da de,en en-GB,es et,fi fr,hr hu,it ja,lt lv,nb nl,pl pt,ro sk,sv tr,zh zh-TW

asanehisa
asanehisa previously approved these changes Apr 21, 2026
Comment thread packages/visual-editor/src/fields/CTASelectorField.tsx Outdated
@mkilpatrick mkilpatrick merged commit 143da77 into main Apr 21, 2026
17 checks passed
@mkilpatrick mkilpatrick deleted the cta branch April 21, 2026 20:38
types: ["type.cta"],
};

export const CTASelectorFieldOverride = ({
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.

Why do we need this override version?

Can you add some jsDocs?

I have my robots set to create jsdocs and godocs for all non-trivial functions

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.

5 participants