add filtering

This commit is contained in:
paul sealock 2024-09-05 13:14:41 +12:00
parent deaf60e387
commit 4242eb3ba6
2 changed files with 34 additions and 12 deletions

View File

@ -8,6 +8,7 @@ import { useSettingsLocation } from '../../routes';
*/ */
import { getNewPath } from '@woocommerce/navigation'; import { getNewPath } from '@woocommerce/navigation';
import { Link } from '@woocommerce/components'; import { Link } from '@woocommerce/components';
import { addFilter } from '@wordpress/hooks';
export const MyExample = () => { export const MyExample = () => {
const { section } = useSettingsLocation(); const { section } = useSettingsLocation();
@ -31,3 +32,20 @@ export const MyExampleEdit = () => {
</> </>
); );
}; };
addFilter( 'woocommerce_admin_settings_pages', 'woocommerce', ( pages ) => {
return [
...pages,
{
page: 'my-example',
areas: {
content: <MyExample />,
edit: <MyExampleEdit />,
},
widths: {
content: undefined,
edit: 380,
},
},
];
} );

View File

@ -2,12 +2,12 @@
* External dependencies * External dependencies
*/ */
import { getQuery } from '@woocommerce/navigation'; import { getQuery } from '@woocommerce/navigation';
import { applyFilters } from '@wordpress/hooks';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { Content } from './content'; import { Content } from './content';
import { MyExample, MyExampleEdit } from './pages/my-example';
const NotFound = () => { const NotFound = () => {
return <h1>Not Found</h1>; return <h1>Not Found</h1>;
@ -42,11 +42,11 @@ export const getRoute = () => {
}; };
} }
const legacyPages = Object.keys( settingsData ).filter( const legacyRoutes = Object.keys( settingsData ).filter(
( p ) => ! settingsData[ p ].is_modern ( p ) => ! settingsData[ p ].is_modern
); );
if ( legacyPages.includes( page ) ) { if ( legacyRoutes.includes( page ) ) {
return { return {
page, page,
areas: { areas: {
@ -60,19 +60,23 @@ export const getRoute = () => {
}; };
} }
const pages = [ const routes = applyFilters( 'woocommerce_admin_settings_pages', [] );
{
page: 'my-example', const pageRoute = routes.find( ( route ) => route.page === page );
if ( ! pageRoute ) {
return {
page,
areas: { areas: {
content: <MyExample />, content: <NotFound />,
edit: <MyExampleEdit />, edit: null,
}, },
widths: { widths: {
content: undefined, content: undefined,
edit: 380, edit: undefined,
}, },
}, };
]; }
return pages.find( ( p ) => p.page === page ); return pageRoute;
}; };