-
Notifications
You must be signed in to change notification settings - Fork 2k
Dashboard v2: show AT transfer status in Status column #104493
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
Open
fushar
wants to merge
1
commit into
trunk
Choose a base branch
from
status-at-transfer
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { fetchLatestAtomicTransfer } from '../../data/site-atomic-transfers'; | ||
|
||
export const siteLatestAtomicTransferQuery = ( siteId: number ) => ( { | ||
queryKey: [ 'site', siteId, 'atomic', 'transfers', 'latest' ], | ||
queryFn: () => fetchLatestAtomicTransfer( siteId ), | ||
retry: ( failureCount: number, error: { code?: string } ) => { | ||
if ( error.code === 'no_transfer_record' ) { | ||
return false; | ||
} | ||
return failureCount < 3; | ||
}, | ||
} ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import wpcom from 'calypso/lib/wp'; | ||
|
||
export type AtomicTransferStatus = | ||
| 'pending' | ||
| 'active' | ||
| 'provisioned' | ||
| 'completed' | ||
| 'error' | ||
| 'reverted' | ||
| 'relocating_revert' | ||
| 'relocating_switcheroo' | ||
| 'reverting' | ||
| 'renaming' | ||
| 'exporting' | ||
| 'importing' | ||
| 'cleanup'; | ||
|
||
export interface AtomicTransfer { | ||
status: AtomicTransferStatus; | ||
} | ||
|
||
export async function fetchLatestAtomicTransfer( | ||
siteId: number | ||
): Promise< AtomicTransfer | undefined > { | ||
return wpcom.req.get( { | ||
path: `/sites/${ siteId }/atomic/transfers/latest`, | ||
apiNamespace: 'wpcom/v2', | ||
} ); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -10,6 +10,7 @@ import { __, sprintf } from '@wordpress/i18n'; | |||
import { useInView } from 'react-intersection-observer'; | ||||
import { useAnalytics } from '../../app/analytics'; | ||||
import { useAuth } from '../../app/auth'; | ||||
import { siteLatestAtomicTransferQuery } from '../../app/queries/site-atomic-transfers'; | ||||
import { siteBackupLastEntryQuery } from '../../app/queries/site-backups'; | ||||
import { siteMediaStorageQuery } from '../../app/queries/site-media-storage'; | ||||
import { sitePHPVersionQuery } from '../../app/queries/site-php-version'; | ||||
|
@@ -18,8 +19,9 @@ import { siteUptimeQuery } from '../../app/queries/site-uptime'; | |||
import ComponentViewTracker from '../../components/component-view-tracker'; | ||||
import { TextBlur } from '../../components/text-blur'; | ||||
import TimeSince from '../../components/time-since'; | ||||
import { JetpackModules } from '../../data/constants'; | ||||
import { hasAtomicFeature, hasJetpackModule } from '../../utils/site-features'; | ||||
import { DotcomFeatures, JetpackModules } from '../../data/constants'; | ||||
import { isAtomicTransferInProgress } from '../../utils/site-atomic-transfers'; | ||||
import { hasAtomicFeature, hasJetpackModule, hasPlanFeature } from '../../utils/site-features'; | ||||
import { getSiteStatus, getSiteStatusLabel } from '../../utils/site-status'; | ||||
import { isSelfHostedJetpackConnected } from '../../utils/site-types'; | ||||
import { HostingFeatures } from '../features'; | ||||
|
@@ -218,6 +220,45 @@ function PlanRenewNag( { site, source }: { site: Site; source: string } ) { | |||
); | ||||
} | ||||
|
||||
interface WithHostingFeaturesProps { | ||||
site: Site; | ||||
children: () => React.ReactNode; | ||||
} | ||||
|
||||
function WithHostingFeaturesQuery( { site, children }: WithHostingFeaturesProps ) { | ||||
const { ref, inView } = useInView( { | ||||
triggerOnce: true, | ||||
fallbackInView: true, | ||||
} ); | ||||
|
||||
const { data } = useQuery( { | ||||
...siteLatestAtomicTransferQuery( site.ID ), | ||||
enabled: inView, | ||||
} ); | ||||
|
||||
const renderContent = () => { | ||||
if ( ! data ) { | ||||
return children(); | ||||
} | ||||
if ( data.status === 'error' ) { | ||||
return __( 'Error activating hosting features' ); | ||||
} | ||||
if ( isAtomicTransferInProgress( data.status ) ) { | ||||
return __( 'Activating hosting features…' ); | ||||
} | ||||
return children(); | ||||
}; | ||||
|
||||
return <span ref={ ref }>{ renderContent() }</span>; | ||||
} | ||||
|
||||
function WithHostingFeaturesStatus( { site, children }: WithHostingFeaturesProps ) { | ||||
if ( hasPlanFeature( site, DotcomFeatures.ATOMIC ) && ! site.is_wpcom_atomic ) { | ||||
return <WithHostingFeaturesQuery site={ site }>{ children }</WithHostingFeaturesQuery>; | ||||
} | ||||
return children(); | ||||
} | ||||
|
||||
export function Status( { site }: { site: Site } ) { | ||||
const status = getSiteStatus( site ); | ||||
const label = getSiteStatusLabel( site ); | ||||
|
@@ -247,11 +288,16 @@ export function Status( { site }: { site: Site } ) { | |||
); | ||||
} | ||||
|
||||
if ( site.launch_status === 'unlaunched' ) { | ||||
return <SiteLaunchNag site={ site } />; | ||||
} | ||||
|
||||
return label; | ||||
return ( | ||||
<WithHostingFeaturesStatus site={ site }> | ||||
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. v1 pattern reference:
|
||||
{ () => { | ||||
if ( site.launch_status === 'unlaunched' ) { | ||||
return <SiteLaunchNag site={ site } />; | ||||
} | ||||
return label; | ||||
} } | ||||
</WithHostingFeaturesStatus> | ||||
); | ||||
} | ||||
|
||||
export function Plan( { site }: { site: Site } ) { | ||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { AtomicTransferStatus } from '../data/types'; | ||
|
||
export function isAtomicTransferInProgress( status: AtomicTransferStatus ) { | ||
const inProgressStatuses: AtomicTransferStatus[] = [ | ||
'pending', | ||
'active', | ||
'provisioned', | ||
'relocating_switcheroo', | ||
]; | ||
return inProgressStatuses.includes( status ); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
v1 reference:
wp-calypso/client/sites-dashboard/components/sites-transfer-notice.tsx
Line 43 in 73a2bde