Skip to content
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 posts based on Idea Hub idea in WordPress posts list table #3271

Closed
felixarntz opened this issue May 3, 2021 · 8 comments
Labels
Module: Idea Hub Google Idea Hub module related issues P0 High priority Rollover Issues which role over to the next sprint Type: Enhancement Improvement of an existing feature
Milestone

Comments

@felixarntz
Copy link
Member

felixarntz commented May 3, 2021

The WordPress posts list table should indicate which posts are drafts created on an Idea Hub idea.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Every WordPress draft post that was created based on Idea Hub idea (i.e. has idea metadata set, see Implement infrastructure for storing Idea Hub idea information with WordPress posts #3157) should be indicated as such in the WordPress admin posts list table.
  • Instead of just "Draft", the annotation that WordPress adds by default should be modified to look similar to what it is in this Figma file, referencing the idea text from the post metadata.
  • The change should be implemented fully on the server-side, i.e. don't load any extra Site Kit JS here.
  • This should only be adjusted for WordPress draft posts based on Idea Hub ideas, not for published posts.

Implementation Brief

In /includes/Modules/Idea_Hub.php, update the function public function register()

Add a check for if ( $this->is_connected() ) {
Add a filter display_post_states( $states, $post ) https://developer.wordpress.org/reference/hooks/display_post_states/

In the filter function, first check that the post is a draft, if it isn't then return the states object as is. Next, add a check for get_post_idea( $post->ID ) (see #3157 ),

if it's not null, we update the draft state, which will change the label:

/* translators: %s: Idea Hub Idea Title */
$states['draft'] = sprintf( __( 'Idea Hub Draft “%s”', 'google-site-kit' ), $idea['text'] );

Make sure to use smart / directional quotation marks “” rather than unidirectional "", or directional single quotes ‘’ see https://en.wikipedia.org/wiki/Quotation_mark#Summary_table English, US

Test Coverage

Update tests/phpunit/integration/Modules/Idea_HubTest.php to create a new test which tests the following:
Idea Hub Module registered, draft post with idea, when running the filter display_post_states the text is changed.
Idea Hub Module registered, draft post not via idea hub, when running the filter display_post_states the text says Draft.
Idea Hub Module NOT registered, draft post with idea, when running the filter display_post_states the text says Draft.

Visual Regression Changes

  • N/A

QA Brief

  1. Enable the ideahub feature via tester plugin.
  2. Connect the module, since we don't have the interface for this yet, we can do it with wp-cli:
    wp option patch insert googlesitekit_active_modules 3 idea-hub
  3. Re-auth sitekit to grant the new permissions required for idea hub.
  4. Add the required settings for is_connected to work
    wp option add googlesitekit_idea-hub_settings --format=json '{"ideaLocale":"en-US"}
  5. Create a draft post.

If #3269 is merged, you can do this:

window.googlesitekit.data.dispatch( 'modules/idea-hub' ).createIdeaDraftPost({
    "name": "ideas/2285812891948871921",
    "text": "Using Site Kit to analyze your success",
    "topics": [
      {
        "mid": "/m/080ag",
        "display_name": "Analytics"
      }
    ]
  });

Otherise you need to create it manually:

 tempid=$(wp post create --post_title='A' --porcelain);  echo $tempid ; wp db query "update wp_posts set post_title='' where ID=$tempid;"

With the post id from the previous step, add your idea post meta:

wp post meta add 32 googlesitekitpersistent_idea_name ideas/68182298994557866271
wp post meta add 32 googlesitekitpersistent_idea_text 'How to make carne asada'
wp post meta add 32 googlesitekitpersistent_idea_topics --format=json '[ { "mid": "/m/07fhc", "display_name": "Cooking" } ]'

After you've created the draft post, open the all posts list /wp-admin/edit.php, you should see your draft post there:
(no title) — Idea Hub Draft “Using Site Kit to analyze your success”

Changelog entry

  • Add Idea Hub context for draft posts generated by Idea Hub.
@felixarntz felixarntz added P0 High priority Type: Enhancement Improvement of an existing feature Module: Idea Hub Google Idea Hub module related issues labels May 3, 2021
@felixarntz felixarntz self-assigned this May 3, 2021
@felixarntz felixarntz removed their assignment May 3, 2021
@fhollis fhollis added this to the Sprint 49 milestone May 5, 2021
@eugene-manuilov eugene-manuilov self-assigned this May 7, 2021
@eugene-manuilov
Copy link
Collaborator

Thanks, @ivankruchkoff. The IB mostly looks good. Could you please explicitly mention that we need to update $states['draft'] only if the post has draft status?

@ivankruchkoff
Copy link
Contributor

Thanks, @ivankruchkoff. The IB mostly looks good. Could you please explicitly mention that we need to update $states['draft'] only if the post has draft status?

Updated, although for non draft posts it wouldn't matter as their non-draft status means that they wouldn't get the draft label anyway.

@eugene-manuilov
Copy link
Collaborator

Thanks, @ivankruchkoff! IB ✔️

@eugene-manuilov eugene-manuilov removed their assignment May 10, 2021
@ivankruchkoff ivankruchkoff self-assigned this May 10, 2021
@ivankruchkoff ivankruchkoff removed their assignment May 15, 2021
@ivankruchkoff
Copy link
Contributor

@felixarntz this might still need QA:Eng due to steps 2 and 4 of qa brief.

@tofumatt tofumatt assigned tofumatt and unassigned tofumatt May 16, 2021
@wpdarren wpdarren self-assigned this May 18, 2021
@fhollis fhollis added the Rollover Issues which role over to the next sprint label May 24, 2021
@fhollis fhollis modified the milestones: Sprint 49, Sprint 50 May 24, 2021
@wpdarren
Copy link
Collaborator

wpdarren commented May 26, 2021

@ivankruchkoff when I run wp option patch insert googlesitekit_active_modules 3 idea-hub in terminal, an error message appears Error: Cannot create key "3" on data type boolean When I started the QA on this yesterday, the command worked fine. I refreshed the develop branch today.

Steps. Connected to SSH on terminal, pointed to the folder cd apps etc.
Ran the code above in terminal and error message appeared.

Can you think of any reason why this might not work now?

@ivankruchkoff
Copy link
Contributor

@ivankruchkoff when I run wp option patch insert googlesitekit_active_modules 3 idea-hub in terminal, an error message appears Error: Cannot create key "3" on data type boolean When I started the QA on this yesterday, the command worked fine. I refreshed the develop branch today.

Can you start with a fresh install, enable a few modules and then try it again?

@wpdarren
Copy link
Collaborator

@cole10up would you be able to look at this one? I have followed the instructions in the QAB. I can connect Idea Hub,, but when I try and add the settings in terminal, nothing happens. When I run the get command, the settings are not updated. Have spent quite a lot of time on this ticket, so think it needs another pair of eyes.

@wpdarren wpdarren assigned cole10up and unassigned wpdarren May 28, 2021
@cole10up
Copy link

cole10up commented Jun 6, 2021

QA ✅

@wpdarren - I was able to create the post manually using "tempid=$(wp post create --post_title='A' --porcelain); echo $tempid ; wp db query "update wp_posts set post_title='' where ID=$tempid;"

Ran the following commands:
wp post meta add 32 googlesitekitpersistent_idea_name ideas/68182298994557866271
wp post meta add 32 googlesitekitpersistent_idea_text 'How to make carne asada'
wp post meta add 32 googlesitekitpersistent_idea_topics --format=json '[ { "mid": "/m/07fhc", "display_name": "Cooking" } ]'

From here I confirmed in edit.php that a draft post was created called "(no title) — Idea Hub Draft “Using Site Kit to analyze your success”

Sending to testing approved.

@cole10up cole10up removed their assignment Jun 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Idea Hub Google Idea Hub module related issues P0 High priority Rollover Issues which role over to the next sprint Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

7 participants