From cce445fa79fdf7eeeb3be37b87ed0c7198f15570 Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Tue, 6 Apr 2021 13:17:22 +0200 Subject: [PATCH 1/3] revert #27717 (#30524) Co-authored-by: grzim --- .../src/components/post-text-editor/index.js | 18 +++----------- .../components/post-text-editor/test/index.js | 24 ++----------------- 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/packages/editor/src/components/post-text-editor/index.js b/packages/editor/src/components/post-text-editor/index.js index 577f4741927018..b764c02014f44f 100644 --- a/packages/editor/src/components/post-text-editor/index.js +++ b/packages/editor/src/components/post-text-editor/index.js @@ -7,13 +7,12 @@ import Textarea from 'react-autosize-textarea'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { useState, useEffect } from '@wordpress/element'; +import { useState } from '@wordpress/element'; import { parse } from '@wordpress/blocks'; import { useDispatch, useSelect } from '@wordpress/data'; import { useInstanceId } from '@wordpress/compose'; import { VisuallyHidden } from '@wordpress/components'; -export const DEBOUNCE_TIME = 300; export default function PostTextEditor() { const postContent = useSelect( ( select ) => select( 'core/editor' ).getEditedPostContent(), @@ -30,18 +29,6 @@ export default function PostTextEditor() { setValue( postContent ); } - const saveText = () => { - const blocks = parse( value ); - resetEditorBlocks( blocks ); - }; - - useEffect( () => { - const timeoutId = setTimeout( saveText, DEBOUNCE_TIME ); - return () => { - clearTimeout( timeoutId ); - }; - }, [ value ] ); - /** * Handles a textarea change event to notify the onChange prop callback and * reflect the new value in the component's own state. This marks the start @@ -67,7 +54,8 @@ export default function PostTextEditor() { */ const stopEditing = () => { if ( isDirty ) { - saveText(); + const blocks = parse( value ); + resetEditorBlocks( blocks ); setIsDirty( false ); } }; diff --git a/packages/editor/src/components/post-text-editor/test/index.js b/packages/editor/src/components/post-text-editor/test/index.js index c6f8492a1fb58d..d132c3b47cd79a 100644 --- a/packages/editor/src/components/post-text-editor/test/index.js +++ b/packages/editor/src/components/post-text-editor/test/index.js @@ -7,14 +7,13 @@ import Textarea from 'react-autosize-textarea'; /** * WordPress dependencies */ -import * as wp from '@wordpress/data'; +import { useSelect } from '@wordpress/data'; /** * Internal dependencies */ -import PostTextEditor, { DEBOUNCE_TIME } from '../'; +import PostTextEditor from '../'; -const useSelect = wp.useSelect; // "Downgrade" ReactAutosizeTextarea to a regular textarea. Assumes aligned // props interface. jest.mock( 'react-autosize-textarea', () => ( props ) => ( @@ -176,23 +175,4 @@ describe( 'PostTextEditor', () => { expect( textarea.props.value ).toBe( 'Goodbye World' ); } ); - it( 'debounce value update after given time', () => { - let wrapper; - act( () => { - wrapper = create( ); - } ); - const mockDispatchFn = jest.fn(); - jest.mock( '@wordpress/data/src/components/use-dispatch', () => ( { - useDispatch: () => ( { - editPost: jest.fn(), - resetEditorBlocks: mockDispatchFn, - } ), - } ) ); - - const textarea = wrapper.root.findByType( Textarea ); - act( () => textarea.props.onChange( { target: { value: 'text' } } ) ); - setTimeout( () => { - expect( mockDispatchFn ).toHaveBeenCalled(); - }, DEBOUNCE_TIME ); - } ); } ); From 0321966d66c6c64d642d54b2a1c2fc90c1a844e6 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 6 Apr 2021 16:20:02 +0400 Subject: [PATCH 2/3] Use getAuthors for 'showCombobox' check (#30218) * Use getAuthors for 'showCombobox' check * Add inline comment --- packages/editor/src/components/post-author/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/components/post-author/index.js b/packages/editor/src/components/post-author/index.js index 90affecc2291e0..0739d75e5e9ed9 100644 --- a/packages/editor/src/components/post-author/index.js +++ b/packages/editor/src/components/post-author/index.js @@ -2,6 +2,7 @@ * WordPress dependencies */ import { useSelect } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies @@ -13,10 +14,8 @@ const minimumUsersForCombobox = 25; function PostAuthor() { const showCombobox = useSelect( ( select ) => { - const authors = select( 'core' ).getUsers( { - who: 'authors', - per_page: minimumUsersForCombobox + 1, - } ); + // Not using `getUsers()` because it requires `list_users` capability. + const authors = select( coreStore ).getAuthors(); return authors?.length >= minimumUsersForCombobox; }, [] ); From ad5e1c49e1a12a4bc60bd8aaccae93c138ea6d8f Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 6 Apr 2021 16:21:21 +0400 Subject: [PATCH 3/3] Gallery: Set 'addToGallery' prop to false when images don't have IDs. (#30122) This also sets MediaPlaceholder value to an empty object. With both props set to "falsy" values, the gallery media frame is initialized in the "Create Gallery" state. This lets users replace placeholder images from patterns. --- packages/block-library/src/gallery/edit.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/gallery/edit.js b/packages/block-library/src/gallery/edit.js index 8482e29812516c..a0ef21b6edd633 100644 --- a/packages/block-library/src/gallery/edit.js +++ b/packages/block-library/src/gallery/edit.js @@ -322,10 +322,11 @@ function GalleryEdit( props ) { }, [ linkTo ] ); const hasImages = !! images.length; + const hasImageIds = hasImages && images.some( ( image ) => !! image.id ); const mediaPlaceholder = (