From 531c442cb3f2e37cdf71a748a855bbe961611bca Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 19 Jul 2024 09:37:51 +0300 Subject: [PATCH 1/2] DataViews: Fix pattens list selection --- .../src/components/page-patterns/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/page-patterns/index.js b/packages/edit-site/src/components/page-patterns/index.js index 27b75424e5f3b8..35b06fbc6f0b64 100644 --- a/packages/edit-site/src/components/page-patterns/index.js +++ b/packages/edit-site/src/components/page-patterns/index.js @@ -13,7 +13,13 @@ import { Flex, } from '@wordpress/components'; import { __, _x } from '@wordpress/i18n'; -import { useState, useMemo, useId, useEffect } from '@wordpress/element'; +import { + useState, + useMemo, + useId, + useEffect, + useCallback, +} from '@wordpress/element'; import { BlockPreview, privateApis as blockEditorPrivateApis, @@ -252,6 +258,10 @@ export default function DataviewsPatterns() { const { params: { postType, categoryId: categoryIdFromURL }, } = useLocation(); + const [ selection, setSelection ] = useState( [] ); + const onChangeSelection = useCallback( ( items ) => { + setSelection( items ); + }, [] ); const type = postType || PATTERN_TYPES.user; const categoryId = categoryIdFromURL || PATTERN_DEFAULT_CATEGORY; const [ view, setView ] = useState( DEFAULT_VIEW ); @@ -409,6 +419,8 @@ export default function DataviewsPatterns() { isLoading={ isResolving } view={ view } onChangeView={ setView } + selection={ selection } + onChangeSelection={ onChangeSelection } defaultLayouts={ defaultLayouts } /> From 1964474d8258f12885939bbc4a6410677f449e0a Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 19 Jul 2024 10:55:18 +0300 Subject: [PATCH 2/2] pass callback directly --- .../edit-site/src/components/page-patterns/index.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/edit-site/src/components/page-patterns/index.js b/packages/edit-site/src/components/page-patterns/index.js index 35b06fbc6f0b64..65e79b406cf559 100644 --- a/packages/edit-site/src/components/page-patterns/index.js +++ b/packages/edit-site/src/components/page-patterns/index.js @@ -13,13 +13,7 @@ import { Flex, } from '@wordpress/components'; import { __, _x } from '@wordpress/i18n'; -import { - useState, - useMemo, - useId, - useEffect, - useCallback, -} from '@wordpress/element'; +import { useState, useMemo, useId, useEffect } from '@wordpress/element'; import { BlockPreview, privateApis as blockEditorPrivateApis, @@ -259,9 +253,6 @@ export default function DataviewsPatterns() { params: { postType, categoryId: categoryIdFromURL }, } = useLocation(); const [ selection, setSelection ] = useState( [] ); - const onChangeSelection = useCallback( ( items ) => { - setSelection( items ); - }, [] ); const type = postType || PATTERN_TYPES.user; const categoryId = categoryIdFromURL || PATTERN_DEFAULT_CATEGORY; const [ view, setView ] = useState( DEFAULT_VIEW ); @@ -420,7 +411,7 @@ export default function DataviewsPatterns() { view={ view } onChangeView={ setView } selection={ selection } - onChangeSelection={ onChangeSelection } + onChangeSelection={ setSelection } defaultLayouts={ defaultLayouts } />