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

Add an image thumbnail to wp-admin post list. #20720

Merged
merged 122 commits into from
Sep 10, 2021

Conversation

DustyReagan
Copy link
Member

@DustyReagan DustyReagan commented Aug 16, 2021

We've created a Composer package in Jetpack to add an image thumbnail to the post-list wp-admin page similar to Calypso. For the thumbnail, we use the "featured image" if one exists, else we look in the post itself for the first media-library hosted image.

Design

image

Does this pull request change what data or activity we track or use?

No

Testing instructions:

Setup Environment

  1. Checkout this branch
git checkout update/add-posts-list-featured-image
  1. Add this dependency to Jetpack plugin
cd projects/plugins/jetpack && composer require automattic/jetpack-post-list
  1. Update pnpm
pnpm install
  1. Update Jetpack dependencies
jetpack install -r && jetpack install --all
  1. Run posts-list package compiling process
jetpack build packages/post-list
  1. Run watch in case you'd like to edit the code in the client.
jetpack watch packages/post-list
  1. In a new terminal run the web server
jetpack docker up

Compiling

Production

jetpack build -p packages/post-list

Development

jetpack build packages/post-list

Development watching mode 👀

jetpack watch packages/post-list

Unit Tests

To run the package unit tests:

  1. go the post-list folder cd projects/packages/post-list
  2. and run the command composer test-php.

If you're running the PHP interpreter that shipped with your Mac you may get the error: /usr/bin/php declares an invalid value for PHP_VERSION. StackOverflow has the solution here.

Load The Post List Package

To load the post list package you need to call it from the "Must Use Plugins" directory. To do that:

  1. Create a file named 0-functions.php in the tools/docker/mu-plugins/ directory.
  2. In that file add this code: add_action( 'admin_init', array( '\Automattic\Jetpack\Post_List\Post_List', 'configure' ) );

Test Feature

  1. Go to http://localhost/wp-admin/edit.php?post-list=true
    Note that post-list=true must be set in the URL.
  2. Create a post with a featured image.
  3. Create another post without a featured image, but add an image to the post content.
  4. You should see those images as thumbnails on the post list page http://localhost/wp-admin/edit.php?post-list=true

image

@DustyReagan DustyReagan linked an issue Aug 16, 2021 that may be closed by this pull request
@DustyReagan DustyReagan self-assigned this Aug 16, 2021
@retrofox retrofox changed the base branch from update/add-wp-admin-plus-package to master August 17, 2021 08:20
@retrofox retrofox requested a review from a team August 17, 2021 08:35
@retrofox retrofox linked an issue Aug 17, 2021 that may be closed by this pull request
@retrofox
Copy link
Contributor

I think it isn't possible to change the title in the wp-admin list.

We can inject the element in the client, though.

@DustyReagan DustyReagan changed the title WIP: Add Featured Image to wp-admin post list. Add Featured Image to wp-admin post list. Aug 17, 2021
@DustyReagan DustyReagan force-pushed the update/add-posts-list-featured-image branch from 263260f to 1bee4c8 Compare August 19, 2021 17:52
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This looks good to me. I had a few comments below.

I couldn't get the build to work on my local machine, for some reason. This is the error I got:

pnpm run build

> [email protected] build /Users/jeherve/code/jetpack/projects/packages/post-list
> wp-scripts build src/index.js

TypeError: Cannot destructure property 'info' of 'TerserPlugin.getAsset(...)' as it is undefined.
    at TerserPlugin.taskGenerator (/Users/jeherve/code/jetpack/node_modules/.pnpm/[email protected][email protected]/node_modules/terser-webpack-plugin/dist/index.js:183:7)
    at taskGenerator.next (<anonymous>)

I think it would be really good to have tests for all methods in this new package, especially since it plays with post content and fetches specific parts of it.

projects/packages/post-list/.jshintrc Outdated Show resolved Hide resolved
.eslintrc Outdated Show resolved Hide resolved
.github/renovate.json Outdated Show resolved Hide resolved
projects/packages/post-list/src/style.scss Outdated Show resolved Hide resolved
projects/packages/post-list/src/hooks/use-post/index.js Outdated Show resolved Hide resolved
projects/packages/post-list/package.json Outdated Show resolved Hide resolved
projects/packages/post-list/src/class-admin.php Outdated Show resolved Hide resolved
projects/packages/post-list/src/class-admin.php Outdated Show resolved Hide resolved
projects/packages/post-list/composer.json Outdated Show resolved Hide resolved
projects/packages/post-list/composer.json Outdated Show resolved Hide resolved
@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Aug 21, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Aug 21, 2021

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.

Copy link
Contributor

@pablinos pablinos left a comment

Choose a reason for hiding this comment

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

It's looking good. I think it would it be worth us slimming this down in order to get the skeleton of the package working and merged.

I wonder whether we should disable (or perhaps just by default, with an option to turn it on via Screen Options) the post thumbnail when the theme doesn't have support for them? It's rare, but we could call get_theme_support to check. There's an argument that we should display the post's image regardless of theme support of course.

We should probably check that the post type supports featured images though via post_type_supports( $post_type, 'thumbnail' ), but that might be at the point we use the package, rather than in the library code.

projects/packages/post-list/src/class-admin.php Outdated Show resolved Hide resolved
projects/packages/post-list/src/hooks/use-post/index.js Outdated Show resolved Hide resolved
projects/packages/post-list/src/class-admin.php Outdated Show resolved Hide resolved
projects/packages/post-list/src/class-admin.php Outdated Show resolved Hide resolved
projects/packages/post-list/src/components/notice/index.js Outdated Show resolved Hide resolved
@retrofox retrofox force-pushed the update/add-posts-list-featured-image branch from 2a7440e to 93aa539 Compare August 23, 2021 19:31
@retrofox
Copy link
Contributor

This looks good to me. I had a few comments below.

I couldn't get the build to work on my local machine, for some reason. This is the error I got:

pnpm run build

> [email protected] build /Users/jeherve/code/jetpack/projects/packages/post-list
> wp-scripts build src/index.js

TypeError: Cannot destructure property 'info' of 'TerserPlugin.getAsset(...)' as it is undefined.
    at TerserPlugin.taskGenerator (/Users/jeherve/code/jetpack/node_modules/.pnpm/[email protected][email protected]/node_modules/terser-webpack-plugin/dist/index.js:183:7)
    at taskGenerator.next (<anonymous>)

I think it would be really good to have tests for all methods in this new package, especially since it plays with post content and fetches specific parts of it.

Already fixed when updating the @wordpress/scripts package dependency. Props to @pablinos

@@ -0,0 +1,21 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a some discussion about using the Config package for handling this on the other PoC PR.

I think it would be a good plan to not have the package autoload like this, so it would be worth investigating.

Copy link
Member

Choose a reason for hiding this comment

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

@kraftbj 👋 We've been trying out your suggestion to use the Config package here, but we're not seeing any examples of the packages being loaded on wpcom. Once we've followed Adding your package to the config class, what's the next step?

@retrofox retrofox force-pushed the update/add-posts-list-featured-image branch 3 times, most recently from bcf7c8f to 269008e Compare August 25, 2021 19:30
@DustyReagan DustyReagan force-pushed the update/add-posts-list-featured-image branch from 142db64 to c307802 Compare September 7, 2021 20:32
@DustyReagan DustyReagan requested a review from jeherve September 7, 2021 21:18
retrofox
retrofox previously approved these changes Sep 8, 2021
Copy link
Contributor

@retrofox retrofox left a comment

Choose a reason for hiding this comment

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

I left a couple of minor suggestions.
Tested and it works as expected. :-)

✅ Set the post thumbnail via featured-image
✅ Set the post thumbnail via the first mage into the post content

Thanks!

@DustyReagan
Copy link
Member Author

@jeherve How does it look? Are we mergeable? -- Thanks for all your help on this PR. 😅

Copy link
Contributor

@retrofox retrofox left a comment

Choose a reason for hiding this comment

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

LGTM :-)

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This looks good to me. Let's merge this! :) 🚢

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Sep 10, 2021
@retrofox
Copy link
Contributor

Thanks, folks. Let me merge it for you, @DustyReagan

@retrofox retrofox merged commit e2c19e8 into master Sep 10, 2021
@retrofox retrofox deleted the update/add-posts-list-featured-image branch September 10, 2021 12:12
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Page React-powered dashboard under the Jetpack menu [Package] Post List [Type] Feature Request
Projects
None yet
10 participants