-
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
Add value to inactive state of VideoPress #38748
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
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. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. |
faed468
to
da0bb73
Compare
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.
Looks good 😄 I've tried to give feedback / sometimes opinions through the code, you can apply when you feel it's appropriate!
@@ -85,7 +87,7 @@ const ConnectedProductCard: FC< ConnectedProductCardProps > = ( { | |||
|
|||
const DefaultDescription = () => { | |||
// Replace the last space with a non-breaking space to prevent widows | |||
const cardDescription = defaultDescription.replace( /\s(?=[^\s]*$)/, '\u00A0' ); | |||
const cardDescription = preventWidows( defaultDescription ); |
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.
Reducing technical debt 💪 great!
@@ -0,0 +1,6 @@ | |||
import type { FC } from 'react'; | |||
|
|||
export type ProductCardType = FC< { |
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.
Idea for name: ProductCardComponent
/ProductCardFC
? I like the unification!
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.
ProductCardComponent
sounds better to me, thanks!
import './style.scss'; | ||
|
||
const VideopressCard: ProductCardType = ( { admin } ) => { | ||
const slug = 'videopress'; |
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.
We could consider putting static variables outside of component scope?
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 don't think it matters too much but we definitely could do that 🤔 And it'd be easy to do it now before we get too far into the product card projects
slug={ slug } | ||
showMenu | ||
admin={ admin } | ||
Description={ descriptionText ? Description : null } |
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.
Maybe Description
variable could be already null
if descriptionText
is not provided?
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 tried this but Description is a function so it does not return null until after it is passed to the function. I think we need to do it inline here 🤔
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.
Yeah, my bad! I thought we can do something like this useCallback( descriptionText ? () => <Description /> : null, [ descriptionText ] );
But I see we cannot.
p.description { | ||
color: var( --jp-gray-70 ); | ||
font-size: var( --font-body-small ); | ||
margin: 0 0 1rem 0; |
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.
margin: 0 0 1rem 0; | |
margin: 0 0 1rem; |
); | ||
} | ||
|
||
return <></>; |
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 not null?
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.
It's just a habit to return some sort of component, shouldn't make any difference but I'll update it to null 😄
const VideoPressValueSection: FC< VideoPressValueSectionProps > = ( { isPluginActive, data } ) => { | ||
if ( ! isPluginActive && data.videoCount ) { | ||
return ( | ||
<div className={ 'videopress-card__video-count' }> |
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.
<div className={ 'videopress-card__video-count' }> | |
<div className="videopress-card__video-count"> |
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 catch 😆
if ( ! isPluginActive && data.videoCount ) { | ||
return ( | ||
<div className={ 'videopress-card__video-count' }> | ||
<span>{ data.videoCount }</span> |
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.
Do we need <span>
tag here?
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.
Hmmm I prefer it rather than just having text straight in the <div>
element 🤔 Does that logic sound decent to you?
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 cannot we have <span className="videopress-card__video-count">
?
The logic sounds good to me, thanks for explaining!
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.
That could work style-wise 🤔
I think I just like container enclosed items such as this. But I think I agree with you that it is not necessary in this case
} | ||
|
||
/** | ||
* This will collect a count of all the items that could be backed up | ||
* This is used to show what backup could be doing if it is not enabled | ||
* | ||
* @return array | ||
* @return WP_Error|\WP_REST_Response |
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.
Usually, these kind of changes to php docs "irritate" phan 😅 maybe the static check will pass if you revert it / change to WP_Error|array
?
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.
Hmm this was throwing a warning since array
is not what is returned 🤔 But it's been this way for a while and if it's going to cause some phan shenanigans then maybe I'll just revert that
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.
It seems like that didn't fix the phan errors 😓 Maybe I'll just move it back to array and see if that helps
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 reverted it back to array and I'm still getting the PHAN errors 😢
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 saw your conversation in jetpack devs channel, glad you got it fixed!
@@ -277,6 +278,10 @@ public static function enqueue_scripts() { | |||
array( 'blocked_logins' => (int) get_site_option( 'jetpack_protect_blocked_attempts', 0 ) ) | |||
), | |||
), | |||
'videopress' => array( | |||
'featuredStats' => self::get_videopress_stats(), | |||
'videoCount' => array_sum( (array) wp_count_attachments( 'video' ) ), |
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.
we could include that code in self::get_videopress_stats()
function?
I think it's a nice practice not to perform any transformations in the array definition itself.
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.
That's a good note, I'll get that moved
bb386f5
to
5bc5af6
Compare
a79438a
to
ee0ce3e
Compare
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 the changes here! One more portion of minor feedback.
isDataLoading?: boolean; | ||
Description?: FC; | ||
additionalActions?: AdditionalAction[]; | ||
secondaryAction?: SecondaryAction; | ||
upgradeInInterstitial?: boolean; | ||
primaryActionOverride?: AdditionalAction; | ||
primaryActionOverride?: { [ key: string ]: AdditionalAction }; |
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.
primaryActionOverride?: { [ key: string ]: AdditionalAction }; | |
primaryActionOverride?: Record< strong, AdditionalAction > |
// We don't have a card for Security or Extras, and scan is displayed as protect. | ||
Exclude< JetpackModule, 'extras' | 'scan' | 'security' >, | ||
Exclude< JetpackModule, 'extras' | 'scan' | 'security' | 'ai' >, |
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.
Let's update the comment above as well. Currently it's a bit confusing because in a way "ai" card is displayed (I'm aware it's about reducing redundancy of "jetpack-ai" and "ai" - but I might forget it in ~3 months 😅)
); | ||
}; | ||
const ProtectCard: ProductCardComponent = props => ( | ||
<ProductCard { ...props } slug={ PRODUCT_SLUGS.PROTECT } upgradeInInterstitial={ true }> |
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.
<ProductCard { ...props } slug={ PRODUCT_SLUGS.PROTECT } upgradeInInterstitial={ true }> | |
<ProductCard { ...props } slug={ PRODUCT_SLUGS.PROTECT } upgradeInInterstitial> |
slug={ slug } | ||
showMenu | ||
admin={ admin } | ||
Description={ descriptionText ? Description : null } |
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.
Yeah, my bad! I thought we can do something like this useCallback( descriptionText ? () => <Description /> : null, [ descriptionText ] );
But I see we cannot.
if ( ! isPluginActive && data.videoCount ) { | ||
return ( | ||
<div className={ 'videopress-card__video-count' }> | ||
<span>{ data.videoCount }</span> |
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 cannot we have <span className="videopress-card__video-count">
?
The logic sounds good to me, thanks for explaining!
PROTECT: 'protect', | ||
VIDEOPRESS: 'videopress', | ||
STATS: 'stats', | ||
} satisfies Record< string, JetpackModule >; |
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.
Learned new Typescript syntax today, thanks 😁
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 also learned that yesterday 😅 It seems like the best way to enforce the value of the object, but infer the types of the key. That way when you're using this in a typescript file, you will be limited to certain keys and still be able to see the value of the key 😄
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.
The other implementations I tried either had the key as a generic "string" type which is problematic as you could use any key you wanted without a typescript error, or the key would be defined but the value would be a generic "string" type and I wanted it to be linked to the JetpackModules type
} | ||
|
||
/** | ||
* This will collect a count of all the items that could be backed up | ||
* This is used to show what backup could be doing if it is not enabled | ||
* | ||
* @return array | ||
* @return WP_Error|\WP_REST_Response |
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 saw your conversation in jetpack devs channel, glad you got it fixed!
).part; | ||
}; | ||
|
||
export default preventWidows; |
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 extending logic of that function! What do you think about adding a reference to the source in the comment in this file?
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.
That's a good note, I'll add that
Proposed changes:
Other information:
Jetpack product discussion
P2: p1HpG7-rb7-p2
Does this pull request change what data or activity we track or use?
No
Testing instructions:
myJetpackInitialState.videopress
and make sure the featuredStats are being loaded. They're probably all 0 since your site is new, but it's enough for now that the data is loading