-
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 5 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,16 @@ 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 { isConvertible } = useMediaRestrictions( connections, useMediaDetails( mediaId )[ 0 ] ); | ||
|
||
const showSharePostForm = | ||
isPublicizeEnabled && ( hasEnabledConnections || attachedMedia.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. 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 we need the full logic as before 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. May be we don't need to use 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 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 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, this logic is going to be difficult to untangle in future. May be we can add explanatory comments to that code. |
||
|
||
const { useAdminUiV1, featureFlags } = useSelect( select => { | ||
const store = select( socialStore ); | ||
|
@@ -57,9 +69,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.