Skip to content

Commit

Permalink
Merge branch 'trunk' into update/react-compat-useref-requires-argument
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-karen authored Aug 9, 2024
2 parents da8be28 + d1a9ad5 commit bfba5ac
Show file tree
Hide file tree
Showing 39 changed files with 207 additions and 360 deletions.
5 changes: 5 additions & 0 deletions projects/packages/jetpack-mu-wpcom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.54.1] - 2024-08-08
### Fixed
- Load Scheduled_Updates for non-wpcom users [#38772]

## [5.54.0] - 2024-08-08
### Added
- MU WPCOM: Port enqueue_coblocks_gallery_scripts from the ETK [#38731]
Expand Down Expand Up @@ -1116,6 +1120,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Testing initial package release.

[5.54.1]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v5.54.0...v5.54.1
[5.54.0]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v5.53.1...v5.54.0
[5.53.1]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v5.53.0...v5.53.1
[5.53.0]: https://github.com/Automattic/jetpack-mu-wpcom/compare/v5.52.1...v5.53.0
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom",
"version": "5.54.0",
"version": "5.54.1",
"description": "Enhances your site with features powered by WordPress.com",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Jetpack_Mu_Wpcom main class.
*/
class Jetpack_Mu_Wpcom {
const PACKAGE_VERSION = '5.54.0';
const PACKAGE_VERSION = '5.54.1';
const PKG_DIR = __DIR__ . '/../';
const BASE_DIR = __DIR__ . '/';
const BASE_FILE = __FILE__;
Expand Down Expand Up @@ -113,6 +113,11 @@ public static function load_features() {
\Marketplace_Products_Updater::init();
\Automattic\Jetpack\Classic_Theme_Helper\Main::init();
\Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::setup();

// Gets autoloaded from the Scheduled_Updates package.
if ( class_exists( 'Automattic\Jetpack\Scheduled_Updates' ) ) {
Scheduled_Updates::init();
}
}

/**
Expand Down Expand Up @@ -145,10 +150,6 @@ public static function load_wpcom_user_features() {
// This is temporary. After we cleanup Masterbar on WPCOM we should load Masterbar for Simple sites too.
\Automattic\Jetpack\Masterbar\Main::init();
}
// Gets autoloaded from the Scheduled_Updates package.
if ( class_exists( 'Automattic\Jetpack\Scheduled_Updates' ) ) {
Scheduled_Updates::init();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function get_last_chat_id() {

$projected_response = array(
'odie_chat_id' => $response->odie_chat_id,
'odie_last_chat_id' => $response->odie_last_chat_id,
'odie_last_chat_id' => $response->odie_last_chat_id ?? null,
);

return rest_ensure_response( $projected_response );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { AdminPage, Container, Col } from '@automattic/jetpack-components';
import { useConnection } from '@automattic/jetpack-connection';
import { ActivationScreen } from '@automattic/jetpack-licensing';
import React, { useCallback, useState, useMemo } from 'react';
/*
Expand All @@ -12,6 +11,7 @@ import { QUERY_LICENSES_KEY } from '../../data/constants';
import useJetpackApiQuery from '../../data/use-jetpack-api-query';
import { getMyJetpackWindowInitialState } from '../../data/utils/get-my-jetpack-window-state';
import useAnalytics from '../../hooks/use-analytics';
import useMyJetpackConnection from '../../hooks/use-my-jetpack-connection';
import GoBackLink from '../go-back-link';

/**
Expand All @@ -25,7 +25,7 @@ export default function AddLicenseScreen() {
name: QUERY_LICENSES_KEY,
queryFn: async api => ( await api.getUserLicenses() )?.items,
} );
const { userConnectionData } = useConnection();
const { userConnectionData } = useMyJetpackConnection();
const [ hasActivatedLicense, setHasActivatedLicense ] = useState( false );

// They might not have a display name set in wpcom, so fall back to wpcom login or local username.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { Text } from '@automattic/jetpack-components';
import { useConnection } from '@automattic/jetpack-connection';
import { __ } from '@wordpress/i18n';
import { useCallback, useEffect } from 'react';
/**
Expand All @@ -14,6 +13,7 @@ import useActivate from '../../data/products/use-activate';
import useInstallStandalonePlugin from '../../data/products/use-install-standalone-plugin';
import useProduct from '../../data/products/use-product';
import useAnalytics from '../../hooks/use-analytics';
import useMyJetpackConnection from '../../hooks/use-my-jetpack-connection';
import useMyJetpackNavigate from '../../hooks/use-my-jetpack-navigate';
import ProductCard from '../product-card';
import type { AdditionalAction, SecondaryAction } from '../product-card/types';
Expand All @@ -22,10 +22,10 @@ import type { FC, ReactNode } from 'react';
interface ConnectedProductCardProps {
admin: boolean;
recommendation: boolean;
slug: string;
slug: JetpackModule;
children: ReactNode;
isDataLoading?: boolean;
Description?: React.JSX.Element | ( () => null );
Description?: FC;
additionalActions?: AdditionalAction[];
secondaryAction?: SecondaryAction;
upgradeInInterstitial?: boolean;
Expand All @@ -48,7 +48,7 @@ const ConnectedProductCard: FC< ConnectedProductCardProps > = ( {
onMouseEnter,
onMouseLeave,
} ) => {
const { isRegistered, isUserConnected } = useConnection();
const { isRegistered, isUserConnected } = useMyJetpackConnection();
const { recordEvent } = useAnalytics();

const { install: installStandalonePlugin, isPending: isInstalling } =
Expand All @@ -74,7 +74,7 @@ const ConnectedProductCard: FC< ConnectedProductCardProps > = ( {
return;
}

activate();
activate( {} );
}, [
activate,
isRegistered,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Button, getRedirectUrl, H3, Text } from '@automattic/jetpack-components';
import {
ManageConnectionDialog,
useConnection,
CONNECTION_STORE_ID,
} from '@automattic/jetpack-connection';
import { ManageConnectionDialog, CONNECTION_STORE_ID } from '@automattic/jetpack-connection';
import { useDispatch } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import { Icon, info, check, lockOutline } from '@wordpress/icons';
Expand All @@ -13,6 +9,7 @@ import { useAllProducts } from '../../data/products/use-product';
import { getMyJetpackWindowInitialState } from '../../data/utils/get-my-jetpack-window-state';
import getProductSlugsThatRequireUserConnection from '../../data/utils/get-product-slugs-that-require-user-connection';
import useAnalytics from '../../hooks/use-analytics';
import useMyJetpackConnection from '../../hooks/use-my-jetpack-connection';
import cloud from './cloud.svg';
import emptyAvatar from './empty-avatar.svg';
import jetpackGray from './jetpack-gray.svg';
Expand Down Expand Up @@ -173,13 +170,8 @@ const ConnectionStatusCard: ConnectionStatusCardType = ( {
context,
onConnectUser = null,
} ) => {
const { isRegistered, isUserConnected, userConnectionData } = useConnection( {
apiRoot,
apiNonce,
const { isRegistered, isUserConnected, userConnectionData } = useMyJetpackConnection( {
redirectUri,
skipUserConnection: false,
autoTrigger: false,
from: 'my-jetpack',
} );

const { recordEvent } = useAnalytics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import Card from '../card';
import ActionButton from './action-button';
import PriceComponent from './pricing-component';
import RecommendationActions from './recommendation-actions';
import SecondaryButton, { type SecondaryButtonProps } from './secondary-button';
import SecondaryButton from './secondary-button';
import Status from './status';
import styles from './style.module.scss';
import type { AdditionalAction, SecondaryAction } from './types';
import type { InstallCallback } from '../../data/products/use-install-standalone-plugin';
import type { FC, MouseEventHandler, ReactNode } from 'react';

export type ProductCardProps = {
Expand All @@ -25,13 +27,13 @@ export type ProductCardProps = {
isManageDisabled?: boolean;
onActivate?: () => void;
slug: JetpackModule;
additionalActions?: SecondaryButtonProps[];
additionalActions?: AdditionalAction[];
upgradeInInterstitial?: boolean;
primaryActionOverride?: Record< string, { href?: string; label?: string } >;
secondaryAction?: Record< string, SecondaryButtonProps & { positionFirst?: boolean } >;
onInstallStandalone?: () => void;
primaryActionOverride?: AdditionalAction;
secondaryAction?: SecondaryAction;
onInstallStandalone?: InstallCallback;
onActivateStandalone?: () => void;
status: keyof typeof PRODUCT_STATUSES;
status: ProductStatus;
onMouseEnter?: MouseEventHandler< HTMLButtonElement >;
onMouseLeave?: MouseEventHandler< HTMLButtonElement >;
};
Expand Down Expand Up @@ -135,7 +137,7 @@ const ProductCard: FC< ProductCardProps > = props => {
recordEvent( 'jetpack_myjetpack_product_card_install_standalone_plugin_click', {
product: slug,
} );
onInstallStandalone();
onInstallStandalone( {} );
}, [ slug, onInstallStandalone, recordEvent ] );

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import styles from './style.module.scss';
import type { FC } from 'react';

interface StatusProps {
status: keyof typeof PRODUCT_STATUSES;
status: ProductStatus;
isFetching: boolean;
isInstallingStandalone: boolean;
isOwned: boolean;
}

type StatusStateFunction = ( status: keyof typeof PRODUCT_STATUSES, isOwned: boolean ) => string;
type StatusStateFunction = ( status: ProductStatus, isOwned: boolean ) => string;

const getStatusLabel: StatusStateFunction = ( status, isOwned ) => {
switch ( status ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Text,
TermsOfService,
} from '@automattic/jetpack-components';
import { useConnection } from '@automattic/jetpack-connection';
import { createInterpolateElement } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import clsx from 'clsx';
Expand All @@ -23,6 +22,7 @@ import useProduct from '../../data/products/use-product';
import { getMyJetpackWindowInitialState } from '../../data/utils/get-my-jetpack-window-state';
import useAnalytics from '../../hooks/use-analytics';
import { useGoBack } from '../../hooks/use-go-back';
import useMyJetpackConnection from '../../hooks/use-my-jetpack-connection';
import useMyJetpackNavigate from '../../hooks/use-my-jetpack-navigate';
import GoBackLink from '../go-back-link';
import ProductDetailCard from '../product-detail-card';
Expand Down Expand Up @@ -80,9 +80,9 @@ export default function ProductInterstitial( {
const { recordEvent } = useAnalytics();
const { onClickGoBack } = useGoBack( { slug } );
const { myJetpackCheckoutUri = '' } = getMyJetpackWindowInitialState();
const { siteIsRegistering, handleRegisterSite } = useConnection( {
const { siteIsRegistering, handleRegisterSite } = useMyJetpackConnection( {
skipUserConnection: true,
redirectUri: detail.postActivationUrl ? detail.postActivationUrl : null,
redirectUri: detail.postActivationUrl ?? null,
} );
const showBundledTOS = ! hideTOS && !! bundle;
const productName = detail?.title;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* External dependencies
*/
import { useConnection } from '@automattic/jetpack-connection';
import debugFactory from 'debug';
import { useCallback } from 'react';
/**
* Internal dependencies
*/
import ProductInterstitial from '../';
import useProduct from '../../../data/products/use-product';
import useMyJetpackConnection from '../../../hooks/use-my-jetpack-connection';
import jetpackAiImage from '../jetpack-ai.png';
import styles from './style.module.scss';

Expand All @@ -23,7 +23,7 @@ export default function JetpackAiInterstitial() {
const { detail } = useProduct( slug );
debug( detail );

const { userConnectionData } = useConnection();
const { userConnectionData } = useMyJetpackConnection();
const { currentUser } = userConnectionData;
const { wpcomUser } = currentUser;
const userId = currentUser?.id || 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
getRedirectUrl,
Notice,
} from '@automattic/jetpack-components';
import { useConnection } from '@automattic/jetpack-connection';
import { Button, Card, ExternalLink } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { Icon, plus, help, check } from '@wordpress/icons';
Expand All @@ -23,6 +22,7 @@ import { useCallback, useState, useEffect } from 'react';
import useProduct from '../../../data/products/use-product';
import useAnalytics from '../../../hooks/use-analytics';
import { useGoBack } from '../../../hooks/use-go-back';
import useMyJetpackConnection from '../../../hooks/use-my-jetpack-connection';
import useMyJetpackNavigate from '../../../hooks/use-my-jetpack-navigate';
import GoBackLink from '../../go-back-link';
import styles from './style.module.scss';
Expand All @@ -38,7 +38,7 @@ export default function () {
const { detail } = useProduct( 'jetpack-ai' );
const { description, aiAssistantFeature } = detail;
const [ showNotice, setShowNotice ] = useState( false );
const { isRegistered } = useConnection();
const { isRegistered } = useMyJetpackConnection();

const videoTitleContentGeneration = __(
'Generate and edit content faster with Jetpack AI Assistant',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useConnection } from '@automattic/jetpack-connection';
import { GoldenTokenModal } from '@automattic/jetpack-licensing';
import { __ } from '@wordpress/i18n';
import React from 'react';
import { QUERY_PURCHASES_KEY, REST_API_SITE_PURCHASES_ENDPOINT } from '../../data/constants';
import useSimpleQuery from '../../data/use-simple-query';
import useMyJetpackConnection from '../../hooks/use-my-jetpack-connection';
import { includesLifetimePurchase } from '../../utils/is-lifetime-purchase';

/**
Expand All @@ -12,7 +11,7 @@ import { includesLifetimePurchase } from '../../utils/is-lifetime-purchase';
* @returns {object} The RedeemTokenScreen component.
*/
export default function RedeemTokenScreen() {
const { userConnectionData } = useConnection();
const { userConnectionData } = useMyJetpackConnection();
// They might not have a display name set in wpcom, so fall back to wpcom login or local username.
const displayName =
userConnectionData?.currentUser?.wpcomUser?.display_name ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Container, Col, Button, Text } from '@automattic/jetpack-components';
import { useConnection } from '@automattic/jetpack-connection';
import { __ } from '@wordpress/i18n';
import { close } from '@wordpress/icons';
import { useEffect, useCallback, useState } from 'react';
import { MyJetpackRoutes } from '../../constants';
import useWelcomeBanner from '../../data/welcome-banner/use-welcome-banner';
import useAnalytics from '../../hooks/use-analytics';
import useMyJetpackConnection from '../../hooks/use-my-jetpack-connection';
import useMyJetpackNavigate from '../../hooks/use-my-jetpack-navigate';
import { CardWrapper } from '../card';
import styles from './style.module.scss';
Expand All @@ -18,7 +18,7 @@ import styles from './style.module.scss';
const WelcomeBanner = () => {
const { recordEvent } = useAnalytics();
const { isWelcomeBannerVisible, dismissWelcomeBanner } = useWelcomeBanner();
const { isRegistered, isUserConnected } = useConnection();
const { isRegistered, isUserConnected } = useMyJetpackConnection();
const navigateToConnectionPage = useMyJetpackNavigate( MyJetpackRoutes.Connection );
const [ bannerVisible, setBannerVisible ] = useState( isWelcomeBannerVisible );
const shouldDisplayConnectionButton = ! isRegistered || ! isUserConnected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@ import { REST_API_SITE_PRODUCTS_ENDPOINT } from '../constants';
import { QUERY_INSTALL_PRODUCT_KEY } from '../constants';
import useSimpleMutation from '../use-simple-mutation';
import useProduct from './use-product';
import type { APIFetchOptionsWithQueryParams } from '../use-simple-mutation';
import type { UseMutateFunction } from '@tanstack/react-query';

const useInstallStandalonePlugin = ( productId: string ) => {
export type InstallCallback = UseMutateFunction<
void,
Error,
APIFetchOptionsWithQueryParams,
unknown
>;

type UseInstallStandalonePluginFunction = ( productId: string ) => {
install: InstallCallback;
isPending: boolean;
};

const useInstallStandalonePlugin: UseInstallStandalonePluginFunction = productId => {
const { detail, refetch } = useProduct( productId );

const { mutate: install, isPending } = useSimpleMutation( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useFetchingErrorNotice } from './notices/use-fetching-error-notice';
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import type { APIFetchOptions } from '@wordpress/api-fetch';

type APIFetchOptionsWithQueryParams = APIFetchOptions & {
export type APIFetchOptionsWithQueryParams = APIFetchOptions & {
queryParams?: Record< string, string | Array< string > | object >;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Update uses of useConnection to useMyJetpackConnection and improve typing in a few places
Loading

0 comments on commit bfba5ac

Please sign in to comment.