From 2c61fc7cbe4c2d03e091654c79c2b7fa550cad82 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 25 May 2021 15:14:30 +0300 Subject: [PATCH 1/2] edit-navigation: no-string-literals fix --- packages/edit-navigation/src/components/add-menu/index.js | 3 ++- .../edit-navigation/src/components/layout/shortcuts.js | 3 ++- packages/edit-navigation/src/hooks/use-menu-entity.js | 5 +++-- .../edit-navigation/src/hooks/use-menu-notifications.js | 5 +++-- packages/edit-navigation/src/store/selectors.js | 7 ++++--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/edit-navigation/src/components/add-menu/index.js b/packages/edit-navigation/src/components/add-menu/index.js index 0e21f6cf045d9..cc42d4ee96057 100644 --- a/packages/edit-navigation/src/components/add-menu/index.js +++ b/packages/edit-navigation/src/components/add-menu/index.js @@ -12,6 +12,7 @@ import { TextControl, Button } from '@wordpress/components'; import { useFocusOnMount } from '@wordpress/compose'; import { __, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; +import { store as coreStore } from '@wordpress/core-data'; const menuNameMatches = ( menuName ) => ( menu ) => menu.name.toLowerCase() === menuName.toLowerCase(); @@ -29,7 +30,7 @@ export default function AddMenu( { noticesStore ); const [ isCreatingMenu, setIsCreatingMenu ] = useState( false ); - const { saveMenu } = useDispatch( 'core' ); + const { saveMenu } = useDispatch( coreStore ); const inputRef = useFocusOnMount( focusInputOnMount ); diff --git a/packages/edit-navigation/src/components/layout/shortcuts.js b/packages/edit-navigation/src/components/layout/shortcuts.js index 9c2e228b4cc0e..ab03b25e7cd3a 100644 --- a/packages/edit-navigation/src/components/layout/shortcuts.js +++ b/packages/edit-navigation/src/components/layout/shortcuts.js @@ -8,6 +8,7 @@ import { store as keyboardShortcutsStore, } from '@wordpress/keyboard-shortcuts'; import { __ } from '@wordpress/i18n'; +import { store as coreStore } from '@wordpress/core-data'; function NavigationEditorShortcuts( { saveBlocks } ) { useShortcut( @@ -21,7 +22,7 @@ function NavigationEditorShortcuts( { saveBlocks } ) { } ); - const { redo, undo } = useDispatch( 'core' ); + const { redo, undo } = useDispatch( coreStore ); useShortcut( 'core/edit-navigation/undo', ( event ) => { diff --git a/packages/edit-navigation/src/hooks/use-menu-entity.js b/packages/edit-navigation/src/hooks/use-menu-entity.js index d6a00a7e694fa..7d3946e201a06 100644 --- a/packages/edit-navigation/src/hooks/use-menu-entity.js +++ b/packages/edit-navigation/src/hooks/use-menu-entity.js @@ -2,19 +2,20 @@ * WordPress dependencies */ import { useSelect, useDispatch } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies */ import { MENU_KIND, MENU_POST_TYPE } from '../constants'; export default function useMenuEntity( menuId ) { - const { editEntityRecord } = useDispatch( 'core' ); + const { editEntityRecord } = useDispatch( coreStore ); const menuEntityData = [ MENU_KIND, MENU_POST_TYPE, menuId ]; const editedMenu = useSelect( ( select ) => menuId && - select( 'core' ).getEditedEntityRecord( ...menuEntityData ), + select( coreStore ).getEditedEntityRecord( ...menuEntityData ), [ menuId ] ); diff --git a/packages/edit-navigation/src/hooks/use-menu-notifications.js b/packages/edit-navigation/src/hooks/use-menu-notifications.js index bedcbd8cb7901..8ff8d4f028aff 100644 --- a/packages/edit-navigation/src/hooks/use-menu-notifications.js +++ b/packages/edit-navigation/src/hooks/use-menu-notifications.js @@ -4,6 +4,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { useEffect } from '@wordpress/element'; import { store as noticesStore } from '@wordpress/notices'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies */ @@ -12,11 +13,11 @@ import { MENU_POST_TYPE, MENU_KIND } from '../constants'; export default function useMenuNotifications( menuId ) { const { lastSaveError, lastDeleteError } = useSelect( ( select ) => ( { - lastSaveError: select( 'core' ).getLastEntitySaveError( + lastSaveError: select( coreStore ).getLastEntitySaveError( MENU_KIND, MENU_POST_TYPE ), - lastDeleteError: select( 'core' ).getLastEntityDeleteError( + lastDeleteError: select( coreStore ).getLastEntityDeleteError( MENU_KIND, MENU_POST_TYPE, menuId diff --git a/packages/edit-navigation/src/store/selectors.js b/packages/edit-navigation/src/store/selectors.js index 9cfbed52cc864..54faf71d43038 100644 --- a/packages/edit-navigation/src/store/selectors.js +++ b/packages/edit-navigation/src/store/selectors.js @@ -7,6 +7,7 @@ import { invert } from 'lodash'; * WordPress dependencies */ import { createRegistrySelector } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies @@ -43,7 +44,7 @@ export const getNavigationPostForMenu = createRegistrySelector( if ( ! hasResolvedNavigationPost( state, menuId ) ) { return null; } - return select( 'core' ).getEditedEntityRecord( + return select( coreStore ).getEditedEntityRecord( NAVIGATION_POST_KIND, NAVIGATION_POST_POST_TYPE, buildNavigationPostId( menuId ) @@ -59,7 +60,7 @@ export const getNavigationPostForMenu = createRegistrySelector( */ export const hasResolvedNavigationPost = createRegistrySelector( ( select ) => ( state, menuId ) => { - return select( 'core' ).hasFinishedResolution( 'getEntityRecord', [ + return select( coreStore ).hasFinishedResolution( 'getEntityRecord', [ NAVIGATION_POST_KIND, NAVIGATION_POST_POST_TYPE, buildNavigationPostId( menuId ), @@ -77,6 +78,6 @@ export const hasResolvedNavigationPost = createRegistrySelector( export const getMenuItemForClientId = createRegistrySelector( ( select ) => ( state, postId, clientId ) => { const mapping = invert( state.mapping[ postId ] ); - return select( 'core' ).getMenuItem( mapping[ clientId ] ); + return select( coreStore ).getMenuItem( mapping[ clientId ] ); } ); From 200bec93b5385318563bfaa527c6a509348e793f Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Wed, 26 May 2021 14:19:43 +0300 Subject: [PATCH 2/2] this expects strings and not an object --- packages/edit-navigation/src/store/selectors.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/edit-navigation/src/store/selectors.js b/packages/edit-navigation/src/store/selectors.js index 54faf71d43038..764c7effc7c69 100644 --- a/packages/edit-navigation/src/store/selectors.js +++ b/packages/edit-navigation/src/store/selectors.js @@ -44,7 +44,7 @@ export const getNavigationPostForMenu = createRegistrySelector( if ( ! hasResolvedNavigationPost( state, menuId ) ) { return null; } - return select( coreStore ).getEditedEntityRecord( + return select( coreStore.name ).getEditedEntityRecord( NAVIGATION_POST_KIND, NAVIGATION_POST_POST_TYPE, buildNavigationPostId( menuId ) @@ -60,7 +60,9 @@ export const getNavigationPostForMenu = createRegistrySelector( */ export const hasResolvedNavigationPost = createRegistrySelector( ( select ) => ( state, menuId ) => { - return select( coreStore ).hasFinishedResolution( 'getEntityRecord', [ + return select( + coreStore.name + ).hasFinishedResolution( 'getEntityRecord', [ NAVIGATION_POST_KIND, NAVIGATION_POST_POST_TYPE, buildNavigationPostId( menuId ), @@ -78,6 +80,6 @@ export const hasResolvedNavigationPost = createRegistrySelector( export const getMenuItemForClientId = createRegistrySelector( ( select ) => ( state, postId, clientId ) => { const mapping = invert( state.mapping[ postId ] ); - return select( coreStore ).getMenuItem( mapping[ clientId ] ); + return select( coreStore.name ).getMenuItem( mapping[ clientId ] ); } );