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

Social | Initial state: Migrate feature flags to script data #38952

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c66d6e4
Social | Initial state: Migrate feature flags to script data
manzoorwanijk Aug 19, 2024
9e9c944
Replace the remaining uses of useAdminUiV1
manzoorwanijk Aug 19, 2024
fa71135
Phan doesn't like calling deprecated functions
manzoorwanijk Aug 19, 2024
689db9a
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 20, 2024
069ad13
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 21, 2024
60e37e8
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 21, 2024
f495351
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 21, 2024
437c21a
Fix duplication after rebase conflicts
manzoorwanijk Aug 21, 2024
c58dd5e
Remove jetpack-script-data as a direct dependency
manzoorwanijk Aug 21, 2024
97f006e
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 21, 2024
4ae0aed
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 27, 2024
5ed7955
Fix up versions
manzoorwanijk Aug 27, 2024
ac57164
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 27, 2024
a9dfe67
Migrate useShareStatus flag
manzoorwanijk Aug 27, 2024
57fc5a1
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 28, 2024
3c1c8ca
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 28, 2024
16bb256
Migrate more useShareStatus flag
manzoorwanijk Aug 28, 2024
2536633
Clean up
manzoorwanijk Aug 28, 2024
7d94532
Merge branch 'trunk' into update/social-initial-state-migrate-feature…
manzoorwanijk Aug 29, 2024
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
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Social: Migrated feature flags to new script data
1 change: 1 addition & 0 deletions projects/js-packages/publicize-components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ export * from './src/hooks/use-saving-post';
export * from './src/hooks/use-post-meta';
export * from './src/components/share-buttons';
export * from './src/components/manage-connections-modal';
export * from './src/utils/script-data';
export * from './src/utils/shares-data';
export * from './src/components/global-modals';
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Button } from '@automattic/jetpack-components';
import { ExternalLink } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { useDispatch } from '@wordpress/data';
import { createInterpolateElement, Fragment } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import usePublicizeConfig from '../../hooks/use-publicize-config';
import useSocialMediaConnections from '../../hooks/use-social-media-connections';
import { store } from '../../social-store';
import { Connection } from '../../social-store/types';
import { getSocialScriptData } from '../../utils/script-data';
import Notice from '../notice';
import { useServiceLabel } from '../services/use-service-label';
import styles from './styles.module.scss';
Expand All @@ -27,7 +28,8 @@ export const BrokenConnectionsNotice: React.FC = () => {

const { connectionsAdminUrl } = usePublicizeConfig();

const useAdminUiV1 = useSelect( select => select( store ).useAdminUiV1(), [] );
const { useAdminUiV1 } = getSocialScriptData().feature_flags;

const { openConnectionsModal } = useDispatch( store );

const fixLink = useAdminUiV1 ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
*/

import { Disabled, PanelRow } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { Fragment } from '@wordpress/element';
import { usePublicizeConfig } from '../../..';
import useAttachedMedia from '../../hooks/use-attached-media';
import useFeaturedImage from '../../hooks/use-featured-image';
import useMediaDetails from '../../hooks/use-media-details';
import useMediaRestrictions from '../../hooks/use-media-restrictions';
import useSocialMediaConnections from '../../hooks/use-social-media-connections';
import { store as socialStore } from '../../social-store';
import { getSocialScriptData } from '../../utils/script-data';
import { ThemedConnectionsModal as ManageConnectionsModal } from '../manage-connections-modal';
import { SocialPostModal } from '../social-post-modal/modal';
import { ConnectionNotice } from './connection-notice';
Expand Down Expand Up @@ -48,28 +47,22 @@ export default function PublicizeForm() {
attachedMedia.length > 0 ||
( Object.keys( validationErrors ).length !== 0 && ! isConvertible ) );

const { useAdminUiV1, featureFlags } = useSelect( select => {
const store = select( socialStore );
return {
useAdminUiV1: store.useAdminUiV1(),
featureFlags: store.featureFlags(),
};
}, [] );

const Wrapper = isPublicizeDisabledBySitePlan ? Disabled : Fragment;

const { feature_flags } = getSocialScriptData();

return (
<Wrapper>
{
// Render modal only once
useAdminUiV1 ? <ManageConnectionsModal /> : null
feature_flags.useAdminUiV1 ? <ManageConnectionsModal /> : null
}
{ hasConnections ? (
<>
<PanelRow>
<ConnectionsList />
</PanelRow>
{ featureFlags.useEditorPreview && isPublicizeEnabled ? <SocialPostModal /> : null }
{ feature_flags.useEditorPreview && isPublicizeEnabled ? <SocialPostModal /> : null }
<EnhancedFeaturesNudge />
</>
) : null }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import usePublicizeConfig from '../../hooks/use-publicize-config';
import { store } from '../../social-store';
import { getSocialScriptData } from '../../utils/script-data';
import styles from './styles.module.scss';

type SettingsButtonProps = {
Expand All @@ -24,9 +25,10 @@ type SettingsButtonProps = {
* @return {import('react').ReactNode} The button/link component.
*/
export function SettingsButton( { label, variant = 'primary' }: SettingsButtonProps ) {
const { useAdminUiV1, connections } = useSelect( select => {
const { useAdminUiV1 } = getSocialScriptData().feature_flags;

const { connections } = useSelect( select => {
return {
useAdminUiV1: select( store ).useAdminUiV1(),
connections: select( store ).getConnections(),
};
}, [] );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useSelect } from '@wordpress/data';
import { store as socialStore } from '../../social-store';
import { getSocialScriptData } from '../../utils/script-data';
import { ThemedShareStatusModal as ShareStatusModal } from '../share-status';

export const GlobalModals = () => {
const featureFlags = useSelect( select => select( socialStore ).featureFlags(), [] );
const { feature_flags } = getSocialScriptData();

return <>{ featureFlags.useShareStatus ? <ShareStatusModal /> : null }</>;
return <>{ feature_flags.useShareStatus ? <ShareStatusModal /> : null }</>;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ThemeProvider } from '@automattic/jetpack-components';
import { getSocialScriptData } from '../../utils/script-data';
import PostPublishManualSharing from '../post-publish-manual-sharing';
import PostPublishReviewPrompt from '../post-publish-review-prompt';
import { PostPublishShareStatus } from '../post-publish-share-status';

const PostPublishPanels = () => {
const { feature_flags } = getSocialScriptData();
return (
<ThemeProvider targetDom={ document.body }>
<PostPublishShareStatus />
{ feature_flags.useShareStatus ? <PostPublishShareStatus /> : null }
<PostPublishManualSharing />
<PostPublishReviewPrompt />
</ThemeProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import { ShareStatus } from './share-status';
*/
export function PostPublishShareStatus() {
const { isPublicizeEnabled } = usePostMeta();
const { featureFlags, postId, isPostPublised } = useSelect( select => {
const store = select( socialStore );

const { postId, isPostPublised } = useSelect( select => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- `@wordpress/editor` is a nightmare to work with TypeScript
const _editorStore = select( editorStore ) as any;

return {
featureFlags: store.featureFlags(),
postId: _editorStore.getCurrentPostId(),
isPostPublised: _editorStore.isCurrentPostPublished(),
};
Expand All @@ -32,7 +29,7 @@ export function PostPublishShareStatus() {

const willPostBeShared = isPublicizeEnabled && enabledConnections.length > 0;

if ( ! featureFlags.useShareStatus || ! willPostBeShared || ! isPostPublised ) {
if ( ! willPostBeShared || ! isPostPublised ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Button } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { forwardRef } from 'react';
import { store as socialStore } from '../../social-store';
import { getSocialScriptData } from '../../utils/script-data';
import styles from './styles.module.scss';
import type { ButtonProps } from '@wordpress/components/build-types/button/types';

Expand All @@ -16,10 +17,9 @@ type ModalTriggerProps = ButtonProps & {
export const ModalTrigger = forwardRef(
( { withWrapper = false, ...props }: ModalTriggerProps, ref: unknown ) => {
const { openShareStatusModal } = useDispatch( socialStore );
const { feature_flags } = getSocialScriptData();

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

if ( ! featureFlags.useShareStatus ) {
if ( ! feature_flags.useShareStatus ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const reducer = combineReducers( {
shareStatus,
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 @@ -11,8 +11,6 @@ const selectors = {
...socialImageGeneratorSettingsSelectors,
...shareStatusSelectors,
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
Expand Up @@ -61,8 +61,6 @@ export type SocialStoreState = {
hasPaidPlan?: boolean;
// on Jetack Social admin page
jetpackSettings?: JetpackSettings;
useAdminUiV1?: boolean;
featureFlags?: Record< string, boolean >;
shareStatus?: ShareStatus;
};

Expand Down
2 changes: 2 additions & 0 deletions projects/js-packages/publicize-components/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export type SharesData = {

export interface FeatureFlags {
useAdminUiV1: boolean;
useEditorPreview: boolean;
useShareStatus: boolean;
}

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

Social: Migrated feature flags to new script data
11 changes: 1 addition & 10 deletions projects/packages/publicize/src/class-publicize-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,7 @@ public function use_admin_ui_v1(): bool {
* @return bool
*/
public function has_feature_flag( $flag_name, $feature_name ): bool {
// If the option is set, use it.
if ( get_option( 'jetpack_social_has_' . $flag_name, false ) ) {
return true;
}
// If the constant is set, use it.
if ( defined( 'JETPACK_SOCIAL_HAS_' . strtoupper( $flag_name ) ) && constant( 'JETPACK_SOCIAL_HAS_' . strtoupper( $flag_name ) ) ) {
return true;
}

return Current_Plan::supports( 'social-' . $feature_name );
return Publicize_Script_Data::has_feature_flag( $feature_name );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public static function get_admin_script_data() {
*/
public static function get_feature_flags() {
$variable_to_feature_map = array(
'useAdminUiV1' => 'connections-management',
'useAdminUiV1' => 'connections-management',
'useEditorPreview' => 'editor-preview',
'useShareStatus' => 'share-status',
);

$feature_flags = array();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import formatCurrency from '@automattic/format-currency';
import restApi from '@automattic/jetpack-api';
import { getRedirectUrl } from '@automattic/jetpack-components';
import { getSocialScriptData } from '@automattic/jetpack-publicize-components';
import { sprintf, __, _x } from '@wordpress/i18n';
import {
PLAN_JETPACK_SECURITY_T1_YEARLY,
Expand All @@ -14,7 +15,6 @@ import {
getSiteRawUrl,
getJetpackCloudUrl,
getStaticProductsForPurchase,
getSocialInitiaState,
} from 'state/initial-state';
import { updateSettings } from 'state/settings';
import { fetchPluginsData } from 'state/site/plugins';
Expand Down Expand Up @@ -79,12 +79,12 @@ export const mapStateToSummaryFeatureProps = ( state, featureSlug ) => {
};
case 'publicize':
return {
configureButtonLabel: getSocialInitiaState( state ).useAdminUiV1
configureButtonLabel: getSocialScriptData().feature_flags.useAdminUiV1
? __( 'View Jetpack Social settings', 'jetpack' )
: _x( 'Manage connections', '', 'jetpack' ),
displayName: __( 'Social Media Sharing', 'jetpack' ),
summaryActivateButtonLabel: __( 'Enable', 'jetpack' ),
configLink: getSocialInitiaState( state ).useAdminUiV1
configLink: getSocialScriptData().feature_flags.useAdminUiV1
? '#/sharing'
: getRedirectUrl( 'calypso-marketing-connections', {
site: getSiteRawUrl( state ),
Expand Down Expand Up @@ -562,7 +562,7 @@ export const getStepContent = ( state, stepSlug ) => {
'jetpack'
),
ctaText: __( 'Manage Social Media Connections', 'jetpack' ),
ctaLink: getSocialInitiaState( state ).useAdminUiV1
ctaLink: getSocialScriptData().feature_flags.useAdminUiV1
? getSiteAdminUrl( state ) + 'admin.php?page=jetpack#/sharing'
: getRedirectUrl( 'calypso-marketing-connections', {
site: getSiteRawUrl( state ),
Expand Down
6 changes: 4 additions & 2 deletions projects/plugins/jetpack/_inc/client/sharing/index.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getSocialScriptData } from '@automattic/jetpack-publicize-components';
import { __ } from '@wordpress/i18n';
import QuerySite from 'components/data/query-site';
import React, { Component } from 'react';
Expand Down Expand Up @@ -27,6 +28,8 @@ import { ShareButtons } from './share-buttons';

class Sharing extends Component {
render() {
const { useAdminUiV1 } = getSocialScriptData().feature_flags;

const commonProps = {
settings: this.props.settings,
getModule: this.props.module,
Expand All @@ -45,7 +48,7 @@ class Sharing extends Component {
isAtomicSite: this.props.isAtomicSite,
hasSharingBlock: this.props.hasSharingBlock,
isBlockTheme: this.props.isBlockTheme,
useAdminUiV1: this.props.useAdminUiV1,
useAdminUiV1,
};

const foundPublicize = this.props.isModuleFound( 'publicize' ),
Expand Down Expand Up @@ -100,6 +103,5 @@ export default connect( state => {
isAtomicSite: isAtomicSite( state ),
hasSharingBlock: isSharingBlockAvailable( state ),
isBlockTheme: currentThemeIsBlockTheme( state ),
useAdminUiV1: state.jetpack.initialState.socialInitialState.useAdminUiV1,
};
} )( Sharing );
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Social: Migrated feature flags to new script data
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Social: Migrated feature flags to new script data
1 change: 0 additions & 1 deletion projects/plugins/social/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@automattic/jetpack-base-styles": "workspace:*",
"@automattic/jetpack-components": "workspace:*",
"@automattic/jetpack-connection": "workspace:*",
"@automattic/jetpack-script-data": "workspace:*",
"@automattic/jetpack-publicize-components": "workspace:*",
"@automattic/jetpack-shared-extension-utils": "workspace:*",
"@wordpress/api-fetch": "7.5.0",
Expand Down
8 changes: 4 additions & 4 deletions projects/plugins/social/src/js/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
} from '@automattic/jetpack-components';
import { ConnectionError, useConnectionErrorNotice } from '@automattic/jetpack-connection';
import {
store as socialStore,
getSocialScriptData,
getTotalSharesCount,
getSharedPostsCount,
store as socialStore,
} from '@automattic/jetpack-publicize-components';
import { getScriptData } from '@automattic/jetpack-script-data';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { Icon, postList } from '@wordpress/icons';
Expand All @@ -36,8 +36,8 @@ const Header = () => {
newPostUrl: `${ store.getAdminUrl() }post-new.php`,
};
} );
// TODO - Replace this with a utility function like `getSocialFeatureFlags` when available
const { useAdminUiV1 } = getScriptData().social.feature_flags;

const { useAdminUiV1 } = getSocialScriptData().feature_flags;

const { hasConnectionError } = useConnectionErrorNotice();

Expand Down
Loading
Loading