Skip to content

Commit e467349

Browse files
gmjuhaszmatticbot
authored andcommitted
Social: Hide custom message box for Social Notes (#41948)
* Create util hook for checking if post is a Social Note * Use util hook for hiding the messaebox and for sig hook * changelog * Add test Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13494036666 Upstream-Ref: Automattic/jetpack@a096b32
1 parent e0f7d69 commit e467349

File tree

5 files changed

+67
-13
lines changed

5 files changed

+67
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This is an alpha version! The changes listed here are not final.
1414

1515
### Fixed
1616
- Fixed an issue with unsupported connection showing up
17+
- Fixed custom message box showing up for custom notes
1718
- Social Previews | Fixed distorted image for Tumblr preview
1819
- Social | Fix plugin version in admin page footer
1920
- Social | Hide upgrade nudge for Atomic sites

src/components/form/share-post-form.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { siteHasFeature } from '@automattic/jetpack-script-data';
22
import useSocialMediaMessage from '../../hooks/use-social-media-message';
33
import { features } from '../../utils/constants';
4+
import { useIsSocialNote } from '../../utils/use-is-social-note';
45
import MediaSection from '../media-section';
56
import MessageBoxControl from '../message-box-control';
67
import styles from './styles.module.scss';
@@ -17,15 +18,18 @@ type SharePostFormProps = {
1718
*/
1819
export const SharePostForm: React.FC< SharePostFormProps > = ( { analyticsData = null } ) => {
1920
const { message, updateMessage, maxLength } = useSocialMediaMessage();
21+
const isSocialNote = useIsSocialNote();
2022

2123
return (
2224
<>
23-
<MessageBoxControl
24-
maxLength={ maxLength }
25-
onChange={ updateMessage }
26-
message={ message }
27-
analyticsData={ analyticsData }
28-
/>
25+
{ ! isSocialNote && (
26+
<MessageBoxControl
27+
maxLength={ maxLength }
28+
onChange={ updateMessage }
29+
message={ message }
30+
analyticsData={ analyticsData }
31+
/>
32+
) }
2933
{ siteHasFeature( features.ENHANCED_PUBLISHING ) && (
3034
<div className={ styles[ 'share-post-form__media-section' ] }>
3135
<MediaSection analyticsData={ analyticsData } />
+2-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import { siteHasFeature } from '@automattic/jetpack-script-data';
2-
import { useSelect } from '@wordpress/data';
3-
import { store as editorStore } from '@wordpress/editor';
42
import { features } from '../../utils/constants';
3+
import { useIsSocialNote } from '../../utils/use-is-social-note';
54

65
/**
76
* When a post can use the Social Image Generator (SIG).
87
*
98
* @return {boolean} Whether the post can use the Social Image Generator.
109
*/
1110
export function usePostCanUseSig() {
12-
const isJetpackSocialNote = useSelect( select => {
13-
const currentPostType = select( editorStore ).getCurrentPostType();
14-
15-
return 'jetpack-social-note' === currentPostType;
16-
}, [] );
11+
const isJetpackSocialNote = useIsSocialNote();
1712

1813
return ! isJetpackSocialNote && siteHasFeature( features.IMAGE_GENERATOR );
1914
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { renderHook } from '@testing-library/react';
2+
import { store as editorStore } from '@wordpress/editor';
3+
import { useIsSocialNote } from '../use-is-social-note';
4+
5+
// Mock the editor store
6+
jest.mock( '@wordpress/editor', () => ( {
7+
store: 'core/editor',
8+
} ) );
9+
10+
const mockGetCurrentPostType = jest.fn();
11+
const mockSelect = jest.fn().mockReturnValue( { getCurrentPostType: mockGetCurrentPostType } );
12+
13+
jest.mock( '@wordpress/data', () => ( {
14+
useSelect: jest.fn( fn => fn( mockSelect ) ),
15+
} ) );
16+
17+
describe( 'useIsSocialNote', () => {
18+
beforeEach( () => {
19+
jest.clearAllMocks();
20+
} );
21+
22+
it( 'should return true when post type is jetpack-social-note', () => {
23+
mockGetCurrentPostType.mockReturnValue( 'jetpack-social-note' );
24+
const { result } = renderHook( () => useIsSocialNote() );
25+
26+
expect( result.current ).toBe( true );
27+
expect( mockSelect ).toHaveBeenCalledWith( editorStore );
28+
expect( mockGetCurrentPostType ).toHaveBeenCalled();
29+
} );
30+
31+
it( 'should return false when post type is not jetpack-social-note', () => {
32+
mockGetCurrentPostType.mockReturnValue( 'post' );
33+
const { result } = renderHook( () => useIsSocialNote() );
34+
35+
expect( result.current ).toBe( false );
36+
expect( mockSelect ).toHaveBeenCalledWith( editorStore );
37+
expect( mockGetCurrentPostType ).toHaveBeenCalled();
38+
} );
39+
} );

src/utils/use-is-social-note.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useSelect } from '@wordpress/data';
2+
import { store as editorStore } from '@wordpress/editor';
3+
4+
/**
5+
* Whether the current post is a social note.
6+
*
7+
* @return {boolean} Whether the current post is a social note.
8+
*/
9+
export function useIsSocialNote() {
10+
return useSelect( select => {
11+
const currentPostType = select( editorStore ).getCurrentPostType();
12+
13+
return 'jetpack-social-note' === currentPostType;
14+
}, [] );
15+
}

0 commit comments

Comments
 (0)