Skip to content
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

Revert "Social | Initial State: Migrate URLs (#38855)" #38907

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -37,7 +37,7 @@ export const BrokenConnectionsNotice: React.FC = () => {
className={ styles[ 'broken-connection-btn' ] }
/>
) : (
<ExternalLink href={ connectionsPageUrl } />
<ExternalLink href={ connectionsAdminUrl } />
);

const getServiceLabel = useServiceLabel();
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
Expand All @@ -19,7 +18,7 @@ export const ConnectionNotice: React.FC = () => {
'jetpack'
) }
&nbsp;
<a href={ getMyJetpackUrl( '#/connection' ) }>{ __( 'Connect now', 'jetpack' ) }</a>
<a href={ userConnectionUrl }>{ __( 'Connect now', 'jetpack' ) }</a>
</p>
</PanelRow>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,7 +46,7 @@ export function SettingsButton( { label, variant = 'primary' }: SettingsButtonPr
{ text }
</Button>
) : (
<ExternalLink className={ styles[ 'settings-button' ] } href={ connectionsPageUrl }>
<ExternalLink className={ styles[ 'settings-button' ] } href={ connectionsAdminUrl }>
{ text }
</ExternalLink>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Expand All @@ -24,7 +24,7 @@ export const UnsupportedConnectionsNotice: React.FC = () => {
'jetpack'
),
{
moreInfo: <ExternalLink href={ connectionsPageUrl } />,
moreInfo: <ExternalLink href={ connectionsAdminUrl } />,
}
) }
</Notice>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,14 +22,17 @@ 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;
const isPostPublished = useSelect( select => select( editorStore ).isCurrentPostPublished(), [] );
const currentPostType = useSelect( select => select( editorStore ).getCurrentPostType(), [] );
const { isUserConnected } = useConnection();

const { urls } = getSocialScriptData();
const connectionsRootUrl =
getJetpackData()?.social?.publicizeConnectionsUrl ??
'https://wordpress.com/marketing/connections/';

/*
* isPublicizeEnabledMeta:
Expand Down Expand Up @@ -101,6 +105,8 @@ export default function usePublicizeConfig() {

const needsUserConnection = ! isUserConnected && ! isSimpleSite();

const userConnectionUrl = useSelect( select => select( socialStore ).userConnectionUrl(), [] );

return {
isPublicizeEnabledMeta,
isPublicizeEnabled,
Expand All @@ -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,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
getConnections,
getConnectionsAdminUrl,
hasConnections,
getFailedConnections,
getMustReauthConnections,
Expand All @@ -10,6 +11,7 @@ import {

const state = {
connectionData: {
adminUrl: 'https://wordpress.com/some-url',
connections: [
{
id: '123456789',
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 1 addition & 5 deletions projects/js-packages/publicize-components/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -27,6 +22,7 @@ type JetpackSettingsSelectors = {
type ConnectionDataSelectors = {
getConnections: () => Array< object >;
getServices: () => Array< object >;
getConnectionsAdminUrl: () => string;
hasConnections: () => boolean;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
11 changes: 0 additions & 11 deletions projects/js-packages/publicize-components/src/utils/script-data.ts

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion projects/js-packages/script-data/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
11 changes: 0 additions & 11 deletions projects/js-packages/script-data/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

This file was deleted.

23 changes: 2 additions & 21 deletions projects/packages/publicize/src/class-publicize-script-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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(),
*/
)
Expand Down Expand Up @@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ beforeEach( () => {
setGradient.mockClear();
setTextColor.mockClear();
setButtonBackgroundColor.mockClear();

global.JetpackScriptData = {
social: {
urls: {},
},
};
} );

describe( 'Inspector controls', () => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,7 +11,7 @@ const AdminPageHeader = () => {

return {
showPricingPage: store.showPricingPage(),
activateLicenseUrl: getMyJetpackUrl( '#/add-license' ),
activateLicenseUrl: `${ store.getAdminUrl() }admin.php?page=my-jetpack#/add-license`,
};
} );

Expand Down
Loading
Loading