Skip to content

feat: add easy test data for reviews, nearby locations, and mapbox in local-editor#1256

Open
benlife5 wants to merge 5 commits into
2026-custom-components-templatesfrom
local-editor-test-data
Open

feat: add easy test data for reviews, nearby locations, and mapbox in local-editor#1256
benlife5 wants to merge 5 commits into
2026-custom-components-templatesfrom
local-editor-test-data

Conversation

@benlife5

@benlife5 benlife5 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
  1. Adds a reviews toggle
    • If there's reviews data on the stream, that data is used
    • If there's no reviews data on the stream, fake reviews are injected
  2. Adds a button to add a Mapbox key
  3. Adds a button to add a Yext Content API key for Nearby Locations
    • Uses the content endpoint from the "Pages Visual Editing" prod account
DataDemo.mp4

(video pauses when I enter the api keys)

@benlife5 benlife5 changed the base branch from main to 2026-custom-components-templates July 2, 2026 15:31
@github-actions

github-actions Bot commented Jul 2, 2026

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.

benlife5 and others added 2 commits July 2, 2026 11:40

@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.

Actionable comments posted: 2

🧹 Nitpick comments (3)
packages/visual-editor/src/local-editor/LocalEditorShell.tsx (2)

435-463: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

onClick: () => any should be () => void.

The return value of onClick isn't used; any here is looser than needed and could mask an accidental non-void return elsewhere.

♻️ Suggested fix
 const ToggleButton = (props: {
   children: React.ReactNode;
-  onClick: () => any;
+  onClick: () => void;
 }) => {
🤖 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/local-editor/LocalEditorShell.tsx` around lines
435 - 463, The ToggleButton props typing is too loose because onClick is
declared as returning any even though the return value is unused. Update the
ToggleButton component in LocalEditorShell so its onClick prop is typed as void,
keeping the signature aligned with the button’s actual usage and preventing
accidental non-void returns from being accepted.

178-195: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicate currentEnv resolution logic.

The _env extraction/guard logic is duplicated verbatim between the Mapbox and Nearby Locations blocks. Also note the two blocks are inconsistent: the Mapbox block skips creating a new object when the value hasn't changed, while the Nearby Locations block always recreates the whole document unconditionally, even if the injected values are already identical.

♻️ Suggested extraction
+  const getCurrentEnv = (doc: typeof nextDocument) =>
+    "_env" in doc && doc._env && typeof doc._env === "object"
+      ? (doc._env as Record<string, unknown>)
+      : undefined;
+
   if (typeof mapboxKey === "string") {
-    const currentEnv =
-      "_env" in nextDocument &&
-      nextDocument._env &&
-      typeof nextDocument._env === "object"
-        ? (nextDocument._env as Record<string, unknown>)
-        : undefined;
+    const currentEnv = getCurrentEnv(nextDocument);

Also applies to: 197-230

🤖 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/local-editor/LocalEditorShell.tsx` around lines
178 - 195, The `_env` parsing/update logic in LocalEditorShell is duplicated
between the Mapbox and Nearby Locations sections and the two branches behave
inconsistently. Extract the shared `currentEnv` resolution and env-merging
behavior into a small helper near the existing update logic, then use it for
both Mapbox and Nearby Locations so each only clones `nextDocument` when the
injected value actually changes. Make sure the helper preserves the existing
`nextDocument` shape and update semantics used by the `mapboxKey` block.
packages/visual-editor/src/local-editor/LocalEditorShell.test.tsx (1)

174-193: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer afterEach(() => vi.restoreAllMocks()) over manual mockRestore().

If an assertion throws before reaching promptSpy.mockRestore(), the spy leaks into subsequent tests. A global afterEach avoids this class of test-isolation bug.

♻️ Suggested fix
-describe("LocalEditorShell", () => {
+describe("LocalEditorShell", () => {
+  afterEach(() => {
+    vi.restoreAllMocks();
+  });
+
   beforeEach(() => {

(and drop the individual promptSpy.mockRestore() calls)

Also applies to: 218-259

🤖 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/local-editor/LocalEditorShell.test.tsx` around
lines 174 - 193, The prompt spy in LocalEditorShell.test.tsx is being restored
manually, which can leak mocks if an assertion fails before cleanup. Add a
shared afterEach(() => vi.restoreAllMocks()) in the test file and remove the
individual promptSpy.mockRestore() calls in the affected tests, including the
ones around renderShell, fireEvent.click, and the Add Mapbox Key / Update Mapbox
Key assertions.
🤖 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.

Inline comments:
In `@packages/visual-editor/src/local-editor/LocalEditorShell.tsx`:
- Around line 157-238: The memoized local value named document in
LocalEditorShell.tsx shadows the global DOM document object throughout the
component body. Rename the React.useMemo result to a non-conflicting name (for
example, previewDocument or editedDocument) and update every downstream
reference in this component, especially the consumers near the render logic, so
any future document/global DOM access remains unambiguous.

In `@packages/visual-editor/src/vite-plugin/local-editor/scaffold.ts`:
- Around line 59-62: The new scaffold entries in scaffold.ts are not actually
commented out because the `//` is inside the string literals, so
`baseLocationStream.fields` will contain invalid field ids like
"//ref_reviewsAgg.topReviews". Update the scaffold generation near the existing
placeholder entries to match the surrounding commented-item pattern by moving
the comment marker outside the string, using the same style as the nearby
entries in the scaffold builder.

---

Nitpick comments:
In `@packages/visual-editor/src/local-editor/LocalEditorShell.test.tsx`:
- Around line 174-193: The prompt spy in LocalEditorShell.test.tsx is being
restored manually, which can leak mocks if an assertion fails before cleanup.
Add a shared afterEach(() => vi.restoreAllMocks()) in the test file and remove
the individual promptSpy.mockRestore() calls in the affected tests, including
the ones around renderShell, fireEvent.click, and the Add Mapbox Key / Update
Mapbox Key assertions.

In `@packages/visual-editor/src/local-editor/LocalEditorShell.tsx`:
- Around line 435-463: The ToggleButton props typing is too loose because
onClick is declared as returning any even though the return value is unused.
Update the ToggleButton component in LocalEditorShell so its onClick prop is
typed as void, keeping the signature aligned with the button’s actual usage and
preventing accidental non-void returns from being accepted.
- Around line 178-195: The `_env` parsing/update logic in LocalEditorShell is
duplicated between the Mapbox and Nearby Locations sections and the two branches
behave inconsistently. Extract the shared `currentEnv` resolution and
env-merging behavior into a small helper near the existing update logic, then
use it for both Mapbox and Nearby Locations so each only clones `nextDocument`
when the injected value actually changes. Make sure the helper preserves the
existing `nextDocument` shape and update semantics used by the `mapboxKey`
block.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 808b8ce3-4f73-4cbf-a167-cda8b0e2eabc

📥 Commits

Reviewing files that changed from the base of the PR and between bd27fe9 and 90f1e1d.

📒 Files selected for processing (3)
  • packages/visual-editor/src/local-editor/LocalEditorShell.test.tsx
  • packages/visual-editor/src/local-editor/LocalEditorShell.tsx
  • packages/visual-editor/src/vite-plugin/local-editor/scaffold.ts

Comment thread packages/visual-editor/src/local-editor/LocalEditorShell.tsx Outdated
Comment thread packages/visual-editor/src/vite-plugin/local-editor/scaffold.ts
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cfc0cd7e-79bc-407e-97e6-73f8d5df8673

📥 Commits

Reviewing files that changed from the base of the PR and between 33f19c8 and c3f8e5d.

📒 Files selected for processing (1)
  • packages/visual-editor/src/local-editor/LocalEditorShell.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/visual-editor/src/local-editor/LocalEditorShell.tsx

Walkthrough

LocalEditorShell now keeps local state for Mapbox and Nearby Locations keys, derives review visibility from the reviews URL param, and builds a memoized editor document that can inject or remove ref_reviewsAgg and update several document fields and env values. The header now includes prompt-driven buttons to add or update those keys and to show or hide reviews data. The editor receives the computed document, and the test suite covers the new behaviors. The scaffold generator also adds commented-out review aggregation fields.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided, so there is nothing to assess against the changeset. Add a brief description of the local-editor test-data and UI changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding local-editor test data and controls for reviews, nearby locations, and Mapbox.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch local-editor-test-data

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.

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/visual-editor/src/vite-plugin/local-editor/scaffold.ts (1)

59-62: 🎯 Functional Correctness | 🟠 Major

Duplicate: the new scaffold entries still aren't actually commented out.

The // is inside the string literal, so the generated scaffold will emit invalid field ids instead of commented-out ref_reviewsAgg lines.

🤖 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/vite-plugin/local-editor/scaffold.ts` around lines
59 - 62, The new scaffold entries in scaffold.ts are being emitted as string
literals that include //, so they are not actually commented out in the
generated editor scaffold. Update the scaffold generation logic around the
ref_reviewsAgg entries in the scaffold template to produce real commented lines,
using the existing scaffold-building code in scaffold.ts rather than embedding
// inside the field id strings.
🤖 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.

Inline comments:
In `@packages/visual-editor/src/local-editor/LocalEditorShell.tsx`:
- Around line 205-230: The `nextDocument` update in `LocalEditorShell`
overwrites `__` instead of merging it, which can drop existing document metadata
when “Add Nearby Locations Key” runs. Update the object spread in that block so
`__` is built from the current `nextDocument.__` (similar to how `_env` uses
`currentEnv`) and only sets `isPrimaryLocale: true` while preserving any other
existing keys.

---

Duplicate comments:
In `@packages/visual-editor/src/vite-plugin/local-editor/scaffold.ts`:
- Around line 59-62: The new scaffold entries in scaffold.ts are being emitted
as string literals that include //, so they are not actually commented out in
the generated editor scaffold. Update the scaffold generation logic around the
ref_reviewsAgg entries in the scaffold template to produce real commented lines,
using the existing scaffold-building code in scaffold.ts rather than embedding
// inside the field id strings.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9405300c-6bfc-427d-8d36-f5d1822683d1

📥 Commits

Reviewing files that changed from the base of the PR and between bd27fe9 and 33f19c8.

⛔ Files ignored due to path filters (1)
  • packages/visual-editor/src/components/testing/screenshots/PhotoGallerySection/[desktop] version 59 with showSectionHeading false.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
📒 Files selected for processing (3)
  • packages/visual-editor/src/local-editor/LocalEditorShell.test.tsx
  • packages/visual-editor/src/local-editor/LocalEditorShell.tsx
  • packages/visual-editor/src/vite-plugin/local-editor/scaffold.ts

Comment thread packages/visual-editor/src/local-editor/LocalEditorShell.tsx
@benlife5 benlife5 marked this pull request as ready for review July 2, 2026 18:37
},
_env: {
...currentEnv,
YEXT_PUBLIC_VISUAL_EDITOR_APP_API_KEY: nearbyLocationsKey,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this key need to be a secret? Would be easier if you didn't need to enter it manually

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