From 5ffa599e3e014a882b370a742140dde5ac17aeda Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Tue, 12 Sep 2023 15:52:25 +0800 Subject: [PATCH] Use private selectors and actions --- .../edit-site/src/components/add-new-pattern/index.js | 3 +-- packages/patterns/src/components/create-pattern-modal.js | 5 +++-- .../patterns/src/components/pattern-convert-button.js | 7 +++++-- .../patterns/src/components/patterns-manage-button.js | 9 +++++++-- packages/patterns/src/store/index.js | 5 +++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/edit-site/src/components/add-new-pattern/index.js b/packages/edit-site/src/components/add-new-pattern/index.js index b1d791a8ea70b..16907006809f6 100644 --- a/packages/edit-site/src/components/add-new-pattern/index.js +++ b/packages/edit-site/src/components/add-new-pattern/index.js @@ -33,8 +33,7 @@ export default function AddNewPattern() { const settings = select( editSiteStore ).getSettings(); return !! settings.supportsTemplatePartsMode; }, [] ); - const { __experimentalCreatePatternFromFile: createPatternFromFile } = - useDispatch( patternsStore ); + const { createPatternFromFile } = unlock( useDispatch( patternsStore ) ); const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); const patternUploadInputRef = useRef(); diff --git a/packages/patterns/src/components/create-pattern-modal.js b/packages/patterns/src/components/create-pattern-modal.js index c2541340384b9..369a1aca24e11 100644 --- a/packages/patterns/src/components/create-pattern-modal.js +++ b/packages/patterns/src/components/create-pattern-modal.js @@ -24,7 +24,8 @@ export const SYNC_TYPES = { /** * Internal dependencies */ -import { store } from '../store'; +import { store as patternsStore } from '../store'; +import { unlock } from '../lock-unlock'; export default function CreatePatternModal( { onSuccess, @@ -35,7 +36,7 @@ export default function CreatePatternModal( { } ) { const [ syncType, setSyncType ] = useState( SYNC_TYPES.full ); const [ title, setTitle ] = useState( '' ); - const { createPattern } = useDispatch( store ); + const { createPattern } = unlock( useDispatch( patternsStore ) ); const { createErrorNotice } = useDispatch( noticesStore ); const onCreate = async function ( patternTitle, sync ) { diff --git a/packages/patterns/src/components/pattern-convert-button.js b/packages/patterns/src/components/pattern-convert-button.js index 474b5aefccf8e..8434009133871 100644 --- a/packages/patterns/src/components/pattern-convert-button.js +++ b/packages/patterns/src/components/pattern-convert-button.js @@ -20,6 +20,7 @@ import { store as noticesStore } from '@wordpress/notices'; */ import { store as patternsStore } from '../store'; import CreatePatternModal from './create-pattern-modal'; +import { unlock } from '../lock-unlock'; /** * Menu control to convert block(s) to a pattern block. @@ -32,7 +33,9 @@ import CreatePatternModal from './create-pattern-modal'; export default function PatternConvertButton( { clientIds, rootClientId } ) { const { createSuccessNotice } = useDispatch( noticesStore ); const { replaceBlocks } = useDispatch( blockEditorStore ); - const { __experimentalSetEditingPattern } = useDispatch( patternsStore ); + // Ignore reason: false positive of the lint rule. + // eslint-disable-next-line @wordpress/no-unused-vars-before-return + const { setEditingPattern } = unlock( useDispatch( patternsStore ) ); const [ isModalOpen, setIsModalOpen ] = useState( false ); const canConvert = useSelect( ( select ) => { @@ -98,7 +101,7 @@ export default function PatternConvertButton( { clientIds, rootClientId } ) { } ); replaceBlocks( clientIds, newBlock ); - __experimentalSetEditingPattern( newBlock.clientId, true ); + setEditingPattern( newBlock.clientId, true ); createSuccessNotice( pattern.wp_pattern_sync_status === 'unsynced' diff --git a/packages/patterns/src/components/patterns-manage-button.js b/packages/patterns/src/components/patterns-manage-button.js index eae307f1838de..5f407682bea0f 100644 --- a/packages/patterns/src/components/patterns-manage-button.js +++ b/packages/patterns/src/components/patterns-manage-button.js @@ -12,7 +12,8 @@ import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies */ -import { store as editorStore } from '../store'; +import { store as patternsStore } from '../store'; +import { unlock } from '../lock-unlock'; function PatternsManageButton( { clientId } ) { const { canRemove, isVisible, innerBlockCount, managePatternsUrl } = @@ -51,7 +52,11 @@ function PatternsManageButton( { clientId } ) { [ clientId ] ); - const { convertSyncedPatternToStatic } = useDispatch( editorStore ); + // Ignore reason: false positive of the lint rule. + // eslint-disable-next-line @wordpress/no-unused-vars-before-return + const { convertSyncedPatternToStatic } = unlock( + useDispatch( patternsStore ) + ); if ( ! isVisible ) { return null; diff --git a/packages/patterns/src/store/index.js b/packages/patterns/src/store/index.js index 6293a7b33408e..af3da7f0ff498 100644 --- a/packages/patterns/src/store/index.js +++ b/packages/patterns/src/store/index.js @@ -10,6 +10,7 @@ import reducer from './reducer'; import * as actions from './actions'; import { STORE_NAME } from './constants'; import * as selectors from './selectors'; +import { unlock } from '../lock-unlock'; /** * Post editor data store configuration. @@ -20,8 +21,6 @@ import * as selectors from './selectors'; */ export const storeConfig = { reducer, - selectors, - actions, }; /** @@ -36,3 +35,5 @@ export const store = createReduxStore( STORE_NAME, { } ); register( store ); +unlock( store ).registerPrivateActions( actions ); +unlock( store ).registerPrivateSelectors( selectors );