-
Notifications
You must be signed in to change notification settings - Fork 809
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
Gutenberg: Add Goodreads Block #33395
Conversation
} | ||
|
||
const html = ` | ||
<style> [class^=gr_custom_container_] { border: 1px solid gray; border-radius: 10px; margin: auto; padding: 0 5px 10px 5px; background-color: #FFF; color: #000; width: 300px; } [class^=gr_custom_header_] { border-bottom: 1px solid gray; width: 100%; padding: 10px 0; margin: auto; text-align: center; font-size: 120%; } [class^=gr_custom_each_container_] { width: 100%; clear: both; margin: auto; overflow: auto; padding-bottom: 4px; border-bottom: 1px solid #aaa; } [class^=gr_custom_each_container_] { width: 100%; clear: both; margin-bottom: 10px; overflow: auto; padding-bottom: 4px; border-bottom: 1px solid #aaa; } [class^=gr_custom_book_container_] { overflow: hidden; height: 60px; float: left; margin-right: 6px; width: 39px; } [class^=gr_custom_author_] { font-size: 10px; } [class^=gr_custom_tags_] { font-size: 10px; color: gray; } [class^=gr_custom_rating_] { float: right; } [class^=gr_grid_book_container] { float: left; width: 98px; height: 160px; padding: 0px 0px; overflow: hidden; } a { text-decoration: none; } a:hover { text-decoration: underline; } img { max-width: 100%; }</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There has got to be a better way of doing this...but no idea what that would be!
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 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Although it would still be nice to add the Author widgets, I can't seem to figure out how to get access to them right now, so I'm marking this as ready for review! Nevertheless, I've added some changes so that it's much simpler for authors to use this block anyway. Whereas the Goodreads widget requires people to read documentation about how to acquire their User ID in case they give us their Author ID, now you can just input your profile URL and the block will handle distinguishing between the two. |
@jeherve I’m looking at adding tests for this block and I’d appreciate some advice - what does the Is this necessary for the tests? Also, apologies if I’ve just completely missed it, but is there any documentation which you could point me to on this? Thanks!! |
Awesome, thanks @Aurorum ! |
@Aurorum The fixtures represent mock data for each block. That data is used in the
You can run |
73bb751
to
b63d06a
Compare
Thanks @jeherve - I think this block is good to go, except for tests which I don't have much experience with. I'm a little stuck on how to get the block to display when embedded. I've drawn this from the Calendly Block tests, but it's still set as embedding the profile for me: test( 'display block', async () => {
const attributes = {
...defaultAttributes,
goodreadsId: '1176283',
userInput: 'https://www.goodreads.com/user/show/1176283-matt-mullenweg',
};
render( <GoodreadsEdit { ...{ ...defaultProps, attributes } } /> );
let iframe;
await waitFor( () => ( iframe = screen.getByTitle( 'Goodreads' ) ) );
expect( iframe ).toBeInTheDocument();
} ); Other than that, I think this is ready for review now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this! I left a few remarks below:
The Grid view doesn't seem to display a grid in the editor, nor on the frontend:
![Screenshot 2023-10-10 at 17 14 26](https://private-user-images.githubusercontent.com/426388/273966794-cb06b7fa-5ade-4db8-b3af-22e839c566f0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNDczMzgsIm5iZiI6MTczOTM0NzAzOCwicGF0aCI6Ii80MjYzODgvMjczOTY2Nzk0LWNiMDZiN2ZhLTVhZGUtNGRiOC1iM2FmLTIyZTgzOWM1NjZmMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMlQwNzU3MThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jZTdjNDYzZWU3MTRjNmI3OGY3NmQ3ZTQwNjYyMGM3ZDE5NGNkOTUwMDdmMDVkNjIyYzQzN2NmNjA1NDk4YjY5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.9fTAGUGmQiS6bWAQG5gcfcPMKjCefE-zYycj7gfbf20)
Those previews here are quite big, I think we would benefit from buttons instead, to reclaim that sidebar space:
I'm a little stuck on how to get the block to display when embedded.
I see you're on the right track with those tests, apart from some formatting issues with the fixtures! Let's run those tests after the updates above, see how things go!
projects/plugins/jetpack/extensions/blocks/goodreads/goodreads.php
Outdated
Show resolved
Hide resolved
...ins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-goodreads.php
Outdated
Show resolved
Hide resolved
...ins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-goodreads.php
Outdated
Show resolved
Hide resolved
...ins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-goodreads.php
Show resolved
Hide resolved
...ins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-goodreads.php
Outdated
Show resolved
Hide resolved
0082059
to
8d5b682
Compare
Thanks for the review @jeherve! I've addressed the points you've raised.
Is the problem the fact that the images aren't aligned? I've taken the styles directly from Goodreads, and "Grid" is the terminology which they use for it, but we could tidy up the styling on our end if that's something which you think would be beneficial. Alternatively, we could rename it. I mainly see this style as being something useful for sidebars where you might want to showcase a range of books without taking up much space. In such cases, "Grid" is probably just about a fitting description.
Ah, I wanted to ask about that. I agree that the previews are far too big, but I still feel like the For example, on the Eventbrite block, it now looks like this. ![]() In #14528, I can see that it used to look like this. Was changing this an intentional design choice or the result of a bug? ![]() I have a fondness to the second design, and I think that it'd make this block look much nicer too. It'd also be clearer which image applies to which style. I don't mind changing this to buttons though, and I definitely agree it'd be preferable to what it is now. I just think that buttons would also add a layer of complexity for those trying to experiment with the two styles, and something like the old |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work so far!
I ran the different GitHub checks we have for this PR, so you now have some additional feedback about your work. I also left a few notes below.
Is the problem the fact that the images aren't aligned? I've taken the styles directly from Goodreads, and "Grid" is the terminology which they use for it, but we could tidy up the styling on our end if that's something which you think would be beneficial.
Yes, maybe we could benefit from aligning the images so it looks more like a grid?
I agree that the previews are far too big, but I still feel like the BlockStylesSelector component is appropriate here since it's also an embed. Instead, I wonder if the component is broken? I remember it used to look a lot more aesthetically pleasing.
You're right, it does look broken. I believe it got messed up during a recent Gutenberg update.
To solve this issue for now, I wonder if there would be a way to ditch our custom BlockStylesSelector
, and instead use Gutenberg's own registerBlockStyle
:
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-styles/
projects/plugins/jetpack/extensions/blocks/goodreads/block.json
Outdated
Show resolved
Hide resolved
Hey @jeherve, just looping back to this old one. If you have some time, I've heavily re-written this block. It now:
I still can't register the two options as an official style because of the fact that it needs to be treated like an attribute. But I've resolved this by adding the icons to the Toolbar, like the Related Posts block does. ![]() Overall, I'm hoping that this works and looks better - both within the code and within the Editor. :) Thanks!! |
That sounds right but it's been a long time since I worked on it! |
Tests should be fixed now |
Hey @jeherve - just looping back to this old one. I can see that the tests are passing except for the WordPress.com Tests. However, I don’t seem able to access the logs and see why they’re failing. Are there any changes needed from my end? |
@Aurorum I think we're getting there! Thanks for working on that! Everything works well for me, except for the number of items. Does this work for you? When I refresh the editor, the number resets back to 5. |
Whoops, that was just me registering the wrong type - not sure how I missed that! Should be fixed now. :) Thanks for taking another look! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Let's merge that first version!
Related diff: D138696-code |
Fixes Automattic/wp-calypso#74494
Fixes #7920
Proposed changes:
Adds a block for Goodreads so that users can update to newer themes - it's currently only available as a legacy widget. This block is similar to the existing widget in that it relies on the default Goodreads styles, but I've added a little bit more customisation which Goodreads offers that was never included in the legacy widget. This can be seen in the Settings panel, and it just controls which books display.
Goodreads also offers a Grid widget that was never used in Jetpack. I feel like Gutenberg is perfect at handling multiple styles, so I've added it with this block.
I'm marking this as a draft because @supernovia mentioned in the original issue that it'd be good to support authors as well as readers. Unfortunately, I don't have an Authors Goodreads account, so I can't yet see how to implement those widgets. I'll do a bit more digging on that, but would be very grateful for any early feedback - it's been a while since I've tried my hand at making a block!
Does this pull request change what data or activity we track or use?
No changes. Regarding the above section, I don't believe that I'm able to test my code on WordPress.com, and I'm not familiar with e2e tests for Jetpack.
Testing instructions:
Notably, you should also be able to test this with an Author URL. The Goodreads Widget directs users to documentation on how to acquire their user ID because it's different for authors; with this block, it's much simpler and only requires your profile URL. Example author profile: https://www.goodreads.com/author/show/1406384