Commit 2a3b57ddddc for woocommerce
commit 2a3b57ddddc2f1585ef74253e1a18def95f12cc3
Author: Daniel Mallory <daniel.mallory@automattic.com>
Date: Mon Nov 30 16:42:41 2026 +0000
Add settings areas to the settings screen route (#70330)
* refactor(settings): Add the settings area to the settings screen route
Route settings pages as /settings/{area}/{page}, such as
/settings/payments/cheque. The area sets the entity kind and the first
breadcrumb, so the breadcrumb no longer hardcodes Payments.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(settings): Give the settings screen route a page title
@wordpress/boot sets the document title and announces it to screen
readers on in-app navigation, using the route's title. The settings
route didn't define one, so neither happened.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(settings): Take the settings area from the entity
getSections() was a fixed list in Core, so an extension could register a
settings page but not the area it belongs to. The route's section segment
now maps to the entity kind (woo_settings_<section>), and each entity
config carries its own breadcrumb label and link.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(settings): Keep the settings area breadcrumb in entity meta
core-data's EntityConfig has an open meta field for extra data, so the
breadcrumb label and link go there instead of a top-level property that
could clash with one core-data adds later.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(settings): Inline the payments entity kind
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/admin-screens/routes/settings/entities.ts b/plugins/woocommerce/admin-screens/routes/settings/entities.ts
index 1e93df8a819..ed59d2bda82 100644
--- a/plugins/woocommerce/admin-screens/routes/settings/entities.ts
+++ b/plugins/woocommerce/admin-screens/routes/settings/entities.ts
@@ -3,11 +3,19 @@
*/
import { __ } from '@wordpress/i18n';
-export const ENTITY_KIND = 'woo_settings_payments';
+const ENTITY_KIND_PREFIX = 'woo_settings_';
/**
- * A core-data entity config for a settings page. The page's URL segment is the entity name and
- * its record ID, and its fields are registered on the server from `packages/entity-fields/`.
+ * The entity kind for a settings area's URL segment, such as `woo_settings_payments` for `payments`.
+ */
+export function getEntityKind( section: string ): string {
+ return ENTITY_KIND_PREFIX + section;
+}
+
+/**
+ * A core-data entity config for a settings page, at `/settings/$section/$page`. The kind holds the
+ * area's segment and the name is the page's segment and record ID. `meta.section` is the area's label
+ * and wp-admin URL for the first breadcrumb. Fields are registered on the server from `packages/entity-fields/`.
*/
export interface SettingsEntityConfig {
kind: string;
@@ -16,6 +24,7 @@ export interface SettingsEntityConfig {
key: string;
label: string;
getTitle: () => string;
+ meta?: { section?: { label: string; url: string } };
}
/**
@@ -24,12 +33,18 @@ export interface SettingsEntityConfig {
export function getCoreEntities(): SettingsEntityConfig[] {
return [
{
- kind: ENTITY_KIND,
+ kind: getEntityKind( 'payments' ),
name: 'cheque',
baseURL: '/wc/v3/payment_gateways',
key: 'id',
label: __( 'Check payments', 'woocommerce' ),
getTitle: () => __( 'Check payments', 'woocommerce' ),
+ meta: {
+ section: {
+ label: __( 'Payments', 'woocommerce' ),
+ url: 'admin.php?page=wc-settings&tab=checkout',
+ },
+ },
},
];
}
diff --git a/plugins/woocommerce/admin-screens/routes/settings/package.json b/plugins/woocommerce/admin-screens/routes/settings/package.json
index 474bf69d3f8..0540dd28383 100644
--- a/plugins/woocommerce/admin-screens/routes/settings/package.json
+++ b/plugins/woocommerce/admin-screens/routes/settings/package.json
@@ -1,6 +1,6 @@
{
"route": {
- "path": "/settings/$page",
+ "path": "/settings/$section/$page",
"page": "wc-settings-screen"
}
}
diff --git a/plugins/woocommerce/admin-screens/routes/settings/route.tsx b/plugins/woocommerce/admin-screens/routes/settings/route.tsx
index e223c1e2553..e6e17dc9a37 100644
--- a/plugins/woocommerce/admin-screens/routes/settings/route.tsx
+++ b/plugins/woocommerce/admin-screens/routes/settings/route.tsx
@@ -8,16 +8,31 @@ import { notFound } from '@wordpress/route';
/**
* Internal dependencies
*/
-import { ENTITY_KIND, getCoreEntities } from './entities';
+import { getCoreEntities, getEntityKind } from './entities';
+import type { SettingsEntityConfig } from './entities';
+
+interface RouteParams {
+ params: { section?: string; page?: string };
+}
+
+function getPageConfig( {
+ params,
+}: RouteParams ): SettingsEntityConfig | undefined {
+ if ( ! params.section || ! params.page ) {
+ return undefined;
+ }
+ return select( coreStore ).getEntityConfig(
+ getEntityKind( params.section ),
+ params.page
+ ) as SettingsEntityConfig | undefined;
+}
export const route = {
- beforeLoad: async ( { params }: { params: { page?: string } } ) => {
+ beforeLoad: async ( context: RouteParams ) => {
await dispatch( coreStore ).addEntities( getCoreEntities() );
- if (
- ! params.page ||
- ! select( coreStore ).getEntityConfig( ENTITY_KIND, params.page )
- ) {
+ if ( ! getPageConfig( context ) ) {
throw notFound();
}
},
+ title: ( context: RouteParams ) => getPageConfig( context )?.label,
};
diff --git a/plugins/woocommerce/admin-screens/routes/settings/stage.tsx b/plugins/woocommerce/admin-screens/routes/settings/stage.tsx
index 4517a92456e..8ef0c595d14 100644
--- a/plugins/woocommerce/admin-screens/routes/settings/stage.tsx
+++ b/plugins/woocommerce/admin-screens/routes/settings/stage.tsx
@@ -19,7 +19,7 @@ import { useState } from 'react';
/**
* Internal dependencies
*/
-import { ENTITY_KIND } from './entities';
+import { getEntityKind } from './entities';
import type { SettingsEntityConfig } from './entities';
import { getEntityFields, getEntityFieldsStatus } from './entity-fields';
import type { SettingsField, SettingsRecord } from './types';
@@ -46,6 +46,7 @@ function getErrorMessage( error: unknown, fallback: string ): string {
*/
function SettingsForm( { config }: { config: SettingsEntityConfig } ) {
const { kind, name, label } = config;
+ const section = config.meta?.section;
const { record, editedRecord, hasEdits, edit, save } =
useEntityRecord< SettingsRecord >( kind, name, name );
const isNarrow = useViewportMatch( 'medium', '<' );
@@ -104,10 +105,15 @@ function SettingsForm( { config }: { config: SettingsEntityConfig } ) {
const hasLoadError = !! loadError;
const isReady = ! hasLoadError && !! data && !! form && hasFields;
// Breadcrumbs link through the router, which only leaves the screen for an absolute URL.
- const paymentsUrl = new URL(
- 'admin.php?page=wc-settings&tab=checkout',
- window.location.href
- ).toString();
+ const breadcrumbs = section
+ ? [
+ {
+ label: section.label,
+ to: new URL( section.url, window.location.href ).toString(),
+ },
+ { label },
+ ]
+ : [ { label } ];
const formActions = (
<Stack direction="row" gap="sm" justify="end">
<Button
@@ -137,17 +143,7 @@ function SettingsForm( { config }: { config: SettingsEntityConfig } ) {
return (
<Page
ariaLabel={ label }
- breadcrumbs={
- <Breadcrumbs
- items={ [
- {
- label: __( 'Payments', 'woocommerce' ),
- to: paymentsUrl,
- },
- { label },
- ] }
- />
- }
+ breadcrumbs={ <Breadcrumbs items={ breadcrumbs } /> }
showSidebarToggle={ false }
hasPadding
// The Page header doesn't wrap its actions, so they move below the form on small screens.
@@ -206,17 +202,20 @@ function SettingsForm( { config }: { config: SettingsEntityConfig } ) {
}
/**
- * Show the settings entity whose name matches the route, as registered with addEntities().
+ * Show the settings entity whose kind and name match the route's area and page.
*/
function SettingsStage() {
- const { page }: { page?: string } = useParams( { strict: false } );
+ const { section, page }: { section?: string; page?: string } = useParams( {
+ strict: false,
+ } );
+ const kind = section ? getEntityKind( section ) : undefined;
const config = useSelect(
( select ) =>
- page
- ? ( select( coreStore ).getEntityConfig( ENTITY_KIND, page ) as
+ kind && page
+ ? ( select( coreStore ).getEntityConfig( kind, page ) as
SettingsEntityConfig | undefined )
: undefined,
- [ page ]
+ [ kind, page ]
);
return config ? (
<SettingsForm key={ config.name } config={ config } />
diff --git a/plugins/woocommerce/changelog/fix-settings-screen-breadcrumb-parent b/plugins/woocommerce/changelog/fix-settings-screen-breadcrumb-parent
new file mode 100644
index 00000000000..b79a39dd0d8
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-settings-screen-breadcrumb-parent
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Add settings areas to the experimental settings screen; flag-only screen.