Repository navigation
Excerpt Generation: Keep the generate buttons on the WordPress 7.2 inspector - #1244
Conversation
…spector WordPress 7.2 renders the excerpt of the editor inspector from the registered entity field instead of the excerpt panel, so the plugin's `__experimentalPluginPostExcerpt` slot and DOM injection no longer reach it. On 7.2+, hand the field's `render` and `Edit` parts to a new `@ai/excerpt-field` script module (packages/excerpt-field) reusing the existing components: the summary keeps the inline generate button next to the excerpt or its placeholder, and the popover keeps the textarea with the generate button and the too-short notice. Before 7.2 the legacy registration is unchanged, gated by the new `entityFieldsApi` flag.
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1244 +/- ##
=============================================
- Coverage 85.20% 85.04% -0.16%
- Complexity 4714 4722 +8
=============================================
Files 182 182
Lines 17509 17548 +39
=============================================
+ Hits 14918 14924 +6
- Misses 2591 2624 +33
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Core lifts a field summary holding a link or button above the panel's edit button, whose hit area is stretched over the whole row, so the inline generate button also kept clicks on the excerpt text from opening the popover, unlike core's excerpt summary. Lift only the button instead, and cover the click in the e2e test.
…e it can run CI measures the coverage on the latest WordPress release, which has no Entity Fields API before 7.2, so the block handing the excerpt field to the script module never runs there and Codecov reports it uncovered. Exclude that block from the measurement (the trunk job runs its test), and test the parts running on every version: the early return while the experiment is disabled and the view config patch keeping the summary.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
|
cc: @oandregal, @ntsekouras |
| ) : ( | ||
| field.placeholder && ( | ||
| <Text className="ai-excerpt-field__placeholder"> | ||
| { field.placeholder } |
There was a problem hiding this comment.
This is good for this particular field because it's only displayed in the inspector and not in DataViews. If it were, this would result in rendering the placeholder in the DataViews layouts (table, etc.). It doesn't impact this PR, but it's something I ran into while working in WordPress/gutenberg#85842 (comment) and so I thought I'd bring it up.
There was a problem hiding this comment.
Good to know 👍 the field only renders in the inspector for now.
|
This is what I meant in my comment and I'm glad it's working well. I've glossed over the AI specific bits, but it looks good to me. |
The `wp_entity_fields_api_init` action only fires with the Entity Fields API, from core or from Gutenberg on older versions, so the callback no longer checks for it. Gutenberg brings the API to WordPress 7.0 without `wp_get_entity_view_config_hook_name()`, which is WordPress 7.1, so the view configuration filter is hooked by the hook's name instead of through the helper, and the PHPStan ignore for the helper goes.
…t tab order and has some spacing between it and the edit icon
Alternative to #1139, following the suggestion of @oandregal there to override the core
excerptfield instead of adding a panel.WordPress 7.2 renders the post summary of the inspector from the registered entity fields, so the excerpt panel slot and the DOM injection used by the excerpt generation experiment never render anything. This PR keeps the current UI on both inspectors. On 7.2+,
wp_update_entity_fields()hands therenderandEditparts of core'sexcerptfield to a new@ai/excerpt-fieldscript module (packages/excerpt-field) that reuses the existing components: the inline icon in the summary and the generate button in the popover. Before 7.2 nothing changes, unless Gutenberg (24.3+) brings the Entity Fields API: the legacy registration is skipped when the API exists.The e2e test now accepts both inspectors, so it catches the next breakage. The
showPlaceholderIfEmptyfilter is a no-op until WordPress/gutenberg#85842 lands.Use of AI Tools
AI assistance: Yes
Tool(s):
Model(s):
Used for: implementation, tests and docs; reviewed and tested by me.
Testing Instructions
Run
npm run build(the module is built by wp-build; a watch that was already running does not pick the new package up).On WordPress 7.2 beta and on 7.1, enable the Excerpt Generation experiment and open a post with at least 250 characters.
Verify the Excerpt row shows the generate icon at its end, also while the excerpt is empty.
Open the excerpt popover ("Edit Excerpt" on 7.2, "Add an excerpt" on 7.1) and verify the "Generate excerpt" button is there.
On 7.2, close it and click the excerpt text itself: the popover opens too, as it does for core's summary.
Generate from both buttons and verify the summary and the textarea update.
Open a post with less than 250 characters and verify the buttons are disabled and the popover shows the notice.
npm run test:e2e -- excerpt-generationandvendor/bin/phpunit tests/Integration/Includes/Experiments/Excerpt_Generationpass on 7.1.4 and 7.2-beta3.Screenshots
On WordPress 7.2 develop shows no generate button at all. With this PR:
Changelog Entry