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-01-27 21:40:27 +00:00
|
|
|
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
|
2021-03-16 00:34:20 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
import { useEffect } from '@wordpress/element';
|
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-01-27 21:40:27 +00:00
|
|
|
const { getOption } = select( OPTIONS_STORE_NAME );
|
|
|
|
const isTaskListHidden = getOption( 'woocommerce_task_list_hidden' );
|
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,
|
2021-01-27 21:40:27 +00:00
|
|
|
isTaskListHidden,
|
2020-11-25 18:51:15 +00:00
|
|
|
manageStock,
|
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( () => {
|
|
|
|
const visiblePanels = panels.reduce(
|
|
|
|
( acc, panel ) => {
|
|
|
|
acc[ panel.id ] = true;
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{ taskList: panelsData.isTaskListHidden !== 'yes' }
|
|
|
|
);
|
|
|
|
recordEvent( 'activity_panel_visible_panels', visiblePanels );
|
|
|
|
}, [ 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={ [
|
|
|
|
<Text key={ title } variant="title.small">
|
|
|
|
{ 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 }
|
|
|
|
>
|
|
|
|
<Text variant="title.small">{ title }</Text>
|
|
|
|
{ count !== null && <Badge count={ count } /> }
|
|
|
|
</Button>
|
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</Panel>
|
2020-11-06 01:21:05 +00:00
|
|
|
);
|
|
|
|
};
|