Repository navigation
fix: make artisanpack/post-title editable inline against the live entity - #548
Conversation
The post-title block edit was a readonly placeholder, so focusing it and
typing did nothing — the canvas displayed the loaded title (via
`useEntityRecord`) but offered no setter path. Replaces the placeholder
with a hybrid edit:
1. Stamped `_resolvedTitle` attribute → readonly (unchanged).
2. `artisanpack/postPreview` query-loop context → readonly preview
(unchanged).
3. Live entity in scope (`postType` + `postId`, no `queryId`) →
editable `PlainText` wired through the core-data shim's
`useEntityProp('postType', postType, 'title', postId)`. Typing
stages an `editEntityRecord` edit, the canvas re-renders via
`useSelect`'s subscription, and `editor-app`'s `stagedEntityEdits`
watch re-arms the metadata-save debounce on the same cycle as
sidebar edits.
4. No entity in scope → placeholder label (unchanged).
Adds a single-mounted-Probe regression test for `useEntityProp` to
confirm the shim's setter does re-render the consumer, and updates the
live-entity test suite with a PlainText mock + a typing test that
asserts both the visible re-render and the staged
`getEntityRecordEdits` payload.
Closes #546
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReplace factory placeholder with PostTitleEdit: stamped resolved → query-preview → live editable via useEntityProp → placeholder. Add PlainText textarea test mocks, rewrite post-title tests to assert textarea display-value and typing/edit propagation, and add a useEntityProp setter re-render test. ChangesPost Title Block Live Entity Editing
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
resources/js/visual-editor/blocks/post-title/edit.tsx (1)
161-161: 💤 Low valueConsider adding a clarifying comment for the condition.
The condition
titleText !== '' || editedTitle !== undefinedcorrectly handles the resolver-in-flight case (as documented in the module docblock), but the logic is subtle. A brief inline comment would help future maintainers understand why we check both conditions:// Render editable PlainText if the title is non-empty OR if the // entity has resolved (editedTitle !== undefined). This falls through // to the placeholder only when the resolver is still in flight. if ( titleText !== '' || editedTitle !== undefined ) {This is a minor readability improvement rather than a functional issue.
🤖 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 `@resources/js/visual-editor/blocks/post-title/edit.tsx` at line 161, Add a brief inline comment above the conditional that checks "titleText !== '' || editedTitle !== undefined" explaining intent: clarify that we render the editable PlainText when the title has content OR when the entity has resolved (editedTitle !== undefined), and only show the placeholder while the resolver is still in flight; reference the variables titleText and editedTitle and place the comment immediately above the if condition in edit.tsx near the PlainText rendering logic.
🤖 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 `@resources/js/visual-editor/blocks/post-title/edit.tsx`:
- Line 161: Add a brief inline comment above the conditional that checks
"titleText !== '' || editedTitle !== undefined" explaining intent: clarify that
we render the editable PlainText when the title has content OR when the entity
has resolved (editedTitle !== undefined), and only show the placeholder while
the resolver is still in flight; reference the variables titleText and
editedTitle and place the comment immediately above the if condition in edit.tsx
near the PlainText rendering logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d60bfc9a-be46-44c2-a788-dad413f9c7ed
📒 Files selected for processing (4)
resources/js/visual-editor/blocks/_shared/__tests__/entity-placeholder-live-entity.test.tsxresources/js/visual-editor/blocks/_shared/__tests__/entity-placeholder-query-preview.test.tsxresources/js/visual-editor/blocks/post-title/edit.tsxresources/js/visual-editor/vendor/__tests__/core-data-shim.test.tsx
Inline comment explaining the editable-vs-placeholder branch on `titleText !== '' || editedTitle !== undefined`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Description
The
artisanpack/post-titleblock edit was a readonly placeholder, so focusing the Title block in the post editor canvas and typing did nothing — the canvas displayed the loaded title (viauseEntityRecord) but offered no setter path. This PR replaces the placeholder with a hybrid edit that becomes editable inline when a single page/post is in scope.Closes: #546
Type of Change
Related Issue
Issue: #546
Motivation and Context
Users expect the post-title block to behave like upstream
core/post-title— type a character, watch the canvas update in real time, and have the edit ride the same metadata-save loop as the sidebar fields. This PR closes that gap without regressing the readonly preview paths the_resolved*stamp, query-loop preview, and live-entity-as-readonly callers depend on.Changes Made
resources/js/visual-editor/blocks/post-title/edit.tsxas a hybrid edit with explicit priority:_resolvedTitlestamped → readonly (unchanged).artisanpack/postPreviewquery-loop context → readonly preview (unchanged).postType+postId, noqueryId) → editablePlainTextwired through the core-data shim'suseEntityProp('postType', postType, 'title', postId).editEntityRecordviauseEntityProp's setter;editor-app's existingstagedEntityEditsuseSelectpicks up the edit and re-arms the metadata-save debounce on the same cycle as sidebar edits — no new wiring on the persistence side.useEntityPropincore-data-shim.test.tsxthat confirms the shim's setter does re-render the consumer (rules out the OP's hypothesis about the setter not firing).entity-placeholder-live-entity.test.tsxwith aPlainTextmock, switched live-entity assertions fromgetByTexttogetByDisplayValue, added a typing test that asserts both the visible re-render and the stagedgetEntityRecordEditspayload, and added a query-loop-readonly assertion.PlainTextmock toentity-placeholder-query-preview.test.tsxso the edit module's import resolves.How Has This Been Tested?
Testing Environment:
release/1.0Tests Performed:
npx vitest run)../vendor/bin/pest --filter=PostTitle).artisanpack/queryloop: title block still renders as readonly preview (not editable).Accessibility Tests Run
PlainTextuses the same focus/typing semantics as upstreamcore/post-title.useBlockProps()block wrapper.Details: No new ARIA surface introduced; the editable element is
@wordpress/block-editor'sPlainText, which carries the same labelling story as the rest of the editor's inline edit fields.Tests Added
Test details:
useEntityPropre-render regression test against a single mounted Probe (core-data-shim.test.tsx).entity-placeholder-live-entity.test.tsx).entity-placeholder-live-entity.test.tsx).getByDisplayValuefor the now-editable post-title.Documentation
edit.tsxdocuments the resolution priority and the link to Post editor title block reads correctly but does not update as the user types #546.Pre-Submission Checklist
Summary by CodeRabbit
Tests
Refactor