Hide Inventory and Reviews panels if store setup task list is visible (https://github.com/woocommerce/woocommerce-admin/pull/6182)
* Fixed reviews and inventory panels visibility This commit fixes the reviews and inventory panels visibility when setup task list is enabled * Fixed tests * Fixed control and small refactor * Fixed useSelect * Fixed multiple useSelect Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
parent
fc41022dd4
commit
7bf63fae05
|
@ -11,6 +11,7 @@ import {
|
||||||
__experimentalText as Text,
|
__experimentalText as Text,
|
||||||
} from '@wordpress/components';
|
} from '@wordpress/components';
|
||||||
import { getSetting } from '@woocommerce/wc-admin-settings';
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
||||||
|
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
@ -34,16 +35,18 @@ export const ActivityPanel = () => {
|
||||||
const countLowStockProducts = getLowStockCount( select );
|
const countLowStockProducts = getLowStockCount( select );
|
||||||
const countUnapprovedReviews = getUnapprovedReviews( select );
|
const countUnapprovedReviews = getUnapprovedReviews( select );
|
||||||
const publishedProductCount = getSetting( 'publishedProductCount', 0 );
|
const publishedProductCount = getSetting( 'publishedProductCount', 0 );
|
||||||
|
const { getOption } = select( OPTIONS_STORE_NAME );
|
||||||
|
const isTaskListHidden = getOption( 'woocommerce_task_list_hidden' );
|
||||||
return {
|
return {
|
||||||
countLowStockProducts,
|
countLowStockProducts,
|
||||||
countUnreadOrders,
|
|
||||||
manageStock,
|
|
||||||
orderStatuses,
|
|
||||||
totalOrderCount,
|
|
||||||
reviewsEnabled,
|
|
||||||
countUnapprovedReviews,
|
countUnapprovedReviews,
|
||||||
|
countUnreadOrders,
|
||||||
|
isTaskListHidden,
|
||||||
|
manageStock,
|
||||||
publishedProductCount,
|
publishedProductCount,
|
||||||
|
reviewsEnabled,
|
||||||
|
totalOrderCount,
|
||||||
|
orderStatuses,
|
||||||
};
|
};
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ export function getAllPanels( {
|
||||||
countLowStockProducts,
|
countLowStockProducts,
|
||||||
countUnapprovedReviews,
|
countUnapprovedReviews,
|
||||||
countUnreadOrders,
|
countUnreadOrders,
|
||||||
|
isTaskListHidden,
|
||||||
manageStock,
|
manageStock,
|
||||||
orderStatuses,
|
orderStatuses,
|
||||||
publishedProductCount,
|
publishedProductCount,
|
||||||
|
@ -37,6 +38,7 @@ export function getAllPanels( {
|
||||||
},
|
},
|
||||||
totalOrderCount > 0 &&
|
totalOrderCount > 0 &&
|
||||||
publishedProductCount > 0 &&
|
publishedProductCount > 0 &&
|
||||||
|
isTaskListHidden === 'yes' &&
|
||||||
manageStock === 'yes' && {
|
manageStock === 'yes' && {
|
||||||
className: 'woocommerce-homescreen-card',
|
className: 'woocommerce-homescreen-card',
|
||||||
count: countLowStockProducts,
|
count: countLowStockProducts,
|
||||||
|
@ -51,6 +53,7 @@ export function getAllPanels( {
|
||||||
title: __( 'Stock', 'woocommerce-admin' ),
|
title: __( 'Stock', 'woocommerce-admin' ),
|
||||||
},
|
},
|
||||||
publishedProductCount > 0 &&
|
publishedProductCount > 0 &&
|
||||||
|
isTaskListHidden === 'yes' &&
|
||||||
reviewsEnabled === 'yes' && {
|
reviewsEnabled === 'yes' && {
|
||||||
className: 'woocommerce-homescreen-card',
|
className: 'woocommerce-homescreen-card',
|
||||||
id: 'reviews-panel',
|
id: 'reviews-panel',
|
||||||
|
|
|
@ -33,6 +33,30 @@ describe( 'ActivityPanel', () => {
|
||||||
publishedProductCount: 0,
|
publishedProductCount: 0,
|
||||||
manageStock: 'yes',
|
manageStock: 'yes',
|
||||||
reviewsEnabled: 'yes',
|
reviewsEnabled: 'yes',
|
||||||
|
isTaskListHidden: 'yes',
|
||||||
|
} );
|
||||||
|
|
||||||
|
expect( panels ).toEqual(
|
||||||
|
expect.not.arrayContaining( [
|
||||||
|
expect.objectContaining( { id: 'reviews-panel' } ),
|
||||||
|
] )
|
||||||
|
);
|
||||||
|
expect( panels ).toEqual(
|
||||||
|
expect.not.arrayContaining( [
|
||||||
|
expect.objectContaining( { id: 'stock-panel' } ),
|
||||||
|
] )
|
||||||
|
);
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should exclude the reviews and stock panels when the setup task list is visible', () => {
|
||||||
|
const panels = getAllPanels( {
|
||||||
|
countUnreadOrders: 0,
|
||||||
|
orderStatuses: [],
|
||||||
|
totalOrderCount: 1, // Yes, I realize this isn't "possible".
|
||||||
|
publishedProductCount: 0,
|
||||||
|
manageStock: 'yes',
|
||||||
|
reviewsEnabled: 'yes',
|
||||||
|
isTaskListHidden: 'no',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
expect( panels ).toEqual(
|
expect( panels ).toEqual(
|
||||||
|
@ -68,6 +92,7 @@ describe( 'ActivityPanel', () => {
|
||||||
totalOrderCount: 10,
|
totalOrderCount: 10,
|
||||||
publishedProductCount: 2,
|
publishedProductCount: 2,
|
||||||
manageStock: 'yes',
|
manageStock: 'yes',
|
||||||
|
isTaskListHidden: 'yes',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
expect( panels ).toEqual(
|
expect( panels ).toEqual(
|
||||||
|
@ -81,6 +106,7 @@ describe( 'ActivityPanel', () => {
|
||||||
const panels = getAllPanels( {
|
const panels = getAllPanels( {
|
||||||
publishedProductCount: 5,
|
publishedProductCount: 5,
|
||||||
reviewsEnabled: 'yes',
|
reviewsEnabled: 'yes',
|
||||||
|
isTaskListHidden: 'yes',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
expect( panels ).toEqual(
|
expect( panels ).toEqual(
|
||||||
|
|
|
@ -25,6 +25,11 @@ jest.mock( '@woocommerce/data', () => ( {
|
||||||
useUserPreferences: jest.fn().mockReturnValue( {} ),
|
useUserPreferences: jest.fn().mockReturnValue( {} ),
|
||||||
} ) );
|
} ) );
|
||||||
|
|
||||||
|
// We aren't testing the <ActivityPanel /> component here.
|
||||||
|
jest.mock( '../activity-panel', () => ( {
|
||||||
|
ActivityPanel: jest.fn().mockReturnValue( '[ActivityPanel]' ),
|
||||||
|
} ) );
|
||||||
|
|
||||||
describe( 'Homescreen Layout', () => {
|
describe( 'Homescreen Layout', () => {
|
||||||
it( 'should show TaskList placeholder when loading', () => {
|
it( 'should show TaskList placeholder when loading', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
|
@ -42,7 +47,7 @@ describe( 'Homescreen Layout', () => {
|
||||||
expect( placeholder ).not.toBeNull();
|
expect( placeholder ).not.toBeNull();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
it( 'should show TaskList inline', async () => {
|
it( 'should show TaskList inline', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<Layout
|
<Layout
|
||||||
requestingTaskList={ false }
|
requestingTaskList={ false }
|
||||||
|
@ -59,11 +64,11 @@ describe( 'Homescreen Layout', () => {
|
||||||
expect( columns ).not.toBeNull();
|
expect( columns ).not.toBeNull();
|
||||||
|
|
||||||
// Expect that the <TaskList /> is there too.
|
// Expect that the <TaskList /> is there too.
|
||||||
const taskList = await screen.findByText( '[TaskList]' );
|
const taskList = screen.queryByText( '[TaskList]' );
|
||||||
expect( taskList ).toBeDefined();
|
expect( taskList ).toBeDefined();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
it( 'should render TaskList alone when on task', async () => {
|
it( 'should render TaskList alone when on task', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<Layout
|
<Layout
|
||||||
requestingTaskList={ false }
|
requestingTaskList={ false }
|
||||||
|
@ -82,7 +87,7 @@ describe( 'Homescreen Layout', () => {
|
||||||
expect( columns ).toBeNull();
|
expect( columns ).toBeNull();
|
||||||
|
|
||||||
// Expect that the <TaskList /> is there though.
|
// Expect that the <TaskList /> is there though.
|
||||||
const taskList = await screen.findByText( '[TaskList]' );
|
const taskList = screen.queryByText( '[TaskList]' );
|
||||||
expect( taskList ).toBeDefined();
|
expect( taskList ).toBeDefined();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue