2018-05-18 17:31:08 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-04-16 13:29:54 +00:00
|
|
|
import { SlotFillProvider } from '@wordpress/components';
|
2020-04-27 14:41:26 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import { withSelect } from '@wordpress/data';
|
2020-04-29 18:01:27 +00:00
|
|
|
import { Component, lazy, Suspense } 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';
|
2020-06-10 23:49:27 +00:00
|
|
|
import { get, isFunction, identity } from 'lodash';
|
2020-07-14 12:20:51 +00:00
|
|
|
import { parse } from 'qs';
|
2020-08-20 23:14:55 +00:00
|
|
|
import { Spinner } from '@woocommerce/components';
|
2020-11-26 00:27:37 +00:00
|
|
|
import { getHistory, getQuery } from '@woocommerce/navigation';
|
2019-10-07 11:51:25 +00:00
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
2020-06-10 23:49:27 +00:00
|
|
|
import {
|
|
|
|
PLUGINS_STORE_NAME,
|
2021-02-19 13:57:17 +00:00
|
|
|
useUser,
|
2020-06-10 23:49:27 +00:00
|
|
|
withPluginsHydration,
|
|
|
|
withOptionsHydration,
|
|
|
|
} from '@woocommerce/data';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordPageView } from '@woocommerce/tracks';
|
2021-02-28 23:48:52 +00:00
|
|
|
import '@woocommerce/notices';
|
2021-04-23 03:44:54 +00:00
|
|
|
import { PluginArea } from '@wordpress/plugins';
|
2018-11-05 21:02:04 +00:00
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2020-08-20 23:14:55 +00:00
|
|
|
import { Controller, getPages } from './controller';
|
2020-08-23 22:46:18 +00:00
|
|
|
import { Header } from '../header';
|
2018-05-18 17:31:08 +00:00
|
|
|
import Notices from './notices';
|
2019-02-13 11:44:58 +00:00
|
|
|
import TransientNotices from './transient-notices';
|
2020-10-22 03:01:25 +00:00
|
|
|
import './navigation';
|
2020-08-13 02:05:22 +00:00
|
|
|
|
2020-04-29 18:01:27 +00:00
|
|
|
const StoreAlerts = lazy( () =>
|
|
|
|
import( /* webpackChunkName: "store-alerts" */ './store-alerts' )
|
|
|
|
);
|
2018-05-18 17:31:08 +00:00
|
|
|
|
2020-11-26 00:27:37 +00:00
|
|
|
const WCPayUsageModal = lazy( () =>
|
|
|
|
import(
|
2021-10-05 18:20:28 +00:00
|
|
|
/* webpackChunkName: "wcpay-usage-modal" */ '../tasks/fills/PaymentGatewaySuggestions/components/WCPay/UsageModal'
|
2020-11-26 00:27:37 +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"
|
|
|
|
>
|
2020-04-29 18:01:27 +00:00
|
|
|
{ window.wcAdminFeatures[ 'store-alerts' ] && (
|
|
|
|
<Suspense fallback={ <Spinner /> }>
|
|
|
|
<StoreAlerts />
|
|
|
|
</Suspense>
|
|
|
|
) }
|
2019-05-22 17:53:30 +00:00
|
|
|
<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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-10-22 22:13:57 +00:00
|
|
|
const navigationFlag = {
|
|
|
|
has_navigation: !! window.wcNavigation,
|
|
|
|
};
|
|
|
|
|
2019-11-15 13:32:02 +00:00
|
|
|
if ( isEmbedded ) {
|
|
|
|
const path = document.location.pathname + document.location.search;
|
2020-10-22 22:13:57 +00:00
|
|
|
recordPageView( path, {
|
|
|
|
is_embedded: true,
|
|
|
|
...navigationFlag,
|
|
|
|
} );
|
2019-11-15 13:32:02 +00:00
|
|
|
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, '_' );
|
|
|
|
|
2020-09-14 23:44:46 +00:00
|
|
|
// When pathname is `/` we are on the home screen.
|
2018-09-19 18:23:05 +00:00
|
|
|
if ( path.length === 0 ) {
|
2020-09-14 23:44:46 +00:00
|
|
|
path = 'home_screen';
|
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,
|
2020-10-22 22:13:57 +00:00
|
|
|
...navigationFlag,
|
2020-04-27 14:41:26 +00:00
|
|
|
} );
|
2018-09-19 18:23:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 12:20:51 +00:00
|
|
|
getQuery( searchString ) {
|
|
|
|
if ( ! searchString ) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const search = searchString.substring( 1 );
|
|
|
|
return parse( search );
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:27:37 +00:00
|
|
|
isWCPaySettingsPage() {
|
|
|
|
const { page, section, tab } = getQuery();
|
|
|
|
return (
|
|
|
|
page === 'wc-settings' &&
|
|
|
|
tab === 'checkout' &&
|
|
|
|
section === 'woocommerce_payments'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
render() {
|
2019-05-22 17:53:30 +00:00
|
|
|
const { isEmbedded, ...restProps } = this.props;
|
2020-07-14 12:20:51 +00:00
|
|
|
const { location, page } = this.props;
|
|
|
|
const { breadcrumbs } = page;
|
|
|
|
const query = this.getQuery( location && location.search );
|
2020-03-13 04:34:53 +00:00
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
return (
|
2021-04-16 13:29:54 +00:00
|
|
|
<SlotFillProvider>
|
|
|
|
<div className="woocommerce-layout">
|
|
|
|
<Header
|
|
|
|
sections={
|
|
|
|
isFunction( breadcrumbs )
|
|
|
|
? breadcrumbs( this.props )
|
|
|
|
: breadcrumbs
|
|
|
|
}
|
|
|
|
isEmbedded={ isEmbedded }
|
|
|
|
query={ query }
|
|
|
|
/>
|
|
|
|
<TransientNotices />
|
|
|
|
{ ! isEmbedded && (
|
|
|
|
<PrimaryLayout>
|
|
|
|
<div className="woocommerce-layout__main">
|
|
|
|
<Controller { ...restProps } query={ query } />
|
|
|
|
</div>
|
|
|
|
</PrimaryLayout>
|
|
|
|
) }
|
|
|
|
|
|
|
|
{ isEmbedded && this.isWCPaySettingsPage() && (
|
|
|
|
<Suspense fallback={ null }>
|
|
|
|
<WCPayUsageModal />
|
|
|
|
</Suspense>
|
|
|
|
) }
|
|
|
|
</div>
|
2021-04-23 03:44:54 +00:00
|
|
|
<PluginArea scope="woocommerce-admin" />
|
2021-09-15 16:42:54 +00:00
|
|
|
{ window.wcAdminFeatures.navigation && (
|
|
|
|
<PluginArea scope="woocommerce-navigation" />
|
|
|
|
) }
|
2021-10-05 18:20:28 +00:00
|
|
|
<PluginArea scope="woocommerce-tasks" />
|
2021-04-16 13:29:54 +00:00
|
|
|
</SlotFillProvider>
|
2018-05-18 17:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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( {
|
2020-04-29 18:01:27 +00:00
|
|
|
container: PropTypes.oneOfType( [
|
|
|
|
PropTypes.func,
|
|
|
|
PropTypes.object, // Support React.lazy
|
|
|
|
] ),
|
2019-07-08 00:54:52 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-08-24 11:39:48 +00:00
|
|
|
const dataEndpoints = getSetting( 'dataEndpoints' );
|
2020-04-27 14:41:26 +00:00
|
|
|
const Layout = compose(
|
|
|
|
withPluginsHydration( {
|
2021-08-24 11:39:48 +00:00
|
|
|
...getSetting( 'plugins', {} ),
|
2020-04-27 14:41:26 +00:00
|
|
|
jetpackStatus:
|
2021-08-24 11:39:48 +00:00
|
|
|
( dataEndpoints && dataEndpoints.jetpackStatus ) || false,
|
2020-04-27 14:41:26 +00:00
|
|
|
} ),
|
|
|
|
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 );
|
|
|
|
|
2021-02-19 13:57:17 +00:00
|
|
|
const _PageLayout = () => {
|
|
|
|
const { currentUserCan } = useUser();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Router history={ getHistory() }>
|
|
|
|
<Switch>
|
|
|
|
{ getPages()
|
|
|
|
.filter(
|
|
|
|
( page ) =>
|
|
|
|
! page.capability ||
|
|
|
|
currentUserCan( page.capability )
|
|
|
|
)
|
|
|
|
.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-06-11 00:26:20 +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
|
|
|
} ) }
|
2021-02-19 13:57:17 +00:00
|
|
|
</Switch>
|
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
};
|
2020-06-03 20:42:30 +00:00
|
|
|
|
|
|
|
export const PageLayout = compose(
|
2021-08-24 11:39:48 +00:00
|
|
|
window.wcSettings.admin
|
2020-06-10 23:49:27 +00:00
|
|
|
? withOptionsHydration( {
|
2021-08-24 11:39:48 +00:00
|
|
|
...getSetting( 'preloadOptions', {} ),
|
2020-06-10 23:49:27 +00:00
|
|
|
} )
|
2020-06-11 00:26:20 +00:00
|
|
|
: identity
|
2020-06-03 20:42:30 +00:00
|
|
|
)( _PageLayout );
|
2018-06-26 14:49:42 +00:00
|
|
|
|
2020-10-13 00:05:06 +00:00
|
|
|
const _EmbedLayout = () => (
|
|
|
|
<Layout
|
|
|
|
page={ {
|
|
|
|
breadcrumbs: getSetting( 'embedBreadcrumbs', [] ),
|
|
|
|
} }
|
|
|
|
isEmbedded
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
export const EmbedLayout = compose(
|
2021-08-24 11:39:48 +00:00
|
|
|
getSetting( 'preloadOptions' )
|
2020-10-13 00:05:06 +00:00
|
|
|
? withOptionsHydration( {
|
2021-08-24 11:39:48 +00:00
|
|
|
...getSetting( 'preloadOptions' ),
|
2020-10-13 00:05:06 +00:00
|
|
|
} )
|
|
|
|
: identity
|
|
|
|
)( _EmbedLayout );
|