-
Notifications
You must be signed in to change notification settings - Fork 55
Refactor sync-support.ts #2359
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
Refactor sync-support.ts #2359
Changes from all commits
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 |
|---|---|---|
|
|
@@ -7,20 +7,23 @@ export function isPressableSite( site: SitesEndpointSite ): boolean { | |
| return site.hosting_provider_guess === 'pressable'; | ||
| } | ||
|
|
||
| export function isAtomicSite( site: SitesEndpointSite ): boolean { | ||
| function isAtomicSite( site: SitesEndpointSite ): boolean { | ||
| return site.is_wpcom_atomic; | ||
| } | ||
|
|
||
| export function hasSupportedPlan( site: SitesEndpointSite ): boolean { | ||
| function hasSupportedPlan( site: SitesEndpointSite ): boolean { | ||
| return site.plan?.features.active.includes( STUDIO_SYNC_FEATURE_NAME ) ?? false; | ||
| } | ||
|
|
||
| export function isJetpackSite( site: SitesEndpointSite ): boolean { | ||
| return !! site.jetpack && ! isAtomicSite( site ) && ! isPressableSite( site ); | ||
| // Sites hosted outside wp.com and Pressable (e.g. jurassic.ninja). | ||
|
Contributor
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. While reviewing the code I wanted to suggest moving
Sounds good to me. 👍🏼 With that I think we may want to update the comment above: As now it looks as if |
||
| function isUnsupported( site: SitesEndpointSite ): boolean { | ||
| return !! site.jetpack && ! isAtomicSite( site ); | ||
| } | ||
|
|
||
| export function needsTransfer( site: SitesEndpointSite ): boolean { | ||
| return ! isJetpackSite( site ) && ! isPressableSite( site ) && ! isAtomicSite( site ); | ||
|
Contributor
Author
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. If we read this condition, it says:
It's dificult to undersathnd when it's actually true. I have read the history of comits and simplified to just
Contributor
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 this was a workaround to check for a Simple site (a site that is not Jetpack, not Atomic and not Pressable). It was as long time again since I looked at the old logic, but I believe there was some edge case that resulted in this more complex check.
Contributor
Author
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. The main point here, that the condition is - |
||
| // needsTransfer means that the site was reverted to "simple" via "bulk-delete-test-sites" tool. | ||
| // Activating e.g. "VaultPress Backup" or "Hosting features" returns "is_wpcom_atomic === true && jetpack === true". | ||
ivan-ottinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| function needsTransfer( site: SitesEndpointSite ): boolean { | ||
| return ! site.jetpack && ! isAtomicSite( site ); | ||
| } | ||
|
|
||
| export function getSyncSupport( site: SitesEndpointSite, connectedSiteIds: number[] ): SyncSupport { | ||
|
|
@@ -30,17 +33,18 @@ export function getSyncSupport( site: SitesEndpointSite, connectedSiteIds: numbe | |
| if ( ! site.capabilities?.manage_options ) { | ||
| return 'missing-permissions'; | ||
| } | ||
| if ( isJetpackSite( site ) ) { | ||
|
Contributor
Author
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. Why jetpack site is unsupported?
Contributor
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. Similar as in my previous comment:
|
||
| if ( isUnsupported( site ) && ! isPressableSite( site ) ) { | ||
| return 'unsupported'; | ||
| } | ||
| if ( ! hasSupportedPlan( site ) && ! isPressableSite( site ) ) { | ||
|
Contributor
Author
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 this condition we keep |
||
| return 'needs-upgrade'; | ||
| } | ||
| if ( needsTransfer( site ) ) { | ||
| if ( needsTransfer( site ) && ! isPressableSite( site ) ) { | ||
| return 'needs-transfer'; | ||
| } | ||
| if ( connectedSiteIds.some( ( id ) => id === site.ID ) ) { | ||
| return 'already-connected'; | ||
| } | ||
|
|
||
| return 'syncable'; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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 detection of jetpack includes ! isAtomic && ! isPressable? Theoretically
!! site.jetpackshould be enough.I took a look at history and now the function directly says that jetpack site, which is not atomic is unsupported, and the example is jurasic.ninja
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.
As far as I remember, we used this in the past to filter out self-hosted sites that are not hosted by us (via WPCOM and Pressable).
In that logic, "Jetpack site" referred to "self-hosted WordPress site".
Uh oh!
There was an error while loading. Please reload this page.
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 main point here - below we have a condition that Jetpack sites are unsupported:
But it's not true, since all supported sites must have Jetpack. I worked around this code, needed cases to reproduce it, and got stuck.
Then it should be either
isUnsupportedorisSelfHosted, but notisJetpackSite.