Skip to content

Gutenberg: Add a Jetpack Related Posts block#26530

Merged
tyxla merged 42 commits intomasterfrom
sdk/add-jetpack-related-posts-block
Sep 20, 2018
Merged

Gutenberg: Add a Jetpack Related Posts block#26530
tyxla merged 42 commits intomasterfrom
sdk/add-jetpack-related-posts-block

Conversation

@tyxla
Copy link
Copy Markdown
Member

@tyxla tyxla commented Aug 7, 2018

Description

This PR introduces a Jetpack Related Posts block for Gutenberg, written entirely in Calypso, intended to be built with the Calypso SDK.

Preview

Grid view with block controls, no alignment specified

List view with block controls, no alignment specified

Grid view with block controls, center alignment specified

Grid view with block controls, wide alignment specified

Grid view with block controls, full-width alignment specified

Inspector controls

Testing

Short instructions (no local dev env setup necessary)

Long instructions (local dev env setup necessary)

  • Checkout this branch on your local Calypso
  • Checkout the latest Jetpack on your local machine.
  • Checkout Gutenberg: Add a Related Posts block jetpack#10132 on your Jetpack.
  • Setup Jetpack's Docker environment.
  • Add the following as a mu-plugin in the Jetpack docker env:
    • add_filter( 'jetpack_gutenberg', '__return_true', 10 );
    • add_filter( 'jetpack_gutenberg_cdn', '__return_false', 10 );
  • Make sure Jetpack is connected on your install.
  • Make sure you got the latest Gutenberg installed.
  • Run the following command in Calypso (where PATH_TO_JETPACK is the path to your Jetpack repo) to build the Jetpack preset of blocks:
npm run sdk -- gutenberg \
--editor-script=client/gutenberg/extensions/presets/jetpack/editor.js \
--output-dir=/PATH_TO_JETPACK/_inc/blocks \
--output-editor-file=jetpack-editor \
  • Write a post, insert a Related Posts block.
  • Play the block settings, verify it looks and works well both in wp-admin and in the frontend of your site.

@matticbot
Copy link
Copy Markdown
Contributor

@tyxla tyxla self-assigned this Aug 7, 2018
@tyxla tyxla force-pushed the sdk/add-jetpack-related-posts-block branch from 193d110 to d11976e Compare September 11, 2018 09:14
@tyxla tyxla changed the title SDK: Add a Jetpack Related Posts block Gutenberg: Add a Jetpack Related Posts block Sep 11, 2018
@tyxla tyxla added [Goal] Gutenberg Working towards full integration with Gutenberg [Type] New feature and removed [Project] SDK labels Sep 11, 2018
@sirreal
Copy link
Copy Markdown
Member

sirreal commented Sep 11, 2018

I see related posts!

I had to remove .js from the --output-editor-file=block.js in the testing instructions. The SDK was building block.js.js block.js.css….

@tyxla
Copy link
Copy Markdown
Member Author

tyxla commented Sep 11, 2018

Oops, test instructions haven't been updated in a while 😉 The ones in #27126 would work better these days.

@MichaelArestad
Copy link
Copy Markdown
Contributor

How can we test this? Do you want @mapk and I to test this? I'm not aware of any prior designs for this feature. Is this just largely a test/learning PR?

date: 'August 5, 2018',
context: 'In "Upgrade"',
},
];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These example texts and images are straight from the current version in Jetpack — since we're at it, we should probably look up some more fresh demo content. Won't stop merging though, just noting down.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 👍

However, I'll defer that decision to @MichaelArestad and @mapk - I'm not planning any changes, as that would affect other bits that already use this content.

Also, FWIW, if we decide to change the content, we should do in all instances - both Jetpack (the plugin) and Calypso (site settings).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it that if we plan to pull in actual site content even in editor mode (in a subsequent iteration), we'll be able to drop the demo content?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct @ockham.

import edit from './edit';
import { MAX_POSTS_TO_SHOW } from './constants';

registerBlockType( 'jetpack/related-posts', {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering this will be used elsewhere than just Jetpack, should we stick to a8c namespace?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I agree.

Done in dcef260.

We can always change it back if we reconsider for any reason (like grouping blocks under the same category/group in the block inserter).

<Toolbar controls={ layoutControls } />
</BlockControls>

<div className="related-posts__main">
Copy link
Copy Markdown
Member

@simison simison Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rely on generated className prop here? Both edit and save have className prop available and it should be wp-block-a8c-related-posts (or wp-block-jetpack-related-posts) for this block.

https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/#classname

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 👍

I think the generated className weren't there yet when I started working on this block 😉

I've updated the block to use that class and cleaned up any unnecessary instances in b9e6a6e

@tyxla
Copy link
Copy Markdown
Member Author

tyxla commented Sep 12, 2018

I'm not aware of any prior designs for this feature.

There aren't any designs as far as I know.

Is this just largely a test/learning PR?

It started as an exploration to help showcase how the SDK can be used to build a block from scratch, but eventually turned out to work pretty well, so we can actually use it for building the production block.

How can we test this? Do you want @mapk and I to test this?

Thanks, I'd love to get that tested; let me take some time to prepare the PR and a playground and I'll ping you folks.

@tyxla tyxla added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Status] Needs Design Review Add this when you'd like to get a review / feedback from the Design team on your PR and removed [Status] In Progress labels Sep 12, 2018
@tyxla tyxla requested review from a team, MichaelArestad and mapk September 12, 2018 11:11
@tyxla
Copy link
Copy Markdown
Member Author

tyxla commented Sep 12, 2018

This is now ready for review and testing ✅

@mapk
Copy link
Copy Markdown
Contributor

mapk commented Sep 12, 2018

@tyxla Can we see a recorded video of how this works posted in this thread? At least until we can get a more simplified testing environment going?

];

const displayPosts =
DEFAULT_POSTS.length > postsToShow ? DEFAULT_POSTS.slice( 0, postsToShow ) : DEFAULT_POSTS;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact! This should be equivalent to the inner case…

const displayPosts = DEFAULT_POSTS.slice( 0, postToShow );

the only difference is that we are cloning the array each time and as-written we're not cloning when the array is empty. since this is inside a render() function it won't trigger additional re-renders

unless there's a reason to leave it here we should be able to remove the conditional altogether.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 👍 Done in be96069.

Comment thread client/gutenberg/extensions/related-posts/edit.jsx
Comment thread client/gutenberg/extensions/related-posts/index.js
@tyxla tyxla force-pushed the sdk/add-jetpack-related-posts-block branch from 5cea80a to 5d766d3 Compare September 20, 2018 11:25
@tyxla tyxla merged commit 9fda0ac into master Sep 20, 2018
@tyxla tyxla deleted the sdk/add-jetpack-related-posts-block branch September 20, 2018 11:41
@matticbot matticbot removed [Status] Needs Design Review Add this when you'd like to get a review / feedback from the Design team on your PR [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Sep 20, 2018
@tyxla
Copy link
Copy Markdown
Member Author

tyxla commented Sep 26, 2018

@mapk thanks for the great feedback, I've been working today on addressing it - see my comments below; also I'd appreciate reviews and feedback on the proposed solutions.

Can we change the selector icon to match the "Latest Posts" icon? Should we?

I've suggested that in #27451. It's worth to mention that @mtias suggested that we use something unique - what can we do to make the icon similar, but still unique?

Will we iterate on the content prior to any users actually using this block, or will there be a chance they see it? If they'll see it, can we edit the content to something else for the new PR? I'd love to use some images and text that visually improve that space if possible.

Well, I'm planning to work on getting real-time content working, but it seems it'll be after the GM. Also, it's not clear whether we'll be able to ship it in the v1, considering the fact that it would require a premium plan feature (Jetpack Search). So I'd really appreciate if you have suggestions for some better images and text - I'd love to implement them.

The font style and size of the date should match that of the Image caption and Pullquote citation in the Gutenberg core blocks. It needs to decrease in importance.

Nice - I've suggested that in #27456.

You bring up good points, @tyxla. I'm okay with not having a complete 1:1 parity with the current design pattern of our Jetpack feature. I think it's more important to shift to the "everything is a block" concept and separate it out.

Okay, that's fair enough. I've opted for removing the headline bit in #27454.

5. TAGS/CATEGORIES
@MichaelArestad and I were discussing that maybe, for now, we don't include this as part of the block. We'd like to research this further. We can always add it later, but it would be much more difficult to remove it once it's included.

Sounds good, let's skip categories/tags for the v1 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Goal] Gutenberg Working towards full integration with Gutenberg Jetpack

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants