Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit-navigation: no-string-literals fix #32196

Merged
merged 2 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/edit-navigation/src/components/add-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 );

Expand Down
3 changes: 2 additions & 1 deletion packages/edit-navigation/src/components/layout/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -21,7 +22,7 @@ function NavigationEditorShortcuts( { saveBlocks } ) {
}
);

const { redo, undo } = useDispatch( 'core' );
const { redo, undo } = useDispatch( coreStore );
useShortcut(
'core/edit-navigation/undo',
( event ) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/edit-navigation/src/hooks/use-menu-entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
);

Expand Down
5 changes: 3 additions & 2 deletions packages/edit-navigation/src/hooks/use-menu-notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions packages/edit-navigation/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,7 +44,7 @@ export const getNavigationPostForMenu = createRegistrySelector(
if ( ! hasResolvedNavigationPost( state, menuId ) ) {
return null;
}
return select( 'core' ).getEditedEntityRecord(
return select( coreStore.name ).getEditedEntityRecord(
NAVIGATION_POST_KIND,
NAVIGATION_POST_POST_TYPE,
buildNavigationPostId( menuId )
Expand All @@ -59,7 +60,9 @@ export const getNavigationPostForMenu = createRegistrySelector(
*/
export const hasResolvedNavigationPost = createRegistrySelector(
( select ) => ( state, menuId ) => {
return select( 'core' ).hasFinishedResolution( 'getEntityRecord', [
return select(
coreStore.name
).hasFinishedResolution( 'getEntityRecord', [
NAVIGATION_POST_KIND,
NAVIGATION_POST_POST_TYPE,
buildNavigationPostId( menuId ),
Expand All @@ -77,6 +80,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.name ).getMenuItem( mapping[ clientId ] );
}
);