2018-05-18 17:31:08 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-05-30 06:51:33 +00:00
|
|
|
import { Suspense, lazy } from '@wordpress/element';
|
|
|
|
import { useRef, useEffect } from 'react';
|
2023-06-05 07:55:20 +00:00
|
|
|
import { parse, stringify } from 'qs';
|
2019-07-11 17:22:26 +00:00
|
|
|
import { find, isEqual, last, omit } from 'lodash';
|
2019-05-14 03:58:37 +00:00
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
2019-07-05 08:15:49 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-02-14 02:23:21 +00:00
|
|
|
import {
|
|
|
|
getNewPath,
|
|
|
|
getPersistedQuery,
|
|
|
|
getHistory,
|
2021-01-07 16:53:31 +00:00
|
|
|
getQueryExcludedScreens,
|
|
|
|
getScreenFromPath,
|
2022-06-01 17:10:20 +00:00
|
|
|
isWCAdmin,
|
2020-02-14 02:23:21 +00:00
|
|
|
} from '@woocommerce/navigation';
|
2020-04-29 18:01:27 +00:00
|
|
|
import { Spinner } from '@woocommerce/components';
|
2018-11-05 21:02:04 +00:00
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
/**
|
2018-10-18 04:37:28 +00:00
|
|
|
* Internal dependencies
|
2018-05-18 17:31:08 +00:00
|
|
|
*/
|
2020-08-13 02:05:22 +00:00
|
|
|
import getReports from '../analytics/report/get-reports';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2023-05-19 16:53:55 +00:00
|
|
|
import { isFeatureEnabled } from '~/utils/features';
|
2021-10-14 14:04:17 +00:00
|
|
|
import { NoMatch } from './NoMatch';
|
2020-06-03 20:42:30 +00:00
|
|
|
|
2023-05-19 16:53:55 +00:00
|
|
|
const AddProductPage = lazy( () =>
|
2022-08-11 14:04:14 +00:00
|
|
|
import(
|
2023-05-19 16:53:55 +00:00
|
|
|
/* webpackChunkName: "edit-product-page" */ '../products/add-product-page'
|
2022-08-11 14:04:14 +00:00
|
|
|
)
|
|
|
|
);
|
2023-05-19 16:53:55 +00:00
|
|
|
const EditProductPage = lazy( () =>
|
2022-08-04 13:15:30 +00:00
|
|
|
import(
|
2023-05-19 16:53:55 +00:00
|
|
|
/* webpackChunkName: "edit-product-page" */ '../products/edit-product-page'
|
2022-08-04 13:15:30 +00:00
|
|
|
)
|
|
|
|
);
|
2023-03-08 09:51:59 +00:00
|
|
|
const ProductPage = lazy( () =>
|
|
|
|
import( /* webpackChunkName: "product-page" */ '../products/product-page' )
|
|
|
|
);
|
2020-04-29 18:01:27 +00:00
|
|
|
const AnalyticsReport = lazy( () =>
|
2020-08-13 02:05:22 +00:00
|
|
|
import( /* webpackChunkName: "analytics-report" */ '../analytics/report' )
|
2020-04-29 18:01:27 +00:00
|
|
|
);
|
|
|
|
const AnalyticsSettings = lazy( () =>
|
2020-08-13 02:05:22 +00:00
|
|
|
import(
|
|
|
|
/* webpackChunkName: "analytics-settings" */ '../analytics/settings'
|
|
|
|
)
|
2020-04-29 18:01:27 +00:00
|
|
|
);
|
|
|
|
const Dashboard = lazy( () =>
|
2020-08-13 02:05:22 +00:00
|
|
|
import( /* webpackChunkName: "dashboard" */ '../dashboard' )
|
2020-04-29 18:01:27 +00:00
|
|
|
);
|
2020-06-15 02:17:12 +00:00
|
|
|
const Homescreen = lazy( () =>
|
2020-08-13 02:05:22 +00:00
|
|
|
import( /* webpackChunkName: "homescreen" */ '../homescreen' )
|
2020-04-29 18:01:27 +00:00
|
|
|
);
|
2022-09-14 07:43:30 +00:00
|
|
|
const MarketingOverviewMultichannel = lazy( () =>
|
|
|
|
import(
|
|
|
|
/* webpackChunkName: "multichannel-marketing" */ '../marketing/overview-multichannel'
|
|
|
|
)
|
|
|
|
);
|
2020-07-16 15:17:10 +00:00
|
|
|
const ProfileWizard = lazy( () =>
|
2020-08-13 02:05:22 +00:00
|
|
|
import( /* webpackChunkName: "profile-wizard" */ '../profile-wizard' )
|
2020-07-16 15:17:10 +00:00
|
|
|
);
|
2023-04-24 02:08:24 +00:00
|
|
|
|
|
|
|
const CoreProfiler = lazy( () =>
|
|
|
|
import( /* webpackChunkName: "core-profiler" */ '../core-profiler' )
|
|
|
|
);
|
|
|
|
|
2021-02-12 19:32:42 +00:00
|
|
|
const SettingsGroup = lazy( () =>
|
|
|
|
import( /* webpackChunkName: "profile-wizard" */ '../settings' )
|
|
|
|
);
|
2022-01-12 06:46:33 +00:00
|
|
|
const WCPaymentsWelcomePage = lazy( () =>
|
|
|
|
import(
|
|
|
|
/* webpackChunkName: "wcpay-payment-welcome-page" */ '../payments-welcome'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-06-26 23:00:23 +00:00
|
|
|
export const PAGES_FILTER = 'woocommerce_admin_pages_list';
|
|
|
|
|
2020-06-11 00:26:20 +00:00
|
|
|
export const getPages = () => {
|
2019-02-12 20:02:02 +00:00
|
|
|
const pages = [];
|
2021-08-24 11:39:48 +00:00
|
|
|
const initialBreadcrumbs = [
|
2022-01-06 12:53:30 +00:00
|
|
|
[ '', getAdminSetting( 'woocommerceTranslation' ) ],
|
2021-08-24 11:39:48 +00:00
|
|
|
];
|
2019-02-12 20:02:02 +00:00
|
|
|
|
2020-09-14 23:44:46 +00:00
|
|
|
pages.push( {
|
|
|
|
container: Homescreen,
|
|
|
|
path: '/',
|
2022-03-30 09:00:04 +00:00
|
|
|
breadcrumbs: [ ...initialBreadcrumbs, __( 'Home', 'woocommerce' ) ],
|
2020-09-14 23:44:46 +00:00
|
|
|
wpOpenMenu: 'toplevel_page_woocommerce',
|
2020-12-02 22:56:24 +00:00
|
|
|
navArgs: {
|
|
|
|
id: 'woocommerce-home',
|
|
|
|
},
|
2021-02-19 13:57:17 +00:00
|
|
|
capability: 'manage_woocommerce',
|
2020-09-14 23:44:46 +00:00
|
|
|
} );
|
2019-02-12 20:02:02 +00:00
|
|
|
|
2020-09-14 23:44:46 +00:00
|
|
|
if ( window.wcAdminFeatures.analytics ) {
|
2020-04-22 21:32:44 +00:00
|
|
|
pages.push( {
|
2020-09-14 23:44:46 +00:00
|
|
|
container: Dashboard,
|
|
|
|
path: '/analytics/overview',
|
2020-04-22 21:32:44 +00:00
|
|
|
breadcrumbs: [
|
|
|
|
...initialBreadcrumbs,
|
2022-03-30 09:00:04 +00:00
|
|
|
[ '/analytics/overview', __( 'Analytics', 'woocommerce' ) ],
|
|
|
|
__( 'Overview', 'woocommerce' ),
|
2020-04-22 21:32:44 +00:00
|
|
|
],
|
2020-09-14 23:44:46 +00:00
|
|
|
wpOpenMenu: 'toplevel_page_wc-admin-path--analytics-overview',
|
2020-12-02 22:56:24 +00:00
|
|
|
navArgs: {
|
|
|
|
id: 'woocommerce-analytics-overview',
|
|
|
|
},
|
2021-02-19 13:57:17 +00:00
|
|
|
capability: 'view_woocommerce_reports',
|
2020-04-22 21:32:44 +00:00
|
|
|
} );
|
2019-02-12 20:02:02 +00:00
|
|
|
pages.push( {
|
2019-01-31 01:04:11 +00:00
|
|
|
container: AnalyticsSettings,
|
|
|
|
path: '/analytics/settings',
|
2019-07-05 08:15:49 +00:00
|
|
|
breadcrumbs: [
|
2020-03-23 22:57:16 +00:00
|
|
|
...initialBreadcrumbs,
|
2022-03-30 09:00:04 +00:00
|
|
|
[ '/analytics/revenue', __( 'Analytics', 'woocommerce' ) ],
|
|
|
|
__( 'Settings', 'woocommerce' ),
|
2019-07-05 08:15:49 +00:00
|
|
|
],
|
2020-09-14 23:44:46 +00:00
|
|
|
wpOpenMenu: 'toplevel_page_wc-admin-path--analytics-overview',
|
2020-12-02 22:56:24 +00:00
|
|
|
navArgs: {
|
|
|
|
id: 'woocommerce-analytics-settings',
|
|
|
|
},
|
2021-02-19 13:57:17 +00:00
|
|
|
capability: 'view_woocommerce_reports',
|
2019-02-12 20:02:02 +00:00
|
|
|
} );
|
2020-02-20 11:59:02 +00:00
|
|
|
pages.push( {
|
|
|
|
container: AnalyticsReport,
|
|
|
|
path: '/customers',
|
2020-03-23 22:57:16 +00:00
|
|
|
breadcrumbs: [
|
|
|
|
...initialBreadcrumbs,
|
2022-03-30 09:00:04 +00:00
|
|
|
__( 'Customers', 'woocommerce' ),
|
2020-03-23 22:57:16 +00:00
|
|
|
],
|
2020-02-20 11:59:02 +00:00
|
|
|
wpOpenMenu: 'toplevel_page_woocommerce',
|
2020-12-02 22:56:24 +00:00
|
|
|
navArgs: {
|
|
|
|
id: 'woocommerce-analytics-customers',
|
|
|
|
},
|
2021-02-19 13:57:17 +00:00
|
|
|
capability: 'view_woocommerce_reports',
|
2020-02-20 11:59:02 +00:00
|
|
|
} );
|
2019-02-12 20:02:02 +00:00
|
|
|
pages.push( {
|
2018-05-18 17:31:08 +00:00
|
|
|
container: AnalyticsReport,
|
|
|
|
path: '/analytics/:report',
|
2019-07-05 08:15:49 +00:00
|
|
|
breadcrumbs: ( { match } ) => {
|
2020-02-14 02:23:21 +00:00
|
|
|
const report = find( getReports(), {
|
|
|
|
report: match.params.report,
|
|
|
|
} );
|
2019-07-05 08:15:49 +00:00
|
|
|
if ( ! report ) {
|
|
|
|
return [];
|
|
|
|
}
|
2020-02-14 02:23:21 +00:00
|
|
|
return [
|
2020-03-23 22:57:16 +00:00
|
|
|
...initialBreadcrumbs,
|
2022-03-30 09:00:04 +00:00
|
|
|
[ '/analytics/revenue', __( 'Analytics', 'woocommerce' ) ],
|
2020-02-14 02:23:21 +00:00
|
|
|
report.title,
|
|
|
|
];
|
2019-07-05 08:15:49 +00:00
|
|
|
},
|
2020-09-14 23:44:46 +00:00
|
|
|
wpOpenMenu: 'toplevel_page_wc-admin-path--analytics-overview',
|
2021-02-19 13:57:17 +00:00
|
|
|
capability: 'view_woocommerce_reports',
|
2019-02-12 20:02:02 +00:00
|
|
|
} );
|
|
|
|
}
|
2018-05-18 17:31:08 +00:00
|
|
|
|
2020-03-28 13:48:27 +00:00
|
|
|
if ( window.wcAdminFeatures.marketing ) {
|
|
|
|
pages.push( {
|
2023-03-23 15:19:34 +00:00
|
|
|
container: MarketingOverviewMultichannel,
|
2020-03-28 13:48:27 +00:00
|
|
|
path: '/marketing',
|
|
|
|
breadcrumbs: [
|
|
|
|
...initialBreadcrumbs,
|
2022-03-30 09:00:04 +00:00
|
|
|
[ '/marketing', __( 'Marketing', 'woocommerce' ) ],
|
|
|
|
__( 'Overview', 'woocommerce' ),
|
2020-03-28 13:48:27 +00:00
|
|
|
],
|
2020-06-12 21:55:15 +00:00
|
|
|
wpOpenMenu: 'toplevel_page_woocommerce-marketing',
|
2020-12-02 22:56:24 +00:00
|
|
|
navArgs: {
|
|
|
|
id: 'woocommerce-marketing-overview',
|
|
|
|
},
|
2021-02-19 13:57:17 +00:00
|
|
|
capability: 'view_woocommerce_reports',
|
2020-03-28 13:48:27 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2023-05-19 16:53:55 +00:00
|
|
|
if ( isFeatureEnabled( 'product_block_editor' ) ) {
|
|
|
|
const productPage = {
|
2023-03-08 09:51:59 +00:00
|
|
|
container: ProductPage,
|
2023-05-19 16:53:55 +00:00
|
|
|
layout: {
|
|
|
|
header: false,
|
|
|
|
},
|
|
|
|
wpOpenMenu: 'menu-posts-product',
|
|
|
|
capability: 'manage_woocommerce',
|
|
|
|
};
|
|
|
|
|
|
|
|
pages.push( {
|
|
|
|
...productPage,
|
2022-08-03 17:42:22 +00:00
|
|
|
path: '/add-product',
|
|
|
|
breadcrumbs: [
|
|
|
|
[ '/add-product', __( 'Product', 'woocommerce' ) ],
|
2022-08-11 14:04:14 +00:00
|
|
|
__( 'Add New Product', 'woocommerce' ),
|
2022-08-03 17:42:22 +00:00
|
|
|
],
|
|
|
|
navArgs: {
|
|
|
|
id: 'woocommerce-add-product',
|
|
|
|
},
|
|
|
|
} );
|
2022-08-11 14:04:14 +00:00
|
|
|
|
|
|
|
pages.push( {
|
2023-05-19 16:53:55 +00:00
|
|
|
...productPage,
|
2023-03-09 18:33:39 +00:00
|
|
|
path: '/product/:productId',
|
2023-03-08 09:51:59 +00:00
|
|
|
breadcrumbs: [
|
2023-03-09 18:33:39 +00:00
|
|
|
[ '/edit-product', __( 'Product', 'woocommerce' ) ],
|
|
|
|
__( 'Edit Product', 'woocommerce' ),
|
2023-03-08 09:51:59 +00:00
|
|
|
],
|
|
|
|
navArgs: {
|
2023-03-09 18:33:39 +00:00
|
|
|
id: 'woocommerce-edit-product',
|
2023-03-08 09:51:59 +00:00
|
|
|
},
|
|
|
|
} );
|
2023-03-09 18:33:39 +00:00
|
|
|
} else if (
|
|
|
|
window.wcAdminFeatures[ 'new-product-management-experience' ]
|
|
|
|
) {
|
2023-03-08 09:51:59 +00:00
|
|
|
pages.push( {
|
2023-03-09 18:33:39 +00:00
|
|
|
container: AddProductPage,
|
|
|
|
path: '/add-product',
|
2022-08-11 14:04:14 +00:00
|
|
|
breadcrumbs: [
|
2023-03-09 18:33:39 +00:00
|
|
|
[ '/add-product', __( 'Product', 'woocommerce' ) ],
|
|
|
|
__( 'Add New Product', 'woocommerce' ),
|
2022-08-11 14:04:14 +00:00
|
|
|
],
|
|
|
|
navArgs: {
|
2023-03-09 18:33:39 +00:00
|
|
|
id: 'woocommerce-add-product',
|
2022-08-11 14:04:14 +00:00
|
|
|
},
|
|
|
|
wpOpenMenu: 'menu-posts-product',
|
|
|
|
capability: 'manage_woocommerce',
|
|
|
|
} );
|
2023-03-08 09:51:59 +00:00
|
|
|
|
|
|
|
pages.push( {
|
|
|
|
container: EditProductPage,
|
2023-03-09 18:33:39 +00:00
|
|
|
path: '/product/:productId',
|
2023-03-08 09:51:59 +00:00
|
|
|
breadcrumbs: [
|
2023-03-09 18:33:39 +00:00
|
|
|
[ '/edit-product', __( 'Product', 'woocommerce' ) ],
|
|
|
|
__( 'Edit Product', 'woocommerce' ),
|
2023-03-08 09:51:59 +00:00
|
|
|
],
|
|
|
|
navArgs: {
|
2023-03-09 18:33:39 +00:00
|
|
|
id: 'woocommerce-edit-product',
|
2023-03-08 09:51:59 +00:00
|
|
|
},
|
|
|
|
wpOpenMenu: 'menu-posts-product',
|
|
|
|
capability: 'manage_woocommerce',
|
|
|
|
} );
|
2023-01-06 02:30:23 +00:00
|
|
|
}
|
2022-12-16 14:20:10 +00:00
|
|
|
|
2023-01-06 02:30:23 +00:00
|
|
|
if ( window.wcAdminFeatures[ 'product-variation-management' ] ) {
|
2022-12-16 14:20:10 +00:00
|
|
|
pages.push( {
|
|
|
|
container: EditProductPage,
|
|
|
|
path: '/product/:productId/variation/:variationId',
|
|
|
|
breadcrumbs: [
|
|
|
|
[ '/edit-product', __( 'Product', 'woocommerce' ) ],
|
|
|
|
__( 'Edit Product Variation', 'woocommerce' ),
|
|
|
|
],
|
|
|
|
navArgs: {
|
|
|
|
id: 'woocommerce-edit-product',
|
|
|
|
},
|
|
|
|
wpOpenMenu: 'menu-posts-product',
|
|
|
|
capability: 'edit_products',
|
|
|
|
} );
|
2022-08-03 17:42:22 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:17:10 +00:00
|
|
|
if ( window.wcAdminFeatures.onboarding ) {
|
2023-04-24 02:08:24 +00:00
|
|
|
if ( ! window.wcAdminFeatures[ 'core-profiler' ] ) {
|
|
|
|
pages.push( {
|
|
|
|
container: ProfileWizard,
|
|
|
|
path: '/setup-wizard',
|
|
|
|
breadcrumbs: [
|
|
|
|
...initialBreadcrumbs,
|
|
|
|
__( 'Setup Wizard', 'woocommerce' ),
|
|
|
|
],
|
|
|
|
capability: 'manage_woocommerce',
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
pages.push( {
|
|
|
|
container: CoreProfiler,
|
|
|
|
path: '/setup-wizard',
|
|
|
|
breadcrumbs: [
|
|
|
|
...initialBreadcrumbs,
|
|
|
|
__( 'Profiler', 'woocommerce' ),
|
|
|
|
],
|
|
|
|
capability: 'manage_woocommerce',
|
|
|
|
} );
|
|
|
|
}
|
2020-07-16 15:17:10 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 00:27:53 +00:00
|
|
|
if ( window.wcAdminFeatures[ 'core-profiler' ] ) {
|
|
|
|
pages.push( {
|
|
|
|
container: CoreProfiler,
|
|
|
|
path: '/profiler',
|
|
|
|
breadcrumbs: [
|
|
|
|
...initialBreadcrumbs,
|
|
|
|
__( 'Profiler', 'woocommerce' ),
|
|
|
|
],
|
|
|
|
capability: 'manage_woocommerce',
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2021-02-12 19:32:42 +00:00
|
|
|
if ( window.wcAdminFeatures.settings ) {
|
|
|
|
pages.push( {
|
|
|
|
container: SettingsGroup,
|
|
|
|
path: '/settings/:page',
|
|
|
|
breadcrumbs: ( { match } ) => {
|
2023-05-08 07:55:09 +00:00
|
|
|
// @todo This might need to be refactored to retrieve groups via data store.
|
2022-01-06 12:53:30 +00:00
|
|
|
const settingsPages = getAdminSetting( 'settingsPages' );
|
2021-02-12 19:32:42 +00:00
|
|
|
const page = settingsPages[ match.params.page ];
|
|
|
|
if ( ! page ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return [
|
|
|
|
...initialBreadcrumbs,
|
|
|
|
[
|
|
|
|
settingsPages.general
|
|
|
|
? '/settings/general'
|
|
|
|
: `/settings/${
|
|
|
|
Object.keys( settingsPages )[ 0 ]
|
|
|
|
}`,
|
2022-03-30 09:00:04 +00:00
|
|
|
__( 'Settings', 'woocommerce' ),
|
2021-02-12 19:32:42 +00:00
|
|
|
],
|
|
|
|
page,
|
|
|
|
];
|
|
|
|
},
|
|
|
|
wpOpenMenu: 'toplevel_page_woocommerce',
|
2021-02-19 13:57:17 +00:00
|
|
|
capability: 'manage_woocommerce',
|
2021-02-12 19:32:42 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2022-01-12 06:46:33 +00:00
|
|
|
if ( window.wcAdminFeatures[ 'wc-pay-welcome-page' ] ) {
|
|
|
|
pages.push( {
|
|
|
|
container: WCPaymentsWelcomePage,
|
|
|
|
path: '/wc-pay-welcome-page',
|
|
|
|
breadcrumbs: [
|
2023-06-16 14:32:58 +00:00
|
|
|
[ '/wc-pay-welcome-page', __( 'WooPayments', 'woocommerce' ) ],
|
|
|
|
__( 'WooPayments', 'woocommerce' ),
|
2022-01-12 06:46:33 +00:00
|
|
|
],
|
|
|
|
navArgs: {
|
|
|
|
id: 'woocommerce-wc-pay-welcome-page',
|
|
|
|
},
|
|
|
|
wpOpenMenu: 'toplevel_page_woocommerce-wc-pay-welcome-page',
|
|
|
|
capability: 'manage_woocommerce',
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* List of WooCommerce Admin pages.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_admin_pages_list
|
|
|
|
* @param {Array.<Object>} pages Array page objects.
|
|
|
|
*/
|
2021-10-14 14:04:17 +00:00
|
|
|
const filteredPages = applyFilters( PAGES_FILTER, pages );
|
|
|
|
|
|
|
|
filteredPages.push( {
|
|
|
|
container: NoMatch,
|
|
|
|
path: '*',
|
|
|
|
breadcrumbs: [
|
|
|
|
...initialBreadcrumbs,
|
2022-03-30 09:00:04 +00:00
|
|
|
__( 'Not allowed', 'woocommerce' ),
|
2021-10-14 14:04:17 +00:00
|
|
|
],
|
|
|
|
wpOpenMenu: 'toplevel_page_woocommerce',
|
|
|
|
} );
|
|
|
|
|
|
|
|
return filteredPages;
|
2018-05-18 17:31:08 +00:00
|
|
|
};
|
|
|
|
|
2022-05-30 06:51:33 +00:00
|
|
|
function usePrevious( value ) {
|
|
|
|
const ref = useRef();
|
|
|
|
useEffect( () => {
|
|
|
|
ref.current = value;
|
|
|
|
}, [ value ] );
|
|
|
|
return ref.current;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Controller = ( { ...props } ) => {
|
|
|
|
const prevProps = usePrevious( props );
|
|
|
|
|
|
|
|
useEffect( () => {
|
2019-04-08 17:53:28 +00:00
|
|
|
window.document.documentElement.scrollTop = 0;
|
2020-10-16 18:47:29 +00:00
|
|
|
window.document.body.classList.remove( 'woocommerce-admin-is-loading' );
|
2022-05-30 06:51:33 +00:00
|
|
|
}, [] );
|
2019-04-08 17:53:28 +00:00
|
|
|
|
2022-05-30 06:51:33 +00:00
|
|
|
useEffect( () => {
|
|
|
|
if ( prevProps ) {
|
|
|
|
const prevBaseQuery = omit(
|
|
|
|
prevProps.query,
|
|
|
|
'chartType',
|
|
|
|
'filter',
|
|
|
|
'paged'
|
|
|
|
);
|
|
|
|
const baseQuery = omit(
|
|
|
|
props.query,
|
|
|
|
'chartType',
|
|
|
|
'filter',
|
|
|
|
'paged'
|
|
|
|
);
|
2019-02-04 02:55:06 +00:00
|
|
|
|
2022-05-30 06:51:33 +00:00
|
|
|
if (
|
|
|
|
prevProps.query.paged > 1 &&
|
|
|
|
! isEqual( prevBaseQuery, baseQuery )
|
|
|
|
) {
|
|
|
|
getHistory().replace( getNewPath( { paged: 1 } ) );
|
|
|
|
}
|
2019-04-08 17:53:28 +00:00
|
|
|
|
2022-05-30 06:51:33 +00:00
|
|
|
if ( prevProps.match.url !== props.match.url ) {
|
|
|
|
window.document.documentElement.scrollTop = 0;
|
|
|
|
}
|
2019-04-08 17:53:28 +00:00
|
|
|
}
|
2022-05-30 06:51:33 +00:00
|
|
|
}, [ props, prevProps ] );
|
2019-02-04 02:55:06 +00:00
|
|
|
|
2022-05-30 06:51:33 +00:00
|
|
|
const { page, match, query } = props;
|
|
|
|
const { url, params } = match;
|
2019-04-11 18:31:31 +00:00
|
|
|
|
2022-05-30 06:51:33 +00:00
|
|
|
window.wpNavMenuUrlUpdate( query );
|
|
|
|
window.wpNavMenuClassChange( page, url );
|
|
|
|
return (
|
|
|
|
<Suspense fallback={ <Spinner /> }>
|
|
|
|
<page.container
|
|
|
|
params={ params }
|
|
|
|
path={ url }
|
|
|
|
pathMatch={ page.path }
|
|
|
|
query={ query }
|
|
|
|
/>
|
|
|
|
</Suspense>
|
|
|
|
);
|
|
|
|
};
|
2018-05-18 17:31:08 +00:00
|
|
|
|
2019-05-14 03:58:37 +00:00
|
|
|
/**
|
|
|
|
* Update an anchor's link in sidebar to include persisted queries. Leave excluded screens
|
|
|
|
* as is.
|
|
|
|
*
|
2022-03-18 11:45:14 +00:00
|
|
|
* @param {HTMLElement} item - Sidebar anchor link.
|
|
|
|
* @param {Object} nextQuery - A query object to be added to updated hrefs.
|
|
|
|
* @param {Array} excludedScreens - wc-admin screens to avoid updating.
|
2019-05-14 03:58:37 +00:00
|
|
|
*/
|
|
|
|
export function updateLinkHref( item, nextQuery, excludedScreens ) {
|
2020-08-05 22:02:24 +00:00
|
|
|
if ( isWCAdmin( item.href ) ) {
|
2019-06-13 19:58:21 +00:00
|
|
|
const search = last( item.href.split( '?' ) );
|
2023-06-05 07:55:20 +00:00
|
|
|
const query = parse( search );
|
|
|
|
const path = query.path || 'homescreen';
|
2021-01-07 16:53:31 +00:00
|
|
|
const screen = getScreenFromPath( path );
|
2019-06-13 19:58:21 +00:00
|
|
|
|
2023-06-05 07:55:20 +00:00
|
|
|
const isExcludedScreen = excludedScreens.includes( screen );
|
2019-06-13 19:58:21 +00:00
|
|
|
|
2023-06-05 07:55:20 +00:00
|
|
|
const href =
|
|
|
|
'admin.php?' +
|
|
|
|
stringify(
|
|
|
|
Object.assign( query, isExcludedScreen ? {} : nextQuery )
|
|
|
|
);
|
2019-06-13 19:58:21 +00:00
|
|
|
|
|
|
|
// Replace the href so you can see the url on hover.
|
|
|
|
item.href = href;
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
item.onclick = ( e ) => {
|
2019-06-13 19:58:21 +00:00
|
|
|
e.preventDefault();
|
|
|
|
getHistory().push( href );
|
|
|
|
};
|
2019-05-14 03:58:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 19:58:21 +00:00
|
|
|
// Update's wc-admin links in wp-admin menu
|
2020-07-28 02:32:58 +00:00
|
|
|
window.wpNavMenuUrlUpdate = function ( query ) {
|
2019-06-13 19:58:21 +00:00
|
|
|
const nextQuery = getPersistedQuery( query );
|
2021-01-07 16:53:31 +00:00
|
|
|
const excludedScreens = getQueryExcludedScreens();
|
2023-05-19 16:53:55 +00:00
|
|
|
const anchors = document.querySelectorAll( '#adminmenu a' );
|
2019-05-14 03:58:37 +00:00
|
|
|
|
2023-05-19 16:53:55 +00:00
|
|
|
Array.from( anchors ).forEach( ( item ) =>
|
|
|
|
updateLinkHref( item, nextQuery, excludedScreens )
|
2022-06-21 08:37:34 +00:00
|
|
|
);
|
2018-10-18 04:37:28 +00:00
|
|
|
};
|
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
// When the route changes, we need to update wp-admin's menu with the correct section & current link
|
2020-07-28 02:32:58 +00:00
|
|
|
window.wpNavMenuClassChange = function ( page, url ) {
|
2021-10-25 13:59:35 +00:00
|
|
|
const wpNavMenu = document.querySelector( '#adminmenu' );
|
|
|
|
Array.from( wpNavMenu.getElementsByClassName( 'current' ) ).forEach(
|
2020-07-28 02:32:58 +00:00
|
|
|
function ( item ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
item.classList.remove( 'current' );
|
|
|
|
}
|
|
|
|
);
|
2018-10-10 14:24:57 +00:00
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const submenu = Array.from(
|
2021-10-25 13:59:35 +00:00
|
|
|
wpNavMenu.querySelectorAll( '.wp-has-current-submenu' )
|
2020-02-14 02:23:21 +00:00
|
|
|
);
|
2020-07-28 02:32:58 +00:00
|
|
|
submenu.forEach( function ( element ) {
|
2018-10-27 17:38:35 +00:00
|
|
|
element.classList.remove( 'wp-has-current-submenu' );
|
|
|
|
element.classList.remove( 'wp-menu-open' );
|
|
|
|
element.classList.remove( 'selected' );
|
|
|
|
element.classList.add( 'wp-not-current-submenu' );
|
|
|
|
element.classList.add( 'menu-top' );
|
|
|
|
} );
|
2018-10-10 14:24:57 +00:00
|
|
|
|
2019-06-13 19:58:21 +00:00
|
|
|
const pageUrl =
|
2020-02-14 02:23:21 +00:00
|
|
|
url === '/'
|
2019-06-13 19:58:21 +00:00
|
|
|
? 'admin.php?page=wc-admin'
|
|
|
|
: 'admin.php?page=wc-admin&path=' + encodeURIComponent( url );
|
2023-07-16 19:23:33 +00:00
|
|
|
let currentItemsSelector =
|
2019-06-13 19:58:21 +00:00
|
|
|
url === '/'
|
|
|
|
? `li > a[href$="${ pageUrl }"], li > a[href*="${ pageUrl }?"]`
|
|
|
|
: `li > a[href*="${ pageUrl }"]`;
|
2023-07-16 19:23:33 +00:00
|
|
|
|
|
|
|
const parentPath = page.navArgs?.parentPath;
|
|
|
|
if ( parentPath ) {
|
|
|
|
const parentPageUrl =
|
|
|
|
parentPath === '/'
|
|
|
|
? 'admin.php?page=wc-admin'
|
|
|
|
: 'admin.php?page=wc-admin&path=' +
|
|
|
|
encodeURIComponent( parentPath );
|
|
|
|
currentItemsSelector += `, li > a[href*="${ parentPageUrl }"]`;
|
|
|
|
}
|
|
|
|
|
2021-10-25 13:59:35 +00:00
|
|
|
const currentItems = wpNavMenu.querySelectorAll( currentItemsSelector );
|
2018-10-18 04:37:28 +00:00
|
|
|
|
2020-07-28 02:32:58 +00:00
|
|
|
Array.from( currentItems ).forEach( function ( item ) {
|
2018-10-10 16:06:32 +00:00
|
|
|
item.parentElement.classList.add( 'current' );
|
|
|
|
} );
|
2018-10-10 14:24:57 +00:00
|
|
|
|
2019-04-11 18:31:31 +00:00
|
|
|
if ( page.wpOpenMenu ) {
|
2021-10-25 13:59:35 +00:00
|
|
|
const currentMenu = wpNavMenu.querySelector( '#' + page.wpOpenMenu );
|
2020-06-10 21:56:01 +00:00
|
|
|
if ( currentMenu ) {
|
|
|
|
currentMenu.classList.remove( 'wp-not-current-submenu' );
|
|
|
|
currentMenu.classList.add( 'wp-has-current-submenu' );
|
|
|
|
currentMenu.classList.add( 'wp-menu-open' );
|
|
|
|
currentMenu.classList.add( 'current' );
|
|
|
|
}
|
2019-04-11 18:31:31 +00:00
|
|
|
}
|
2018-10-18 04:37:28 +00:00
|
|
|
|
2019-02-20 15:18:27 +00:00
|
|
|
const wpWrap = document.querySelector( '#wpwrap' );
|
|
|
|
wpWrap.classList.remove( 'wp-responsive-open' );
|
2018-05-18 17:31:08 +00:00
|
|
|
};
|