Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Remove subpath URLQueryParam from settings pages. #1031

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ addFilter(
__( 'Settings', 'google-listings-and-ads' ),
],
container: Settings,
path: '/google/settings',
path: '/google/settings/:subpath?',
wpOpenMenu: 'toplevel_page_woocommerce-marketing',
navArgs: {
id: 'google-settings',
Expand Down
15 changes: 11 additions & 4 deletions js/src/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { useEffect } from '@wordpress/element';
import { getQuery, getHistory } from '@woocommerce/navigation';
import { getHistory } from '@woocommerce/navigation';

/**
* Internal dependencies
Expand All @@ -17,8 +17,15 @@ import EditStoreAddress from './edit-store-address';
import EditPhoneNumber from './edit-phone-number';
import './index.scss';

const Settings = () => {
const { subpath } = getQuery();
/**
* Settings page component.
*
* @param {Object} [props] React props
* @param {Object} [props.params = {}] `path` params extracted by React `<Router>`.
* @param {string} [props.params.subpath] Sub path of a nested settings page.
Comment on lines +24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎 👍

* @return {JSX.Element} Settings page component.
*/
const Settings = ( { params: { subpath } = {} } ) => {
const { google } = useGoogleAccount();
const isReconnectAccountsPage = subpath === subpaths.reconnectAccounts;

Expand All @@ -31,7 +38,7 @@ const Settings = () => {
}, [ isReconnectAccountsPage, google ] );

// Navigate to subpath is any.
switch ( subpath ) {
switch ( '/' + subpath ) {
case subpaths.reconnectAccounts:
return <ReconnectAccounts />;
case subpaths.editPhoneNumber:
Expand Down
18 changes: 3 additions & 15 deletions js/src/utils/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,12 @@ export const getSettingsUrl = () => {
};

export const getEditPhoneNumberUrl = () => {
return getNewPath(
{ subpath: subpaths.editPhoneNumber },
settingsPath,
null
);
return getNewPath( null, settingsPath + subpaths.editPhoneNumber, null );
};
export const getEditStoreAddressUrl = () => {
return getNewPath(
{ subpath: subpaths.editStoreAddress },
settingsPath,
null
);
return getNewPath( null, settingsPath + subpaths.editStoreAddress, null );
};

export const getReconnectAccountsUrl = () => {
return getNewPath(
{ subpath: subpaths.reconnectAccounts },
settingsPath,
null
);
return getNewPath( null, settingsPath + subpaths.reconnectAccounts, null );
};
2 changes: 1 addition & 1 deletion src/API/Site/Controllers/Google/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function get_connect_callback(): callable {
return function( Request $request ) {
try {
$next = $request->get_param( 'next' );
$path = $next === 'setup-mc' ? '/google/setup-mc' : '/google/settings&subpath=/reconnect-accounts';
$path = $next === 'setup-mc' ? '/google/setup-mc' : '/google/settings/reconnect-accounts';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝
Will conflict with this commit in PR #1069


return [
'url' => $this->connection->connect( admin_url( "admin.php?page=wc-admin&path={$path}" ) ),
Expand Down
29 changes: 29 additions & 0 deletions src/Menu/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,38 @@ function() {
'nav_args' => [
'order' => 40,
'parent' => 'google-listings-and-ads-category',
// Highlight this menu item for other subpages.
'matchExpression' => '/google/settings(/[^/]+)?',
Comment on lines +32 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: matchExpression. Great find! 🙌

],
]
);
// TODO: Check if we can make it a bit DRYier, and reduce the below, to smth like `'path' => '/google/settings/:subpage?'`
// So far it's hard to guess the type of register_page options,
// which is documented to be the type of "Options for PageController::register_page()." ➰
wc_admin_register_page(
[
'title' => __( 'Settings', 'google-listings-and-ads' ),
'parent' => 'google-listings-and-ads-category',
'path' => '/google/settings/edit-phone-number',
'id' => 'google-settings-phone-number',
]
);
wc_admin_register_page(
[
'title' => __( 'Settings', 'google-listings-and-ads' ),
'parent' => 'google-listings-and-ads-category',
'path' => '/google/settings/edit-store-address',
'id' => 'google-settings-store-address',
]
);
wc_admin_register_page(
[
'title' => __( 'Settings', 'google-listings-and-ads' ),
'parent' => 'google-listings-and-ads-category',
'path' => '/google/settings/reconnect-accounts',
'id' => 'google-settings-reconnect-accounts',
]
);
}
);
}
Expand Down