diff --git a/projects/js-packages/publicize-components/changelog/update-social-initial-state-migrate-urls b/projects/js-packages/publicize-components/changelog/update-social-initial-state-migrate-urls
deleted file mode 100644
index 9095474b9fba3..0000000000000
--- a/projects/js-packages/publicize-components/changelog/update-social-initial-state-migrate-urls
+++ /dev/null
@@ -1,4 +0,0 @@
-Significance: patch
-Type: changed
-
-Migrated social URLs to use the new script data (initial state)
diff --git a/projects/js-packages/publicize-components/src/components/form/broken-connections-notice.tsx b/projects/js-packages/publicize-components/src/components/form/broken-connections-notice.tsx
index fb06f35edbe90..f4c9b0c750127 100644
--- a/projects/js-packages/publicize-components/src/components/form/broken-connections-notice.tsx
+++ b/projects/js-packages/publicize-components/src/components/form/broken-connections-notice.tsx
@@ -25,7 +25,7 @@ export const BrokenConnectionsNotice: React.FC = () => {
);
} );
- const { connectionsPageUrl } = usePublicizeConfig();
+ const { connectionsAdminUrl } = usePublicizeConfig();
const useAdminUiV1 = useSelect( select => select( store ).useAdminUiV1(), [] );
const { openConnectionsModal } = useDispatch( store );
@@ -37,7 +37,7 @@ export const BrokenConnectionsNotice: React.FC = () => {
className={ styles[ 'broken-connection-btn' ] }
/>
) : (
-
+
);
const getServiceLabel = useServiceLabel();
diff --git a/projects/js-packages/publicize-components/src/components/form/connection-notice.tsx b/projects/js-packages/publicize-components/src/components/form/connection-notice.tsx
index 3d91d085372bb..f4bedf6763ccb 100644
--- a/projects/js-packages/publicize-components/src/components/form/connection-notice.tsx
+++ b/projects/js-packages/publicize-components/src/components/form/connection-notice.tsx
@@ -1,4 +1,3 @@
-import { getMyJetpackUrl } from '@automattic/jetpack-script-data';
import { PanelRow } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import usePublicizeConfig from '../../hooks/use-publicize-config';
@@ -8,7 +7,7 @@ import styles from './styles.module.scss';
export const ConnectionNotice: React.FC = () => {
const { hasConnections } = useSocialMediaConnections();
- const { needsUserConnection } = usePublicizeConfig();
+ const { needsUserConnection, userConnectionUrl } = usePublicizeConfig();
if ( needsUserConnection ) {
return (
@@ -19,7 +18,7 @@ export const ConnectionNotice: React.FC = () => {
'jetpack'
) }
- { __( 'Connect now', 'jetpack' ) }
+ { __( 'Connect now', 'jetpack' ) }
);
diff --git a/projects/js-packages/publicize-components/src/components/form/settings-button.tsx b/projects/js-packages/publicize-components/src/components/form/settings-button.tsx
index 38487b16cb686..8f591da12a2f7 100644
--- a/projects/js-packages/publicize-components/src/components/form/settings-button.tsx
+++ b/projects/js-packages/publicize-components/src/components/form/settings-button.tsx
@@ -31,7 +31,7 @@ export function SettingsButton( { label, variant = 'primary' }: SettingsButtonPr
};
}, [] );
const { openConnectionsModal } = useDispatch( store );
- const { connectionsPageUrl } = usePublicizeConfig();
+ const { connectionsAdminUrl } = usePublicizeConfig();
const text = label || __( 'Manage connections', 'jetpack' );
const hasConnections = connections.length > 0;
@@ -46,7 +46,7 @@ export function SettingsButton( { label, variant = 'primary' }: SettingsButtonPr
{ text }
) : (
-
+
{ text }
);
diff --git a/projects/js-packages/publicize-components/src/components/form/unsupported-connections-notice.tsx b/projects/js-packages/publicize-components/src/components/form/unsupported-connections-notice.tsx
index 418bf27b85cdf..3ab32afa9437f 100644
--- a/projects/js-packages/publicize-components/src/components/form/unsupported-connections-notice.tsx
+++ b/projects/js-packages/publicize-components/src/components/form/unsupported-connections-notice.tsx
@@ -9,7 +9,7 @@ import { checkConnectionCode } from './utils';
export const UnsupportedConnectionsNotice: React.FC = () => {
const { connections } = useSocialMediaConnections();
- const { connectionsPageUrl } = usePublicizeConfig();
+ const { connectionsAdminUrl } = usePublicizeConfig();
const unsupportedConnections = connections.filter( connection =>
checkConnectionCode( connection, 'unsupported' )
@@ -24,7 +24,7 @@ export const UnsupportedConnectionsNotice: React.FC = () => {
'jetpack'
),
{
- moreInfo: ,
+ moreInfo: ,
}
) }
diff --git a/projects/js-packages/publicize-components/src/hooks/use-publicize-config/index.js b/projects/js-packages/publicize-components/src/hooks/use-publicize-config/index.js
index 3513a64247d4e..271cbd0ba514b 100644
--- a/projects/js-packages/publicize-components/src/hooks/use-publicize-config/index.js
+++ b/projects/js-packages/publicize-components/src/hooks/use-publicize-config/index.js
@@ -3,11 +3,12 @@ import {
getJetpackExtensionAvailability,
isUpgradable,
getJetpackData,
+ getSiteFragment,
isSimpleSite,
} from '@automattic/jetpack-shared-extension-utils';
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
-import { getSocialScriptData } from '../../utils';
+import { store as socialStore } from '../../social-store';
import { usePostMeta } from '../use-post-meta';
const republicizeFeatureName = 'republicize';
@@ -21,6 +22,7 @@ const republicizeFeatureName = 'republicize';
*/
export default function usePublicizeConfig() {
const sharesData = getJetpackData()?.social?.sharesData ?? {};
+ const blogID = getJetpackData()?.wpcomBlogId;
const isShareLimitEnabled = sharesData.is_share_limit_enabled;
const isRePublicizeFeatureAvailable =
getJetpackExtensionAvailability( republicizeFeatureName )?.available || isShareLimitEnabled;
@@ -28,7 +30,9 @@ export default function usePublicizeConfig() {
const currentPostType = useSelect( select => select( editorStore ).getCurrentPostType(), [] );
const { isUserConnected } = useConnection();
- const { urls } = getSocialScriptData();
+ const connectionsRootUrl =
+ getJetpackData()?.social?.publicizeConnectionsUrl ??
+ 'https://wordpress.com/marketing/connections/';
/*
* isPublicizeEnabledMeta:
@@ -101,6 +105,8 @@ export default function usePublicizeConfig() {
const needsUserConnection = ! isUserConnected && ! isSimpleSite();
+ const userConnectionUrl = useSelect( select => select( socialStore ).userConnectionUrl(), [] );
+
return {
isPublicizeEnabledMeta,
isPublicizeEnabled,
@@ -118,8 +124,11 @@ export default function usePublicizeConfig() {
isSocialImageGeneratorAvailable:
!! getJetpackData()?.social?.isSocialImageGeneratorAvailable && ! isJetpackSocialNote,
isSocialImageGeneratorEnabled: !! getJetpackData()?.social?.isSocialImageGeneratorEnabled,
- connectionsPageUrl: urls.connectionsManagementPage,
+ connectionsAdminUrl: connectionsRootUrl + ( blogID ?? getSiteFragment() ),
+ adminUrl: getJetpackData()?.social?.adminUrl,
+ jetpackSharingSettingsUrl: getJetpackData()?.social?.jetpackSharingSettingsUrl,
isJetpackSocialNote,
needsUserConnection,
+ userConnectionUrl,
};
}
diff --git a/projects/js-packages/publicize-components/src/social-store/reducer/index.js b/projects/js-packages/publicize-components/src/social-store/reducer/index.js
index dccb0e13abdda..e330313125616 100644
--- a/projects/js-packages/publicize-components/src/social-store/reducer/index.js
+++ b/projects/js-packages/publicize-components/src/social-store/reducer/index.js
@@ -12,6 +12,7 @@ const reducer = combineReducers( {
jetpackSettings,
socialImageGeneratorSettings,
hasPaidPlan: ( state = false ) => state,
+ userConnectionUrl: ( state = '' ) => state,
useAdminUiV1: ( state = false ) => state,
featureFlags: ( state = false ) => state,
hasPaidFeatures: ( state = false ) => state,
diff --git a/projects/js-packages/publicize-components/src/social-store/selectors/connection-data.js b/projects/js-packages/publicize-components/src/social-store/selectors/connection-data.js
index 4c6d003a1c196..a9427c8333c78 100644
--- a/projects/js-packages/publicize-components/src/social-store/selectors/connection-data.js
+++ b/projects/js-packages/publicize-components/src/social-store/selectors/connection-data.js
@@ -35,6 +35,15 @@ export function getConnectionsByService( state, serviceName ) {
return getConnections( state ).filter( ( { service_name } ) => service_name === serviceName );
}
+/**
+ * Returns the connections admin URL from the store.
+ * @param {import("../types").SocialStoreState} state - State object.
+ * @returns {string|null} The connections admin URL.
+ */
+export function getConnectionsAdminUrl( state ) {
+ return state.connectionData?.adminUrl ?? null;
+}
+
/**
* Returns whether there are connections in the store.
* @param {import("../types").SocialStoreState} state - State object.
diff --git a/projects/js-packages/publicize-components/src/social-store/selectors/index.js b/projects/js-packages/publicize-components/src/social-store/selectors/index.js
index 3597c9157746f..ad6608112a2fe 100644
--- a/projects/js-packages/publicize-components/src/social-store/selectors/index.js
+++ b/projects/js-packages/publicize-components/src/social-store/selectors/index.js
@@ -10,6 +10,7 @@ const selectors = {
...jetpackSettingSelectors,
...sharesData,
...socialImageGeneratorSettingsSelectors,
+ userConnectionUrl: state => state.userConnectionUrl,
useAdminUiV1: state => state.useAdminUiV1,
featureFlags: state => state.featureFlags,
hasPaidFeatures: state => state.hasPaidFeatures,
diff --git a/projects/js-packages/publicize-components/src/social-store/selectors/site-data.js b/projects/js-packages/publicize-components/src/social-store/selectors/site-data.js
index 3b4ab1d22a8b4..5f1d726f3082d 100644
--- a/projects/js-packages/publicize-components/src/social-store/selectors/site-data.js
+++ b/projects/js-packages/publicize-components/src/social-store/selectors/site-data.js
@@ -1,4 +1,5 @@
const siteDataSelectors = {
+ getAdminUrl: state => state.siteData?.adminUrl ?? null,
getAPIRootUrl: state => state.siteData?.apiRoot ?? null,
getAPINonce: state => state.siteData?.apiNonce ?? null,
getRegistrationNonce: state => state.siteData?.registrationNonce ?? null,
diff --git a/projects/js-packages/publicize-components/src/social-store/selectors/test/connection-data.test.js b/projects/js-packages/publicize-components/src/social-store/selectors/test/connection-data.test.js
index b73f4d62f1c49..61c92970b9325 100644
--- a/projects/js-packages/publicize-components/src/social-store/selectors/test/connection-data.test.js
+++ b/projects/js-packages/publicize-components/src/social-store/selectors/test/connection-data.test.js
@@ -1,5 +1,6 @@
import {
getConnections,
+ getConnectionsAdminUrl,
hasConnections,
getFailedConnections,
getMustReauthConnections,
@@ -10,6 +11,7 @@ import {
const state = {
connectionData: {
+ adminUrl: 'https://wordpress.com/some-url',
connections: [
{
id: '123456789',
@@ -62,6 +64,17 @@ describe( 'Social store selectors: connectionData', () => {
} );
} );
+ describe( 'getConnectionsAdminUrl', () => {
+ it( 'should return null if no adminUrl', () => {
+ expect( getConnectionsAdminUrl( {} ) ).toBeNull();
+ } );
+
+ it( 'should return adminUrl', () => {
+ const adminUrl = getConnectionsAdminUrl( state );
+ expect( adminUrl ).toEqual( state.connectionData.adminUrl );
+ } );
+ } );
+
describe( 'hasConnections', () => {
it( 'should return false if no connections', () => {
expect( hasConnections( {} ) ).toBe( false );
diff --git a/projects/js-packages/publicize-components/src/types/types.ts b/projects/js-packages/publicize-components/src/types/types.ts
index ad03070e386d9..05adb13d3c4be 100644
--- a/projects/js-packages/publicize-components/src/types/types.ts
+++ b/projects/js-packages/publicize-components/src/types/types.ts
@@ -2,14 +2,9 @@ export interface FeatureFlags {
useAdminUiV1: boolean;
}
-export interface SocialUrls {
- connectionsManagementPage: string;
-}
-
export interface SocialScriptData {
is_publicize_enabled: boolean;
feature_flags: FeatureFlags;
- urls: SocialUrls;
}
type JetpackSettingsSelectors = {
@@ -27,6 +22,7 @@ type JetpackSettingsSelectors = {
type ConnectionDataSelectors = {
getConnections: () => Array< object >;
getServices: () => Array< object >;
+ getConnectionsAdminUrl: () => string;
hasConnections: () => boolean;
};
diff --git a/projects/js-packages/publicize-components/src/utils/index.js b/projects/js-packages/publicize-components/src/utils/index.js
index 6e0284f7b9870..65f2dd163c5c5 100644
--- a/projects/js-packages/publicize-components/src/utils/index.js
+++ b/projects/js-packages/publicize-components/src/utils/index.js
@@ -2,4 +2,3 @@ export * from './get-share-message-max-length';
export * from './get-supported-additional-connections';
export * from './request-external-access';
export * from './types';
-export * from './script-data';
diff --git a/projects/js-packages/publicize-components/src/utils/script-data.ts b/projects/js-packages/publicize-components/src/utils/script-data.ts
deleted file mode 100644
index 9707648ae940b..0000000000000
--- a/projects/js-packages/publicize-components/src/utils/script-data.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import { getScriptData } from '@automattic/jetpack-script-data';
-import { SocialScriptData } from '../types/types';
-
-/**
- * Get the social script data from the window object.
- *
- * @returns {SocialScriptData} The social script data.
- */
-export function getSocialScriptData(): SocialScriptData {
- return getScriptData().social;
-}
diff --git a/projects/js-packages/script-data/changelog/update-social-initial-state-migrate-urls b/projects/js-packages/script-data/changelog/update-social-initial-state-migrate-urls
deleted file mode 100644
index 9095474b9fba3..0000000000000
--- a/projects/js-packages/script-data/changelog/update-social-initial-state-migrate-urls
+++ /dev/null
@@ -1,4 +0,0 @@
-Significance: patch
-Type: changed
-
-Migrated social URLs to use the new script data (initial state)
diff --git a/projects/js-packages/script-data/package.json b/projects/js-packages/script-data/package.json
index bee09b5ab60bd..7688537f442af 100644
--- a/projects/js-packages/script-data/package.json
+++ b/projects/js-packages/script-data/package.json
@@ -1,6 +1,6 @@
{
"name": "@automattic/jetpack-script-data",
- "version": "0.1.2-alpha",
+ "version": "0.1.1",
"description": "A library to provide data for script handles and the corresponding utility functions for Jetpack.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/script-data/#readme",
"bugs": {
diff --git a/projects/js-packages/script-data/src/utils.ts b/projects/js-packages/script-data/src/utils.ts
index adb9b36b4c37c..e23463e308d06 100644
--- a/projects/js-packages/script-data/src/utils.ts
+++ b/projects/js-packages/script-data/src/utils.ts
@@ -57,14 +57,3 @@ export function getMyJetpackUrl( section = '' ) {
export function getActiveFeatures() {
return getScriptData().site.plan?.features?.active ?? [];
}
-
-/**
- * Check if the site has a specific feature.
- *
- * @param {string} feature - The feature to check.
- *
- * @returns {boolean} Whether the site has the feature.
- */
-export function siteHasFeature( feature: string ) {
- return getActiveFeatures().includes( feature );
-}
diff --git a/projects/packages/publicize/changelog/update-social-initial-state-migrate-urls b/projects/packages/publicize/changelog/update-social-initial-state-migrate-urls
deleted file mode 100644
index 9095474b9fba3..0000000000000
--- a/projects/packages/publicize/changelog/update-social-initial-state-migrate-urls
+++ /dev/null
@@ -1,4 +0,0 @@
-Significance: patch
-Type: changed
-
-Migrated social URLs to use the new script data (initial state)
diff --git a/projects/packages/publicize/src/class-publicize-script-data.php b/projects/packages/publicize/src/class-publicize-script-data.php
index 04c64ef688690..d688b958f37e6 100644
--- a/projects/packages/publicize/src/class-publicize-script-data.php
+++ b/projects/packages/publicize/src/class-publicize-script-data.php
@@ -47,7 +47,7 @@ public static function set_admin_script_data( $data ) {
$data['social'] = self::get_admin_script_data();
- if ( empty( $data['site']['plan']['product_slug'] ) ) {
+ if ( empty( $data['site']['plan'] ) ) {
$data['site']['plan'] = Current_Plan::get();
}
@@ -83,9 +83,9 @@ public static function get_admin_script_data() {
return array_merge(
$basic_data,
array(
- 'urls' => self::get_urls(),
/**
* 'store' => self::get_store_script_data(),
+ * 'urls' => self::get_urls(),
* 'shares_data' => self::get_shares_data(),
*/
)
@@ -133,23 +133,4 @@ public static function has_feature_flag( $feature ): bool {
return Current_Plan::supports( 'social-' . $feature );
}
-
- /**
- * Get the URLs.
- *
- * @return array
- */
- public static function get_urls() {
-
- $urls = array(
- 'connectionsManagementPage' => self::publicize()->publicize_connections_url(
- 'jetpack-social-connections-admin-page'
- ),
- );
-
- // Escape the URLs.
- array_walk( $urls, 'esc_url_raw' );
-
- return $urls;
- }
}
diff --git a/projects/plugins/jetpack/changelog/update-social-initial-state-migrate-urls b/projects/plugins/jetpack/changelog/update-social-initial-state-migrate-urls
deleted file mode 100644
index 59ebeed6d5616..0000000000000
--- a/projects/plugins/jetpack/changelog/update-social-initial-state-migrate-urls
+++ /dev/null
@@ -1,4 +0,0 @@
-Significance: patch
-Type: other
-
-Fixed unit test
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/controls.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/controls.js
index 79e0c682052dd..77a52f9da4a9e 100644
--- a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/controls.js
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/controls.js
@@ -71,12 +71,6 @@ beforeEach( () => {
setGradient.mockClear();
setTextColor.mockClear();
setButtonBackgroundColor.mockClear();
-
- global.JetpackScriptData = {
- social: {
- urls: {},
- },
- };
} );
describe( 'Inspector controls', () => {
diff --git a/projects/plugins/social/changelog/update-social-initial-state-migrate-urls b/projects/plugins/social/changelog/update-social-initial-state-migrate-urls
deleted file mode 100644
index 9095474b9fba3..0000000000000
--- a/projects/plugins/social/changelog/update-social-initial-state-migrate-urls
+++ /dev/null
@@ -1,4 +0,0 @@
-Significance: patch
-Type: changed
-
-Migrated social URLs to use the new script data (initial state)
diff --git a/projects/plugins/social/src/js/components/admin-page/header/index.jsx b/projects/plugins/social/src/js/components/admin-page/header/index.jsx
index 5a35a427cceeb..0a2eb23d3509a 100644
--- a/projects/plugins/social/src/js/components/admin-page/header/index.jsx
+++ b/projects/plugins/social/src/js/components/admin-page/header/index.jsx
@@ -1,5 +1,4 @@
import { SOCIAL_STORE_ID } from '@automattic/jetpack-publicize-components';
-import { getMyJetpackUrl } from '@automattic/jetpack-script-data';
import { useSelect } from '@wordpress/data';
import { createInterpolateElement } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
@@ -12,7 +11,7 @@ const AdminPageHeader = () => {
return {
showPricingPage: store.showPricingPage(),
- activateLicenseUrl: getMyJetpackUrl( '#/add-license' ),
+ activateLicenseUrl: `${ store.getAdminUrl() }admin.php?page=my-jetpack#/add-license`,
};
} );
diff --git a/projects/plugins/social/src/js/components/header/index.js b/projects/plugins/social/src/js/components/header/index.js
index 7d2c82af17d57..10604c5dd3db0 100644
--- a/projects/plugins/social/src/js/components/header/index.js
+++ b/projects/plugins/social/src/js/components/header/index.js
@@ -12,9 +12,8 @@ import {
ShareLimitsBar,
store as socialStore,
useShareLimits,
- getSocialScriptData,
} from '@automattic/jetpack-publicize-components';
-import { getAdminUrl } from '@automattic/jetpack-script-data';
+import { getScriptData } from '@automattic/jetpack-script-data';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { Icon, postList } from '@wordpress/icons';
@@ -22,28 +21,29 @@ import StatCards from '../stat-cards';
import styles from './styles.module.scss';
const Header = () => {
+ const connectionData = window.jetpackSocialInitialState.connectionData ?? {};
const {
- // TODO replace some of these from script data (initial state)
+ connectionsAdminUrl,
hasConnections,
isModuleEnabled,
+ newPostUrl,
postsCount,
totalShareCount,
showShareLimits,
} = useSelect( select => {
const store = select( socialStore );
return {
+ connectionsAdminUrl: connectionData.adminUrl,
hasConnections: store.getConnections().length > 0,
isModuleEnabled: store.isModuleEnabled(),
+ newPostUrl: `${ store.getAdminUrl() }post-new.php`,
postsCount: store.getSharedPostsCount(),
totalShareCount: store.getTotalSharesCount(),
showShareLimits: store.showShareLimits(),
};
} );
-
- const {
- feature_flags: { useAdminUiV1 },
- urls,
- } = getSocialScriptData();
+ // TODO - Replace this with a utility function like `getSocialFeatureFlags` when available
+ const { useAdminUiV1 } = getScriptData().social.feature_flags;
const { hasConnectionError } = useConnectionErrorNotice();
@@ -79,16 +79,13 @@ const Header = () => {
{ __( 'Connect accounts', 'jetpack-social' ) }
) : (
-