Repository navigation
Premium Analytics: carry widget attributes through the registry - #53774
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 2 files.
|
louwie17
left a comment
There was a problem hiding this comment.
Thanks @retrofox, this tested well and code looks good! I added the chartType example to the Clicks widget.json on a local Docker site, and the /widget-modules record carried it through with both elements, while a duplicate id, an empty label, an unknown relevance and isValid.custom were all dropped as expected.
Left one small inline nit on the changelog entry, can be a quick fix before merging. LGTM 🚀
dognose24
left a comment
There was a problem hiding this comment.
Thanks, this looks good. I compared sanitize_widget_attributes() line by line with gutenberg_sanitize_widget_attributes() at the merge commit of WordPress/gutenberg#82485: identical apart from the element icon going through sanitize_widget_icon().
I also checked the "nothing else is needed on the client" claim: @wordpress/build 0.25.0 serializes each attribute object whole into the PHP manifest (toPhpAttributesLiteral() → toPhpValueLiteral()), element icons included, and @wordpress/widget-primitives 0.9.0 merges the record's entries over the module's by id in mergeAttributes().
Changelog scope is right too: no bundled widget declares attributes yet, so nothing is observable in a plugin.
Two small notes inline, neither blocking.
| * @since 0.9.0 | ||
| */ | ||
| const WIDGET_API_VERSION = '1.13.0'; | ||
| const WIDGET_API_VERSION = '1.14.0'; |
There was a problem hiding this comment.
#53771 also moves WIDGET_API_VERSION from 1.13.0 to 1.14.0, on an independent branch, and its 1.14.0 row in the docs says something different (that branch still has the paragraph form, this one the table). From #53778 I read the intent as one combined 1.14.0, which is fine, but whichever of the two lands second will conflict here and in dashboard-widgets.md. Suggest the second one, on rebase, replaces its 1.14.0 row with the merged wording #53778 already carries rather than bumping to 1.15.0.
| } | ||
|
|
||
| /** | ||
| * Sanitizes a widget attribute schema. An entry is a DataViews field in its |
There was a problem hiding this comment.
The same explanation now lives in three places: this docblock, the Widget_Type::$attributes docblock, and the Vocabulary table in docs/dashboard-widgets.md ("a DataViews field in its JSON form, plus the keys the dashboard reads on top of a field (relevance, so far)"). The docs table is the natural owner. Suggest this docblock keeps only what the function does, which also brings it back inside the comment budget:
/**
* Sanitizes a widget attribute schema. A malformed or empty key drops, never
* the entry; an entry without a unique string `id` drops.and the property docblock in class-widget-type.php a one-liner pointing at the docs: Attribute schema, one entry per setting of a widget instance; see docs/dashboard-widgets.md § Vocabulary.
mirrors gutenberg#82485; an element keeps its icon reference
…-attributes-registry Co-authored-by: louwie17 <lourensschep@gmail.com>
f27792e to
0f4b605
Compare
Part of WOOA7S-2176
Proposed changes
register_widget_types_from_manifest()carries theattributesA
widget.jsondeclares into the registry, sanitized bysanitize_widget_attributes().An attribute is one setting of a widget instance: a DataViews field in its JSON form (
id, the string and boolean keys,elements,filterBy,format,isValidwithoutcustom,Edit), plus the keys the dashboard reads on top of a field,relevanceso far.A malformed or empty key drops, never the entry; an entry without a unique string
iddrops.This mirrors
gutenberg_sanitize_widget_attributes()from WordPress/gutenberg#82485.Beyond upstream, an element names its
iconby reference (collection/icon-name, throughsanitize_widget_icon()): the dashboard'sjpa/toggle-groupdraws its options from it (Premium Analytics: resolve toggle group option icons by reference #53771).Widget_Type::$attributesThe
attributesfield on the/widget-modulesREST record and theattributescontexts insrc/widget-i18n.jsonmean that labels, headers, descriptions, placeholders, and option text translate with the widget's text domain.WIDGET_API_VERSIONmoves to 1.14.0: a consumer may declare attributes in its manifest and rely on the registry carrying them.@wordpress/build0.25.0 already emitsattributesinto the manifest and@wordpress/widget-primitives0.9.0 merges a record's entries over the module's byid, so nothing else is needed on the client. No bundled widget declares attributes inwidget.jsonyet; that move follows, widget by widget, once thewidget.jsonstring extraction is in place.Related product discussion/links
attributesthrough the widget pipeline WordPress/gutenberg#82485Does this pull request change what data or activity we track or use?
No.
Testing instructions
composer phpunitinprojects/packages/premium-analytics:Widget_Metadata_Testcovers the sanitizer, the translation contexts, hydration, and the REST record.To see it end-to-end, add to any widget's
widget.json, e.g.,widgets/clicks/widget.json:Rebuild
Open the dashboard and check
GET /wp-json/wpcom/v2/widget-modules: thejpa/clicksrecord carries the attribute with both elements and their icons.Before
This branch, with the testing code above:
The widget's controls then show the toggle (the attribute reaches the module's schema by
id).