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: Replace remaining store name string with constant #27281

Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/edit-navigation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { addFilter } from '@wordpress/hooks';
import Layout from './components/layout';
import './store';

export { STORE_NAME } from './store/constants';
gziolo marked this conversation as resolved.
Show resolved Hide resolved

function disableInsertingNonNavigationBlocks( settings, name ) {
if ( ! [ 'core/navigation', 'core/navigation-link' ].includes( name ) ) {
set( settings, [ 'supports', 'inserter' ], false );
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-navigation/src/store/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Module Constants
*/
export const STORE_NAME = 'core/edit-navigation';
6 changes: 3 additions & 3 deletions packages/edit-navigation/src/store/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createRegistryControl } from '@wordpress/data';
* Internal dependencies
*/
import { menuItemsQuery } from './utils';
import { STORE_NAME } from './constants';

/**
* Trigger an API Fetch request.
Expand Down Expand Up @@ -72,7 +73,7 @@ export function getMenuItemToClientIdMapping( postId ) {
export function getNavigationPostForMenu( menuId ) {
return {
type: 'SELECT',
registryName: 'core/edit-navigation',
registryName: STORE_NAME,
selectorName: 'getNavigationPostForMenu',
args: [ menuId ],
};
Expand Down Expand Up @@ -173,7 +174,6 @@ const controls = {
),
};

const getState = ( registry ) =>
registry.stores[ 'core/edit-navigation' ].store.getState();
const getState = ( registry ) => registry.stores[ STORE_NAME ].store.getState();

export default controls;
6 changes: 1 addition & 5 deletions packages/edit-navigation/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import * as resolvers from './resolvers';
import * as selectors from './selectors';
import * as actions from './actions';
import controls from './controls';

/**
* Module Constants
*/
const STORE_NAME = 'core/edit-navigation';
import { STORE_NAME } from './constants';

/**
* Block editor data store configuration.
Expand Down
21 changes: 11 additions & 10 deletions packages/edit-navigation/src/store/test/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import controls, {
dispatch,
} from '../controls';
import { menuItemsQuery } from '../utils';
import { STORE_NAME } from '../constants';

// Mock it to prevent calling window.fetch in test environment
jest.mock( '@wordpress/api-fetch', () => jest.fn( ( request ) => request ) );
Expand Down Expand Up @@ -63,7 +64,7 @@ describe( 'getNavigationPostForMenu', () => {
it( 'has the correct type and payload', () => {
expect( getNavigationPostForMenu( 123 ) ).toEqual( {
type: 'SELECT',
registryName: 'core/edit-navigation',
registryName: STORE_NAME,
selectorName: 'getNavigationPostForMenu',
args: [ 123 ],
} );
Expand Down Expand Up @@ -144,7 +145,7 @@ describe( 'controls', () => {
};
const registry = {
stores: {
'core/edit-navigation': {
[ STORE_NAME ]: {
store: {
getState: jest.fn( () => state ),
},
Expand All @@ -157,7 +158,7 @@ describe( 'controls', () => {
).toEqual( [ 'action1', 'action2' ] );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 1 );

expect(
Expand All @@ -167,7 +168,7 @@ describe( 'controls', () => {
).toEqual( [] );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 2 );
} );

Expand All @@ -181,7 +182,7 @@ describe( 'controls', () => {
};
const registry = {
stores: {
'core/edit-navigation': {
[ STORE_NAME ]: {
store: {
getState: jest.fn( () => state ),
},
Expand All @@ -194,7 +195,7 @@ describe( 'controls', () => {
).toBe( true );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 1 );

expect(
Expand All @@ -204,7 +205,7 @@ describe( 'controls', () => {
).toBe( false );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 2 );
} );

Expand All @@ -218,7 +219,7 @@ describe( 'controls', () => {
};
const registry = {
stores: {
'core/edit-navigation': {
[ STORE_NAME ]: {
store: {
getState: jest.fn( () => state ),
},
Expand All @@ -235,7 +236,7 @@ describe( 'controls', () => {
} );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 1 );

expect(
Expand All @@ -245,7 +246,7 @@ describe( 'controls', () => {
).toEqual( {} );

expect(
registry.stores[ 'core/edit-navigation' ].store.getState
registry.stores[ STORE_NAME ].store.getState
).toHaveBeenCalledTimes( 2 );
} );

Expand Down
1 change: 1 addition & 0 deletions packages/edit-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@wordpress/core-data": "file:../core-data",
"@wordpress/data": "file:../data",
"@wordpress/data-controls": "file:../data-controls",
"@wordpress/edit-navigation": "file:../edit-navigation",
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
"@wordpress/element": "file:../element",
"@wordpress/hooks": "file:../hooks",
"@wordpress/i18n": "file:../i18n",
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-widgets/src/store/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { createRegistryControl } from '@wordpress/data';
import { STORE_NAME as editNavigationStoreName } from '@wordpress/edit-navigation';

/**
* Internal dependencies
Expand Down Expand Up @@ -74,7 +75,7 @@ export function getWidgetToClientIdMapping() {
export function getNavigationPostForMenu( menuId ) {
return {
type: 'SELECT',
registryName: 'core/edit-navigation',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it as a hardcoded string and revert the change in this line. We shouldn't expose new constants from @wordpress/edit-navigation. It is probably something complex that we better ignore in this PR.

@adamziel and @noisysocks, aren't edit-widgets and edit-navigation two packages that target two different pages? I'm curious how it works since @wordpress/edit-widgets doesn't depend on @wordpress/edit-navigation as you can learn from the package.json file changes proposed in this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably just a mistake. edit-widgets's store is originally copied from edit-navigation, seems like we just forgot to delete this.

registryName: editNavigationStoreName,
selectorName: 'getNavigationPostForMenu',
args: [ menuId ],
};
Expand Down