Skip to content

Commit

Permalink
Revert changes to feature flags other than useAdminUiV1
Browse files Browse the repository at this point in the history
  • Loading branch information
manzoorwanijk committed Aug 29, 2024
1 parent 7d94532 commit 9a73374
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
*/

import { Disabled, PanelRow } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { Fragment } from '@wordpress/element';
import { usePublicizeConfig } from '../../..';
import { getSocialScriptData, 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 { getSocialScriptData } from '../../utils/script-data';
import { store as socialStore } from '../../social-store';
import { ThemedConnectionsModal as ManageConnectionsModal } from '../manage-connections-modal';
import { SocialPostModal } from '../social-post-modal/modal';
import { ConnectionNotice } from './connection-notice';
Expand Down Expand Up @@ -46,6 +47,12 @@ export default function PublicizeForm() {
// fix the issues with uploading an image.
attachedMedia.length > 0 ||
( Object.keys( validationErrors ).length !== 0 && ! isConvertible ) );
const { featureFlags } = useSelect( select => {
const store = select( socialStore );
return {
featureFlags: store.featureFlags(),
};
}, [] );

const Wrapper = isPublicizeDisabledBySitePlan ? Disabled : Fragment;

Expand All @@ -62,7 +69,7 @@ export default function PublicizeForm() {
<PanelRow>
<ConnectionsList />
</PanelRow>
{ feature_flags.useEditorPreview && isPublicizeEnabled ? <SocialPostModal /> : null }
{ featureFlags.useEditorPreview && isPublicizeEnabled ? <SocialPostModal /> : null }
<EnhancedFeaturesNudge />
</>
) : null }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getSocialScriptData } from '../../utils/script-data';
import { useSelect } from '@wordpress/data';
import { store as socialStore } from '../../social-store';
import { ThemedShareStatusModal as ShareStatusModal } from '../share-status';

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

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

// 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 @@ -29,7 +32,7 @@ export function PostPublishShareStatus() {

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Button } from '@wordpress/components';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } 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 @@ -17,9 +16,10 @@ type ModalTriggerProps = ButtonProps & {
export const ModalTrigger = forwardRef(
( { withWrapper = false, ...props }: ModalTriggerProps, ref: unknown ) => {
const { openShareStatusModal } = useDispatch( socialStore );
const { feature_flags } = getSocialScriptData();

if ( ! feature_flags.useShareStatus ) {
const featureFlags = useSelect( select => select( socialStore ).featureFlags(), [] );

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const reducer = combineReducers( {
shareStatus,
hasPaidPlan: ( state = false ) => state,
userConnectionUrl: ( state = '' ) => state,
featureFlags: ( state = false ) => state,
hasPaidFeatures: ( state = false ) => state,
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const selectors = {
...socialImageGeneratorSettingsSelectors,
...shareStatusSelectors,
userConnectionUrl: state => state.userConnectionUrl,
featureFlags: state => state.featureFlags,
hasPaidFeatures: state => state.hasPaidFeatures,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type SocialStoreState = {
hasPaidPlan?: boolean;
// on Jetack Social admin page
jetpackSettings?: JetpackSettings;
featureFlags?: Record< string, boolean >;
shareStatus?: ShareStatus;
};

Expand Down
2 changes: 0 additions & 2 deletions projects/js-packages/publicize-components/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ 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
Expand Up @@ -120,9 +120,7 @@ public static function get_admin_script_data() {
*/
public static function get_feature_flags() {
$variable_to_feature_map = array(
'useAdminUiV1' => 'connections-management',
'useEditorPreview' => 'editor-preview',
'useShareStatus' => 'share-status',
'useAdminUiV1' => 'connections-management',
);

$feature_flags = array();
Expand Down

0 comments on commit 9a73374

Please sign in to comment.