Skip to content

Commit

Permalink
Handle A4A Pressable sites which have jetpack deactivated, when it is…
Browse files Browse the repository at this point in the history
… listed on dotcom.
  • Loading branch information
andregardi committed Oct 17, 2024
1 parent eabab75 commit d65808e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion client/controller/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ export function redirectIfJetpackNonAtomic( context, next ) {
const site = getSelectedSite( state );
const isAtomicSite = !! site?.is_wpcom_atomic || !! site?.is_wpcom_staging_site;
const isJetpackNonAtomic = ! isAtomicSite && !! site?.jetpack;
const isDisconnectedJetpackAndNotAtomic =
! site?.is_wpcom_atomic && site?.jetpack_connection && ! site?.jetpack;

if ( isJetpackNonAtomic ) {
if ( isJetpackNonAtomic || isDisconnectedJetpackAndNotAtomic ) {
return redirectToDashboard( context );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
isNotAtomicJetpack,
isMigrationInProgress,
isStagingSite,
isDisconnectedJetpackAndNotAtomic,
} from 'calypso/sites-dashboard/utils';
import { useSelector } from 'calypso/state';
import { canCurrentUser } from 'calypso/state/selectors/can-current-user';
Expand Down Expand Up @@ -72,7 +73,12 @@ const SiteField = ( { site, openSitePreviewPane }: Props ) => {
const isAdmin = useSelector( ( state ) => canCurrentUser( state, site.ID, 'manage_options' ) );

const onSiteClick = ( event: React.MouseEvent ) => {
if ( isAdmin && ! isP2Site && ! isNotAtomicJetpack( site ) ) {
if (
isAdmin &&
! isP2Site &&
! isNotAtomicJetpack( site ) &&
! isDisconnectedJetpackAndNotAtomic( site )
) {
openSitePreviewPane && openSitePreviewPane( site );
} else {
navigate( adminUrl );
Expand Down
26 changes: 26 additions & 0 deletions client/sites-dashboard/components/sites-ellipsis-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
isNotAtomicJetpack,
isSimpleSite,
isP2Site,
isDisconnectedJetpackAndNotAtomic,
} from '../utils';
import SitePreviewModal from './site-preview-modal';
import type { SiteExcerptData } from '@automattic/sites';
Expand Down Expand Up @@ -273,6 +274,22 @@ const WpAdminItem = ( { site, recordTracks }: SitesMenuItemProps ) => {
);
};

const MigrateToWordPress = ( { recordTracks }: SitesMenuItemProps ) => {
const { __ } = useI18n();

return (
<MenuItemLink
href="https://wordpress.com/move/"
onClick={ () => recordTracks( 'calypso_sites_dashboard_site_action_migrate_to_wpcom_click' ) }
target="_blank"
icon={ external }
iconPosition="right"
>
{ __( 'Migrate to WordPress.com' ) }
</MenuItemLink>
);
};

const SiteMenuGroup = styled( MenuGroup )( {
'> div[role="group"]': {
display: 'flex',
Expand Down Expand Up @@ -519,6 +536,7 @@ export const SitesEllipsisMenu = ( {
};

const isSiteJetpackNotAtomic = isNotAtomicJetpack( site );
const isSiteDisconnectedJetpackAndNotAtomic = isDisconnectedJetpackAndNotAtomic( site );
const hasHostingFeatures = ! isSiteJetpackNotAtomic && ! isP2Site( site );
const { shouldShowSiteCopyItem, startSiteCopy } = useSiteCopy( site );
const hasCustomDomain = isCustomDomain( site.slug );
Expand All @@ -537,6 +555,14 @@ export const SitesEllipsisMenu = ( {
</SiteMenuGroup>
);
}
if ( isSiteDisconnectedJetpackAndNotAtomic ) {
return (
<SiteMenuGroup>
<WpAdminItem { ...props } />
<MigrateToWordPress { ...props } />
</SiteMenuGroup>
);
}

return (
<SiteMenuGroup>
Expand Down
5 changes: 5 additions & 0 deletions client/sites-dashboard/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export const isNotAtomicJetpack = ( site: SiteExcerptNetworkData ) => {
return site.jetpack && ! site?.is_wpcom_atomic;
};

// Sites connected through A4A plugin are listed on wordpress.com/sites even when Jetpack is deactivated.
export const isDisconnectedJetpackAndNotAtomic = ( site: SiteExcerptNetworkData ) => {
return ! site?.is_wpcom_atomic && site?.jetpack_connection && ! site?.jetpack;
};

export const isSimpleSite = ( site: SiteExcerptNetworkData ) => {
return ! site?.jetpack && ! site?.is_wpcom_atomic;
};
Expand Down
1 change: 1 addition & 0 deletions packages/data-stores/src/site/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export interface SiteDetails {
is_a4a_client?: boolean;
is_a4a_dev_site?: boolean;
jetpack: boolean;
jetpack_connection?: boolean;
lang?: string;
launch_status: string;
locale: string;
Expand Down
1 change: 1 addition & 0 deletions packages/sites/src/site-excerpt-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const SITE_EXCERPT_REQUEST_FIELDS = [
'p2_thumbnail_elements',
'plan',
'jetpack',
'jetpack_connection',
'is_wpcom_atomic',
'is_wpcom_staging_site',
'user_interactions',
Expand Down

0 comments on commit d65808e

Please sign in to comment.