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

Social: Fix media validation deadlock #38933

Merged
merged 9 commits into from
Aug 28, 2024

Conversation

gmjuhasz
Copy link
Contributor

@gmjuhasz gmjuhasz commented Aug 16, 2024

Fixes https://github.com/Automattic/jetpack-reach/issues/478

Proposed changes:

  • Show the post form if
    • There are enabled connections
    • There is any attached media
    • There is any media validation error - to combat the issue of not showing the form with the no media error

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

https://github.com/Automattic/jetpack-reach/issues/478

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

Testing instructions:

  • Go to the post editor and check the following scenarios:

Go to an already published post and have only an Instagram connection

  • If SIG is off you cannot turn the connection on because it's disabled because of the no media error - deadlock. With this change the media picker should be shown so you can upload media

Go to an already published post and add a media that is invalid for all connections

  • All connections should get disabled, a warning is shown and you are in a deadlock on trunk. With this change the media picker should be visible, so you can remove the image from it

Go to an already published post that has no errors and no media.

  • The form should not be shown

Copy link
Contributor

github-actions bot commented Aug 16, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the fix/social-media-validation-deadlock branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack fix/social-media-validation-deadlock
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

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.
  • ✅ 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.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!

@gmjuhasz gmjuhasz changed the title Fix/social media validation deadlock Social: Fix media validation deadlock Aug 21, 2024
@gmjuhasz gmjuhasz requested a review from a team August 21, 2024 11:17
@gmjuhasz gmjuhasz self-assigned this Aug 21, 2024
@gmjuhasz gmjuhasz marked this pull request as ready for review August 21, 2024 11:20
isPublicizeEnabled &&
( hasEnabledConnections ||
attachedMedia.length > 0 ||
( Object.keys( validationErrors ).length !== 0 && ! isConvertible ) );
Copy link
Member

@manzoorwanijk manzoorwanijk Aug 21, 2024

Choose a reason for hiding this comment

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

In what case will there be no validation errors when the media is not convertible?

I mean if the media is not convertible, won't there already be validation errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you say we should only look for ! isConvertible in that part of the logic?

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure but my concern is that if the media is not convertible, we should already show/have validation errors. If that is not the case then we may need to fix that first, otherwise, yes, we may only look for ! isConvertible in that part of the logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure but my concern is that if the media is not convertible, we should already show/have validation errors.

Yeah we do, I think it's true that if something is not convertible, that means we have at least 1 error

Copy link
Member

Choose a reason for hiding this comment

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

Cool. Thank you for the confirmation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only use that here too: MediaValidationNotices I'll update that

const { attachedMedia } = useAttachedMedia();
const featuredImageId = useFeaturedImage();

const mediaId = attachedMedia[ 0 ]?.id || featuredImageId;
Copy link
Member

Choose a reason for hiding this comment

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

Why should featured image be a part of this logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that if the featured image is invalid, you still get the deadlock in the editor on the jetpack tab, until you remove the featured image. If we use it here, they can also use the attached media to upload a working image without having to change the featured image. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. Thank you for the explanation.

const { isConvertible } = useMediaRestrictions( connections, useMediaDetails( mediaId )[ 0 ] );

const showSharePostForm =
isPublicizeEnabled && ( hasEnabledConnections || attachedMedia.length > 0 || ! isConvertible );
Copy link
Member

Choose a reason for hiding this comment

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

isConvertible is false if there is no media attached. Thus ! isConvertible becomes true.

That means, the SharePostForm is visible by default, which is not the case on trunk.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we need the full logic as before

Copy link
Member

Choose a reason for hiding this comment

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

May be we don't need to use isConvertible here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we do because otherwise we would show the modal even if the media is invalid but convertible. For example the featured image is too big, but can be converted, in that case I think we do not need it 🤔 This logic starts to get fiddly

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this logic is going to be difficult to untangle in future.

May be we can add explanatory comments to that code.

Copy link
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

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

Works good

@gmjuhasz gmjuhasz enabled auto-merge (squash) August 28, 2024 12:55
@gmjuhasz gmjuhasz disabled auto-merge August 28, 2024 12:55
@gmjuhasz gmjuhasz enabled auto-merge (squash) August 28, 2024 12:56
@gmjuhasz gmjuhasz merged commit a1da228 into trunk Aug 28, 2024
59 checks passed
@gmjuhasz gmjuhasz deleted the fix/social-media-validation-deadlock branch August 28, 2024 13:07
gogdzl pushed a commit that referenced this pull request Oct 25, 2024
* Show SharePostForm if there is attached media

* changelog

* Show form if there is any validation error

* Use only !isConvertible

* Use validationErrors

* Add a small comment to explain why we do that
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants