-
Notifications
You must be signed in to change notification settings - Fork 800
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
Changes from 4 commits
0628513
a9724e1
ae7c3d0
0e3167c
a806222
9f3c520
3f27ace
0eb7571
3e475dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: fixed | ||
|
||
Fixed a deadlock with media validation and media picker |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,10 @@ import { Disabled, PanelRow } from '@wordpress/components'; | |
import { useSelect } from '@wordpress/data'; | ||
import { Fragment } from '@wordpress/element'; | ||
import { usePublicizeConfig } from '../../..'; | ||
import useAttachedMedia from '../../hooks/use-attached-media'; | ||
import useFeaturedImage from '../../hooks/use-featured-image'; | ||
import useMediaDetails from '../../hooks/use-media-details'; | ||
import useMediaRestrictions from '../../hooks/use-media-restrictions'; | ||
import useSocialMediaConnections from '../../hooks/use-social-media-connections'; | ||
import { store as socialStore } from '../../social-store'; | ||
import { ThemedConnectionsModal as ManageConnectionsModal } from '../manage-connections-modal'; | ||
|
@@ -25,8 +29,22 @@ import { SharePostForm } from './share-post-form'; | |
* @return {object} - Publicize form component. | ||
*/ | ||
export default function PublicizeForm() { | ||
const { hasConnections, hasEnabledConnections } = useSocialMediaConnections(); | ||
const { hasConnections, hasEnabledConnections, connections } = useSocialMediaConnections(); | ||
const { isPublicizeEnabled, isPublicizeDisabledBySitePlan } = usePublicizeConfig(); | ||
const { attachedMedia } = useAttachedMedia(); | ||
const featuredImageId = useFeaturedImage(); | ||
|
||
const mediaId = attachedMedia[ 0 ]?.id || featuredImageId; | ||
const { validationErrors, isConvertible } = useMediaRestrictions( | ||
connections, | ||
useMediaDetails( mediaId )[ 0 ] | ||
); | ||
|
||
const showSharePostForm = | ||
isPublicizeEnabled && | ||
( hasEnabledConnections || | ||
attachedMedia.length > 0 || | ||
( Object.keys( validationErrors ).length !== 0 && ! isConvertible ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you say we should only look for There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah we do, I think it's true that if something is not convertible, that means we have at least 1 error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. Thank you for the confirmation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only use that here too: |
||
|
||
const { useAdminUiV1, featureFlags } = useSelect( select => { | ||
const store = select( socialStore ); | ||
|
@@ -57,9 +75,7 @@ export default function PublicizeForm() { | |
|
||
{ ! isPublicizeDisabledBySitePlan && ( | ||
<Fragment> | ||
{ isPublicizeEnabled && hasEnabledConnections && ( | ||
<SharePostForm analyticsData={ { location: 'editor' } } /> | ||
) } | ||
{ showSharePostForm && <SharePostForm analyticsData={ { location: 'editor' } } /> } | ||
</Fragment> | ||
) } | ||
</Wrapper> | ||
|
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.
Why should featured image be a part of this logic?
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.
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?
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.
Fair enough. Thank you for the explanation.