/** @format */
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import classnames from 'classnames';
import clickOutside from 'react-click-outside';
import { Component } from '@wordpress/element';
import Gridicon from 'gridicons';
import { IconButton, NavigableMenu } from '@wordpress/components';
import { partial, uniqueId, find } from 'lodash';
/**
* Internal dependencies
*/
import './style.scss';
import ActivityPanelToggleBubble from './toggle-bubble';
import { H, Section } from '@woocommerce/components';
import InboxPanel from './panels/inbox';
import OrdersPanel from './panels/orders';
import StockPanel from './panels/stock';
import ReviewsPanel from './panels/reviews';
import WordPressNotices from './wordpress-notices';
class ActivityPanel extends Component {
constructor() {
super( ...arguments );
this.togglePanel = this.togglePanel.bind( this );
this.toggleMobile = this.toggleMobile.bind( this );
this.renderTab = this.renderTab.bind( this );
this.updateNoticeFlag = this.updateNoticeFlag.bind( this );
this.state = {
isPanelOpen: false,
mobileOpen: false,
currentTab: '',
hasWordPressNotices: false,
};
}
togglePanel( tabName ) {
// The WordPress Notices tab is handled differently, since they are displayed inline, so the panel should be closed,
// Close behavior of the expanded notices is based on current tab.
if ( 'wpnotices' === tabName ) {
this.setState( state => ( {
currentTab: 'wpnotices' === state.currentTab ? '' : tabName,
mobileOpen: 'wpnotices' !== state.currentTab,
isPanelOpen: false,
} ) );
return;
}
this.setState( state => {
if (
tabName === state.currentTab ||
'' === state.currentTab ||
'wpnotices' === state.currentTab
) {
return {
isPanelOpen: ! state.isPanelOpen,
currentTab: state.isPanelOpen ? '' : tabName,
mobileOpen: ! state.isPanelOpen,
};
}
return { currentTab: tabName };
} );
}
// On smaller screen, the panel buttons are hidden behind a toggle.
toggleMobile() {
const tabs = this.getTabs();
this.setState( state => ( {
mobileOpen: ! state.mobileOpen,
currentTab: state.mobileOpen ? '' : tabs[ 0 ].name,
isPanelOpen: ! state.mobileOpen,
} ) );
}
handleClickOutside() {
const { isPanelOpen, currentTab } = this.state;
if ( isPanelOpen ) {
this.togglePanel( currentTab );
}
}
updateNoticeFlag( noticeCount ) {
this.setState( {
hasWordPressNotices: noticeCount > 0,
} );
}
// @todo Pull in dynamic unread status/count
getTabs() {
return [
{
name: 'inbox',
title: __( 'Inbox', 'wc-admin' ),
icon: