Remove active item from navigation store (https://github.com/woocommerce/woocommerce-admin/pull/6486)
* Remove active item from navigation store * Add changelog entry
This commit is contained in:
parent
7a20e582a3
commit
40a86daf2f
|
@ -125,10 +125,9 @@ const Container = ( { menuItems } ) => {
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withSelect( ( select ) => {
|
withSelect( ( select ) => {
|
||||||
const { getActiveItem, getMenuItems } = select( NAVIGATION_STORE_NAME );
|
const { getMenuItems } = select( NAVIGATION_STORE_NAME );
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeItem: getActiveItem(),
|
|
||||||
menuItems: getMenuItems(),
|
menuItems: getMenuItems(),
|
||||||
};
|
};
|
||||||
} )
|
} )
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
const TYPES = {
|
const TYPES = {
|
||||||
ADD_MENU_ITEMS: 'ADD_MENU_ITEMS',
|
ADD_MENU_ITEMS: 'ADD_MENU_ITEMS',
|
||||||
SET_MENU_ITEMS: 'SET_MENU_ITEMS',
|
SET_MENU_ITEMS: 'SET_MENU_ITEMS',
|
||||||
SET_ACTIVE_ITEM: 'SET_ACTIVE_ITEM',
|
|
||||||
ADD_FAVORITE_FAILURE: 'ADD_FAVORITE_FAILURE',
|
ADD_FAVORITE_FAILURE: 'ADD_FAVORITE_FAILURE',
|
||||||
ADD_FAVORITE_REQUEST: 'ADD_FAVORITE_REQUEST',
|
ADD_FAVORITE_REQUEST: 'ADD_FAVORITE_REQUEST',
|
||||||
ADD_FAVORITE_SUCCESS: 'ADD_FAVORITE_SUCCESS',
|
ADD_FAVORITE_SUCCESS: 'ADD_FAVORITE_SUCCESS',
|
||||||
|
|
|
@ -9,13 +9,6 @@ import apiFetch from '@wordpress/api-fetch';
|
||||||
import TYPES from './action-types';
|
import TYPES from './action-types';
|
||||||
import { WC_ADMIN_NAMESPACE } from '../constants';
|
import { WC_ADMIN_NAMESPACE } from '../constants';
|
||||||
|
|
||||||
export function setActiveItem( activeItem ) {
|
|
||||||
return {
|
|
||||||
type: TYPES.SET_ACTIVE_ITEM,
|
|
||||||
activeItem,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setMenuItems( menuItems ) {
|
export function setMenuItems( menuItems ) {
|
||||||
return {
|
return {
|
||||||
type: TYPES.SET_MENU_ITEMS,
|
type: TYPES.SET_MENU_ITEMS,
|
||||||
|
|
|
@ -5,21 +5,14 @@ import TYPES from './action-types';
|
||||||
|
|
||||||
const reducer = (
|
const reducer = (
|
||||||
state = {
|
state = {
|
||||||
activeItem: null,
|
|
||||||
error: null,
|
error: null,
|
||||||
menuItems: [],
|
menuItems: [],
|
||||||
favorites: [],
|
favorites: [],
|
||||||
requesting: {},
|
requesting: {},
|
||||||
},
|
},
|
||||||
{ type, activeItem, error, favorite, favorites, menuItems }
|
{ type, error, favorite, favorites, menuItems }
|
||||||
) => {
|
) => {
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
case TYPES.SET_ACTIVE_ITEM:
|
|
||||||
state = {
|
|
||||||
...state,
|
|
||||||
activeItem,
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case TYPES.SET_MENU_ITEMS:
|
case TYPES.SET_MENU_ITEMS:
|
||||||
state = {
|
state = {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
@ -9,10 +9,6 @@ export const getMenuItems = ( state ) => {
|
||||||
return applyFilters( MENU_ITEMS_HOOK, state.menuItems );
|
return applyFilters( MENU_ITEMS_HOOK, state.menuItems );
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getActiveItem = ( state ) => {
|
|
||||||
return state.activeItem || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getFavorites = ( state ) => {
|
export const getFavorites = ( state ) => {
|
||||||
return state.favorites || [];
|
return state.favorites || [];
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,6 @@ import reducer from '../reducer';
|
||||||
import TYPES from '../action-types';
|
import TYPES from '../action-types';
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
activeItem: null,
|
|
||||||
error: null,
|
error: null,
|
||||||
menuItems: [],
|
menuItems: [],
|
||||||
favorites: [],
|
favorites: [],
|
||||||
|
@ -75,15 +74,6 @@ describe( 'navigation reducer', () => {
|
||||||
expect( state.menuItems[ 1 ].id ).toBe( 'menu-item-2' );
|
expect( state.menuItems[ 1 ].id ).toBe( 'menu-item-2' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
it( 'should set the active menu item', () => {
|
|
||||||
const state = reducer( defaultState, {
|
|
||||||
type: TYPES.SET_ACTIVE_ITEM,
|
|
||||||
activeItem: 'test-active-item',
|
|
||||||
} );
|
|
||||||
|
|
||||||
expect( state.activeItem ).toBe( 'test-active-item' );
|
|
||||||
} );
|
|
||||||
|
|
||||||
it( 'should set the favorites', () => {
|
it( 'should set the favorites', () => {
|
||||||
const favorites = [ 'favorite1', 'favorite2' ];
|
const favorites = [ 'favorite1', 'favorite2' ];
|
||||||
const state = reducer( defaultState, {
|
const state = reducer( defaultState, {
|
||||||
|
|
|
@ -76,6 +76,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
|
||||||
== Unreleased ==
|
== Unreleased ==
|
||||||
|
|
||||||
- Dev: Add initial tests for navigation Menu class #6492
|
- Dev: Add initial tests for navigation Menu class #6492
|
||||||
|
- Dev: Remove active item from navigation store #6486
|
||||||
- Fix: Add check for navigating being enabled. #6462
|
- Fix: Add check for navigating being enabled. #6462
|
||||||
- Dev: Add nav favorite button tests #6446
|
- Dev: Add nav favorite button tests #6446
|
||||||
- Dev: Add a changelog lint check to PRs. #6414
|
- Dev: Add a changelog lint check to PRs. #6414
|
||||||
|
|
Loading…
Reference in New Issue