-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show Idea Hub context for post based on Idea Hub idea in WordPress block editor / Gutenberg #3272
Comments
@felixarntz @aaemnnosttv A couple of things I caught out when working on this IB:
|
@asvinb Thanks for raising these points, it leads me to question a little bit the wording we use here in the first place. @marrrmarrr Is the wording like we have it in this Figma design really what we should have here? The primary concern is that this doesn't use proper language while typical WordPress notices do, i.e. full sentence (e.g. |
@felixarntz the wording in Figma is not final, it was purely to help explain the flows, and definitely open to edits. |
@marrrmarrr Sounds good, with just one remark: Let's use just "This post..." instead of "This draft post..." so that it also works for published posts based on an Idea Hub idea. @asvinb Can you update the relevant bits of the IB accordingly? In the future, to simplify this I'd recommend to not re-phrase exact wording and rather say "the copy from the ACs" or "the copy from the Figma design" or so. |
Sounds good @felixarntz . Thanks! |
Thanks, @asvinb. IB looks solid overall, as usual, but I have two comments for you:
I think we need to introduce a new approach of enqueueing Gutenberg-related assets that will follow the similar logic that we use for regular admin assets. Here is what we need to do:
cc @felixarntz @aaemnnosttv in case you want to add or change something
Let's use the localStorage instead of cookies. |
@eugene-manuilov +1 for the suggested approach! We can later also consider implementing similar infrastructure for any frontend assets (which we'll need for some future functionality that has been discussed in the past). |
@eugene-manuilov I'm not sure we should replicate |
@aaemnnosttv yes, we can add a context ( |
@eugene-manuilov IB updated to use localStorage instead of cookies. Once @aaemnnosttv, @felixarntz and you are aligned on the way to enqueue Gutenberg assets, I'll update the IB with your approach. |
QA ✅Confirmed the idea hub banner is displayed on a Gutenberg post in draft mode. Was able to close the banner properly and confirmed the dialogue is correct. One thing I noticed is the banner doesn't come back if the user closes it, leaves the drafted post without saving any edits then navigates back into the draft. Moving to approval. |
The WordPress block editor (Gutenberg) should indicate if the current post is a draft based on an Idea Hub idea.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Idea_Hub
class in PHP), if necessary for the current post. Other than typical for Site Kit JS code, the code here should actually rely on WordPress's included versions of@wordpress/*
dependencies (e.g. referencewp.data
instead of@wordpress/data
, and includewp-data
in the dependencies for the asset in PHP) and not come with any of our own bundled dependencies, to not double-load dependencies and minimize the footprint in the block editor.Implementation Brief
PHP
Asset
class:CONTEXT_ADMIN_GLOBAL = 'admin-global'
CONTEXT_ADMIN_POST_EDITOR = 'admin-post-editor'
CONTEXT_ADMIN_POSTS = 'admin-posts'
CONTEXT_ADMIN_SITEKIT = 'admin-sitekit'
'load_contexts' => array( self::CONTEXT_ADMIN_SITEKIT ),
to the array of default values for the$args
property.has_context( $context )
that returnsTRUE
if the incoming$context
exists in the$this->args['load_contexts']
array.enqueue_assets
method of theModule_With_Assets
interface to accept$context = Asset::CONTEXT_ADMIN_SITEKIT
argument.enqueue_assets
method of theModule_With_Assets_Trait
trait to have the same new$context = Asset::CONTEXT_ADMIN_SITEKIT
argument and to filter out assets that don't have provided context before enqueueing assets.enqueue_block_editor_assets
action in theAssets::register
method to enqueue registered gutenberg assets. UseAssets::get_assets()
method to return registered assets and filter out assets that don't support theCONTEXT_ADMIN_POST_EDITOR
context.Idea_Hub::setup_assets
method to define a new Script for thedist/js/googlesitekit-idea-hub-notice.js
with theCONTEXT_ADMIN_POST_EDITOR
context andwp-data
as a dependency.JS
Create
assets/js/googlesitekit-idea-hub-notice.js
which has theshowIdeaHubNotice
function and the file which will be enqueued in the block editor only.Update
webpack.config.js
to add a new entry for the above file similar toanalytics-advanced-tracking
.The
showIdeaHubNotice
function should do the following:getEditedPostAttribute
selector ofcore/editor
data store. As per the IB,wp.data
should be used. For e.g:googlesitekitpersistent_idea_name
googlesitekitpersistent_idea_text
googlesitekitpersistent_idea_topics
setItem
andgetItem
fromassets/js/googlesitekit/api/cache.js
.getItem
function to check if there is an item in local storage with the keymodules::idea-hub::dismissed-editor-notice-<post_ID>
where<post_ID>
is the ID of the currently edited post. To get the current post ID, query thecore/editor
data store via thegetCurrentPostId
selector.cacheHit
isfalse
from the result ofgetItem
, then the user has not dismissed the notice. The Gutenberg notice API will be used to display the notice but theonDismiss
callback did not work until recently. To circumvent that, we can create listen to data store changes checking whether the notice is still present on the page or has been dismissed.createInfoNotice
action of thecore/notices
data store. For e.g:{idea}
is the value from the post meta with thegooglesitekitpersistent_idea_text
key.id
of the notice should begooglesitekit-idea-hub-notice
.onDismiss
property does not work, listen to the data store to see if the notice is still present.hasNotice
which returnstrue
if the notice id defined in the previous bullet point is in the list of notices. To get the list of notices, use thegetNotices
selector of thecore/notice
data store.handleDataChange
change, which checks whetherhasNotice
returnstrue
. If this is the case, then the notice is currently being displayed on the page. IfhasNotice
returnsfalse
, this means that the user has dismissed the notice. In that case, do the following:setItem
to set the keymodules::idea-hub::dismissed-editor-notice-<post_ID>
to havetrue
as value.key
andvalue
parameters to thesetItem
function since the default parameters set the expiry for the item in local storage to 1 hour.subscribe
function ofwp.data
, passinghandleDataChange
as parameter. Thesubscribe
function returns a unsubscribe function used to stop the subscription. This should occur in thehandleDataChange
function whenhasNotice
returnsfalse
.cacheHit
istrue
from the result ofgetItem
, do not do anything. It means that the user has seen the notice and dismissed it in the past hour.POC for listening to data changes: Show Idea Hub context for post based on Idea Hub idea in WordPress block editor / Gutenberg #3272 (comment)
Test Coverage
Visual Regression Changes
QA Brief
To the engineer writing the QA Brief: Similar to #3271, this issue should be testable by our QA team and not require
QA: Eng
. Include a sample datastore call to do in the browser console (e.g.window.googlesitekit.data.dispatch( 'modules/idea-hub' ).createIdeaDraftPost( ... )
) so that a draft post is created that can then be checked.Changelog entry
The text was updated successfully, but these errors were encountered: