2018-05-18 17:31:08 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2018-06-26 14:49:42 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2018-06-26 14:59:35 +00:00
|
|
|
import { Router, Route, Switch } from 'react-router-dom';
|
2018-05-18 17:31:08 +00:00
|
|
|
import { Slot } from 'react-slot-fill';
|
2018-06-26 14:49:42 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-09-19 18:23:05 +00:00
|
|
|
import { get } from 'lodash';
|
2018-05-18 17:31:08 +00:00
|
|
|
|
2018-11-05 21:02:04 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2019-02-06 19:28:29 +00:00
|
|
|
import { getHistory } from '@woocommerce/navigation';
|
2018-11-05 21:02:04 +00:00
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
import { Controller, getPages } 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';
|
2018-05-18 17:31:08 +00:00
|
|
|
|
|
|
|
class Layout extends Component {
|
2018-09-19 18:23:05 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this.recordPageViewTrack();
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
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 ) {
|
|
|
|
path = 'dashboard';
|
|
|
|
}
|
|
|
|
|
|
|
|
recordPageView( path );
|
|
|
|
}
|
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
render() {
|
2018-06-26 14:49:42 +00:00
|
|
|
const { isEmbeded, ...restProps } = this.props;
|
2018-05-18 17:31:08 +00:00
|
|
|
return (
|
2018-06-28 13:52:45 +00:00
|
|
|
<div className="woocommerce-layout">
|
2019-02-12 20:02:02 +00:00
|
|
|
{ window.wcAdminFeatures[ 'activity-panels' ] && <Slot name="header" /> }
|
2019-02-13 11:44:58 +00:00
|
|
|
<TransientNotices />
|
|
|
|
|
2018-06-04 14:25:41 +00:00
|
|
|
<div className="woocommerce-layout__primary" id="woocommerce-layout__primary">
|
2019-02-21 00:41:00 +00:00
|
|
|
{ window.wcAdminFeatures[ 'store-alerts' ] && <StoreAlerts /> }
|
2019-02-19 21:07:19 +00:00
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
<Notices />
|
2018-06-26 14:49:42 +00:00
|
|
|
{ ! isEmbeded && (
|
|
|
|
<div className="woocommerce-layout__main">
|
|
|
|
<Controller { ...restProps } />
|
|
|
|
</div>
|
|
|
|
) }
|
2018-05-18 17:31:08 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 14:49:42 +00:00
|
|
|
Layout.propTypes = {
|
|
|
|
isEmbededLayout: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
export 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>
|
|
|
|
{ getPages().map( page => {
|
|
|
|
return <Route key={ page.path } path={ page.path } exact component={ Layout } />;
|
|
|
|
} ) }
|
|
|
|
<Route component={ Layout } />
|
|
|
|
</Switch>
|
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-06-26 14:49:42 +00:00
|
|
|
|
|
|
|
export class EmbedLayout extends Component {
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<Header sections={ wcSettings.embedBreadcrumbs } isEmbedded />
|
|
|
|
<Layout isEmbeded />
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|