2018-05-18 17:31:08 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-04-27 14:41:26 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import { withSelect } from '@wordpress/data';
|
2019-07-05 08:15:49 +00:00
|
|
|
import { Component } from '@wordpress/element';
|
2018-06-26 14:59:35 +00:00
|
|
|
import { Router, Route, Switch } from 'react-router-dom';
|
2018-06-26 14:49:42 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-07-05 08:15:49 +00:00
|
|
|
import { get, isFunction } from 'lodash';
|
2018-05-18 17:31:08 +00:00
|
|
|
|
2018-11-05 21:02:04 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2020-04-27 14:41:26 +00:00
|
|
|
import { useFilters } from '@woocommerce/components';
|
2019-02-06 19:28:29 +00:00
|
|
|
import { getHistory } from '@woocommerce/navigation';
|
2019-10-07 11:51:25 +00:00
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
2020-04-27 14:41:26 +00:00
|
|
|
import { PLUGINS_STORE_NAME, withPluginsHydration } from '@woocommerce/data';
|
2018-11-05 21:02:04 +00:00
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2019-06-26 23:00:23 +00:00
|
|
|
import { Controller, getPages, PAGES_FILTER } from './controller';
|
2018-09-21 15:19:05 +00:00
|
|
|
import Header from 'header';
|
2018-05-18 17:31:08 +00:00
|
|
|
import Notices from './notices';
|
2018-09-19 18:23:05 +00:00
|
|
|
import { recordPageView } from 'lib/tracks';
|
2019-02-13 11:44:58 +00:00
|
|
|
import TransientNotices from './transient-notices';
|
2019-02-19 21:07:19 +00:00
|
|
|
import StoreAlerts from './store-alerts';
|
2019-07-05 08:15:49 +00:00
|
|
|
import { REPORTS_FILTER } from 'analytics/report';
|
2018-05-18 17:31:08 +00:00
|
|
|
|
2019-05-22 17:53:30 +00:00
|
|
|
export class PrimaryLayout extends Component {
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
return (
|
2020-02-14 02:23:21 +00:00
|
|
|
<div
|
|
|
|
className="woocommerce-layout__primary"
|
|
|
|
id="woocommerce-layout__primary"
|
|
|
|
>
|
2019-05-22 17:53:30 +00:00
|
|
|
{ window.wcAdminFeatures[ 'store-alerts' ] && <StoreAlerts /> }
|
|
|
|
<Notices />
|
|
|
|
{ children }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 14:41:26 +00:00
|
|
|
class _Layout extends Component {
|
2018-09-19 18:23:05 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this.recordPageViewTrack();
|
2019-05-28 10:38:01 +00:00
|
|
|
document.body.classList.remove( 'woocommerce-admin-is-loading' );
|
2018-09-19 18:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate( prevProps ) {
|
|
|
|
const previousPath = get( prevProps, 'location.pathname' );
|
|
|
|
const currentPath = get( this.props, 'location.pathname' );
|
|
|
|
|
|
|
|
if ( ! previousPath || ! currentPath ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( previousPath !== currentPath ) {
|
|
|
|
this.recordPageViewTrack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
recordPageViewTrack() {
|
2020-04-27 14:41:26 +00:00
|
|
|
const {
|
|
|
|
activePlugins,
|
|
|
|
installedPlugins,
|
|
|
|
isEmbedded,
|
|
|
|
isJetpackConnected,
|
|
|
|
} = this.props;
|
|
|
|
|
2019-11-15 13:32:02 +00:00
|
|
|
if ( isEmbedded ) {
|
|
|
|
const path = document.location.pathname + document.location.search;
|
|
|
|
recordPageView( path, { isEmbedded } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-19 18:23:05 +00:00
|
|
|
const pathname = get( this.props, 'location.pathname' );
|
|
|
|
if ( ! pathname ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove leading slash, and camel case remaining pathname
|
|
|
|
let path = pathname.substring( 1 ).replace( /\//g, '_' );
|
|
|
|
|
|
|
|
// When pathname is `/` we are on the dashboard
|
|
|
|
if ( path.length === 0 ) {
|
2020-04-27 14:41:26 +00:00
|
|
|
path = window.wcAdminFeatures.homepage
|
|
|
|
? 'home_screen'
|
|
|
|
: 'dashboard';
|
2018-09-19 18:23:05 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 14:41:26 +00:00
|
|
|
recordPageView( path, {
|
|
|
|
jetpack_installed: installedPlugins.includes( 'jetpack' ),
|
|
|
|
jetpack_active: activePlugins.includes( 'jetpack' ),
|
|
|
|
jetpack_connected: isJetpackConnected,
|
|
|
|
} );
|
2018-09-19 18:23:05 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
render() {
|
2019-05-22 17:53:30 +00:00
|
|
|
const { isEmbedded, ...restProps } = this.props;
|
2019-07-05 08:15:49 +00:00
|
|
|
const { breadcrumbs } = this.props.page;
|
2020-03-13 04:34:53 +00:00
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
return (
|
2018-06-28 13:52:45 +00:00
|
|
|
<div className="woocommerce-layout">
|
2019-07-05 08:15:49 +00:00
|
|
|
<Header
|
2020-02-14 02:23:21 +00:00
|
|
|
sections={
|
|
|
|
isFunction( breadcrumbs )
|
|
|
|
? breadcrumbs( this.props )
|
|
|
|
: breadcrumbs
|
|
|
|
}
|
2019-07-05 08:15:49 +00:00
|
|
|
isEmbedded={ isEmbedded }
|
|
|
|
/>
|
2019-02-13 11:44:58 +00:00
|
|
|
<TransientNotices />
|
2019-05-22 17:53:30 +00:00
|
|
|
{ ! isEmbedded && (
|
|
|
|
<PrimaryLayout>
|
2018-06-26 14:49:42 +00:00
|
|
|
<div className="woocommerce-layout__main">
|
|
|
|
<Controller { ...restProps } />
|
|
|
|
</div>
|
2019-05-22 17:53:30 +00:00
|
|
|
</PrimaryLayout>
|
|
|
|
) }
|
2018-05-18 17:31:08 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 14:41:26 +00:00
|
|
|
_Layout.propTypes = {
|
2019-05-22 17:53:30 +00:00
|
|
|
isEmbedded: PropTypes.bool,
|
2019-07-05 08:15:49 +00:00
|
|
|
page: PropTypes.shape( {
|
2019-07-08 00:54:52 +00:00
|
|
|
container: PropTypes.func,
|
|
|
|
path: PropTypes.string,
|
2019-07-05 08:15:49 +00:00
|
|
|
breadcrumbs: PropTypes.oneOfType( [
|
|
|
|
PropTypes.func,
|
|
|
|
PropTypes.arrayOf(
|
2020-02-14 02:23:21 +00:00
|
|
|
PropTypes.oneOfType( [
|
|
|
|
PropTypes.arrayOf( PropTypes.string ),
|
|
|
|
PropTypes.string,
|
|
|
|
] )
|
2019-07-05 08:15:49 +00:00
|
|
|
),
|
|
|
|
] ).isRequired,
|
2019-07-08 00:54:52 +00:00
|
|
|
wpOpenMenu: PropTypes.string,
|
2019-07-05 08:15:49 +00:00
|
|
|
} ).isRequired,
|
2018-06-26 14:49:42 +00:00
|
|
|
};
|
|
|
|
|
2020-04-27 14:41:26 +00:00
|
|
|
const Layout = compose(
|
|
|
|
withPluginsHydration( {
|
|
|
|
...( window.wcSettings.plugins || {} ),
|
|
|
|
jetpackStatus:
|
|
|
|
window.wcSettings.dataEndpoints &&
|
|
|
|
window.wcSettings.dataEndpoints.jetpackStatus || false,
|
|
|
|
} ),
|
|
|
|
withSelect( ( select, { isEmbedded } ) => {
|
|
|
|
// Embedded pages don't send plugin info to Tracks.
|
|
|
|
if ( isEmbedded ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
getActivePlugins,
|
|
|
|
getInstalledPlugins,
|
|
|
|
isJetpackConnected,
|
|
|
|
} = select( PLUGINS_STORE_NAME );
|
|
|
|
|
|
|
|
return {
|
|
|
|
activePlugins: getActivePlugins(),
|
|
|
|
isJetpackConnected: isJetpackConnected(),
|
|
|
|
installedPlugins: getInstalledPlugins(),
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( _Layout );
|
|
|
|
|
2019-06-26 23:00:23 +00:00
|
|
|
class _PageLayout extends Component {
|
2018-05-18 17:31:08 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2019-02-06 19:28:29 +00:00
|
|
|
<Router history={ getHistory() }>
|
2018-05-18 17:31:08 +00:00
|
|
|
<Switch>
|
2020-02-14 02:23:21 +00:00
|
|
|
{ getPages().map( ( page ) => {
|
2019-06-13 19:58:21 +00:00
|
|
|
return (
|
|
|
|
<Route
|
|
|
|
key={ page.path }
|
|
|
|
path={ page.path }
|
|
|
|
exact
|
2020-02-14 02:23:21 +00:00
|
|
|
render={ ( props ) => (
|
2020-04-27 14:41:26 +00:00
|
|
|
<Layout
|
|
|
|
page={ page }
|
|
|
|
{ ...props }
|
|
|
|
/>
|
2020-02-14 02:23:21 +00:00
|
|
|
) }
|
2019-06-13 19:58:21 +00:00
|
|
|
/>
|
|
|
|
);
|
2018-05-18 17:31:08 +00:00
|
|
|
} ) }
|
|
|
|
</Switch>
|
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-07-05 08:15:49 +00:00
|
|
|
// Use the useFilters HoC so PageLayout is re-rendered when filters are used to add new pages or reports
|
2020-02-14 02:23:21 +00:00
|
|
|
export const PageLayout = useFilters( [ PAGES_FILTER, REPORTS_FILTER ] )(
|
|
|
|
_PageLayout
|
|
|
|
);
|
2018-06-26 14:49:42 +00:00
|
|
|
|
|
|
|
export class EmbedLayout extends Component {
|
|
|
|
render() {
|
|
|
|
return (
|
2019-07-05 08:15:49 +00:00
|
|
|
<Layout
|
|
|
|
page={ {
|
2019-10-07 11:51:25 +00:00
|
|
|
breadcrumbs: getSetting( 'embedBreadcrumbs', [] ),
|
2019-07-05 08:15:49 +00:00
|
|
|
} }
|
|
|
|
isEmbedded
|
|
|
|
/>
|
2018-06-26 14:49:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|