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
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2018-06-28 13:52:45 +00:00
|
|
|
import Header from 'layout/header';
|
2018-05-18 17:31:08 +00:00
|
|
|
import { Controller, getPages } from './controller';
|
2018-06-26 14:59:35 +00:00
|
|
|
import history from 'lib/history';
|
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';
|
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">
|
|
|
|
<Slot name="header" />
|
|
|
|
|
2018-06-04 14:25:41 +00:00
|
|
|
<div className="woocommerce-layout__primary" id="woocommerce-layout__primary">
|
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 (
|
2018-06-26 14:59:35 +00:00
|
|
|
<Router history={ history }>
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|