2020-11-06 01:21:05 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useSelect } from '@wordpress/data';
|
2021-01-12 21:18:51 +00:00
|
|
|
import { Badge } from '@woocommerce/components';
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Panel,
|
|
|
|
PanelBody,
|
|
|
|
PanelRow,
|
|
|
|
__experimentalText as Text,
|
|
|
|
} from '@wordpress/components';
|
2020-11-23 15:06:55 +00:00
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
2021-10-04 17:02:01 +00:00
|
|
|
import { ONBOARDING_STORE_NAME } from '@woocommerce/data';
|
2021-03-16 00:34:20 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
import { useEffect } from '@wordpress/element';
|
2021-09-23 13:39:44 +00:00
|
|
|
import { snakeCase } from 'lodash';
|
2020-11-06 01:21:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2020-11-25 18:51:15 +00:00
|
|
|
import {
|
|
|
|
getLowStockCount,
|
|
|
|
getOrderStatuses,
|
|
|
|
getUnreadOrders,
|
|
|
|
} from './orders/utils';
|
2020-11-06 01:21:05 +00:00
|
|
|
import { getAllPanels } from './panels';
|
2020-12-02 13:30:39 +00:00
|
|
|
import { getUnapprovedReviews } from './reviews/utils';
|
2021-06-09 13:56:45 +00:00
|
|
|
import { getUrlParams } from '../../utils';
|
2020-11-06 01:21:05 +00:00
|
|
|
|
|
|
|
export const ActivityPanel = () => {
|
2020-12-01 12:44:54 +00:00
|
|
|
const panelsData = useSelect( ( select ) => {
|
2020-11-23 15:06:55 +00:00
|
|
|
const totalOrderCount = getSetting( 'orderCount', 0 );
|
2020-11-06 16:50:24 +00:00
|
|
|
const orderStatuses = getOrderStatuses( select );
|
2020-12-02 13:30:39 +00:00
|
|
|
const reviewsEnabled = getSetting( 'reviewsEnabled', 'no' );
|
2020-11-06 16:50:24 +00:00
|
|
|
const countUnreadOrders = getUnreadOrders( select, orderStatuses );
|
2020-11-25 18:51:15 +00:00
|
|
|
const manageStock = getSetting( 'manageStock', 'no' );
|
|
|
|
const countLowStockProducts = getLowStockCount( select );
|
2020-12-02 13:30:39 +00:00
|
|
|
const countUnapprovedReviews = getUnapprovedReviews( select );
|
2020-12-29 16:19:13 +00:00
|
|
|
const publishedProductCount = getSetting( 'publishedProductCount', 0 );
|
2021-10-04 17:02:01 +00:00
|
|
|
const taskLists = select( ONBOARDING_STORE_NAME ).getTaskLists();
|
|
|
|
|
2020-12-01 12:44:54 +00:00
|
|
|
return {
|
2020-11-25 18:51:15 +00:00
|
|
|
countLowStockProducts,
|
2021-01-27 21:40:27 +00:00
|
|
|
countUnapprovedReviews,
|
2020-11-23 15:06:55 +00:00
|
|
|
countUnreadOrders,
|
2020-11-25 18:51:15 +00:00
|
|
|
manageStock,
|
2021-10-04 17:02:01 +00:00
|
|
|
isTaskListHidden: Boolean( taskLists.length )
|
|
|
|
? ! taskLists.find( ( list ) => list.id === 'setup' ).isVisible
|
|
|
|
: null,
|
2020-12-29 16:19:13 +00:00
|
|
|
publishedProductCount,
|
2021-01-27 21:40:27 +00:00
|
|
|
reviewsEnabled,
|
|
|
|
totalOrderCount,
|
|
|
|
orderStatuses,
|
2020-12-01 12:44:54 +00:00
|
|
|
};
|
2020-11-06 01:21:05 +00:00
|
|
|
} );
|
2020-12-01 12:44:54 +00:00
|
|
|
|
|
|
|
const panels = getAllPanels( panelsData );
|
|
|
|
|
2021-03-16 00:34:20 +00:00
|
|
|
useEffect( () => {
|
2021-09-23 13:39:44 +00:00
|
|
|
if ( panelsData.isTaskListHidden !== undefined ) {
|
|
|
|
const visiblePanels = panels.reduce(
|
|
|
|
( acc, panel ) => {
|
|
|
|
const panelId = snakeCase( panel.id );
|
|
|
|
acc[ panelId ] = true;
|
|
|
|
return acc;
|
|
|
|
},
|
2021-10-04 17:02:01 +00:00
|
|
|
{ task_list: ! panelsData.isTaskListHidden }
|
2021-09-23 13:39:44 +00:00
|
|
|
);
|
|
|
|
recordEvent( 'activity_panel_visible_panels', visiblePanels );
|
|
|
|
}
|
2021-03-16 00:34:20 +00:00
|
|
|
}, [ panelsData.isTaskListHidden ] );
|
|
|
|
|
2020-12-29 16:19:13 +00:00
|
|
|
if ( panels.length === 0 ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-09 13:56:45 +00:00
|
|
|
const getInitialOpenState = ( panelId ) => {
|
|
|
|
const { opened_panel: openedPanel } = getUrlParams(
|
|
|
|
window.location.search
|
|
|
|
);
|
|
|
|
return panelId === openedPanel;
|
|
|
|
};
|
|
|
|
|
2020-11-06 01:21:05 +00:00
|
|
|
return (
|
2021-01-12 21:18:51 +00:00
|
|
|
<Panel className="woocommerce-activity-panel">
|
|
|
|
{ panels.map( ( panelData ) => {
|
|
|
|
const {
|
|
|
|
className,
|
|
|
|
count,
|
|
|
|
id,
|
|
|
|
initialOpen,
|
|
|
|
panel,
|
|
|
|
title,
|
|
|
|
collapsible,
|
|
|
|
} = panelData;
|
|
|
|
return collapsible ? (
|
|
|
|
<PanelBody
|
|
|
|
title={ [
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text
|
|
|
|
key={ title }
|
|
|
|
variant="title.small"
|
|
|
|
size="20"
|
|
|
|
lineHeight="28px"
|
|
|
|
>
|
2021-01-12 21:18:51 +00:00
|
|
|
{ title }
|
|
|
|
</Text>,
|
2021-01-14 22:04:16 +00:00
|
|
|
count !== null && (
|
|
|
|
<Badge
|
|
|
|
key={ `${ title }-badge` }
|
|
|
|
count={ count }
|
|
|
|
/>
|
|
|
|
),
|
2021-01-12 21:18:51 +00:00
|
|
|
] }
|
|
|
|
key={ id }
|
|
|
|
className={ className }
|
2021-06-09 13:56:45 +00:00
|
|
|
initialOpen={ getInitialOpenState( id ) || initialOpen }
|
2021-01-12 21:18:51 +00:00
|
|
|
collapsible={ collapsible }
|
|
|
|
disabled={ ! collapsible }
|
2021-03-16 00:34:20 +00:00
|
|
|
onToggle={ ( isOpen ) => {
|
|
|
|
if ( ! isOpen ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
recordEvent( 'activity_panel_open', {
|
|
|
|
tab: id,
|
|
|
|
} );
|
|
|
|
} }
|
2021-01-12 21:18:51 +00:00
|
|
|
>
|
|
|
|
<PanelRow>{ panel }</PanelRow>
|
|
|
|
</PanelBody>
|
|
|
|
) : (
|
2021-01-14 22:04:16 +00:00
|
|
|
<div className="components-panel__body" key={ id }>
|
2021-01-12 21:18:51 +00:00
|
|
|
<h2 className="components-panel__body-title">
|
|
|
|
<Button
|
|
|
|
className="components-panel__body-toggle"
|
|
|
|
aria-expanded={ false }
|
|
|
|
disabled={ true }
|
|
|
|
>
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text
|
|
|
|
variant="title.small"
|
|
|
|
size="20"
|
|
|
|
lineHeight="28px"
|
|
|
|
>
|
|
|
|
{ title }
|
|
|
|
</Text>
|
2021-01-12 21:18:51 +00:00
|
|
|
{ count !== null && <Badge count={ count } /> }
|
|
|
|
</Button>
|
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</Panel>
|
2020-11-06 01:21:05 +00:00
|
|
|
);
|
|
|
|
};
|