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
Add inbox WP admin link support for remote inbox notifications #33237
Conversation
@@ -101,7 +101,10 @@ private static function get_url( $action ) { | |||
} | |||
|
|||
if ( isset( $action->url_is_admin_query ) && $action->url_is_admin_query ) { | |||
return wc_admin_url( $action->url ); | |||
if ( strpos( $action->url, '&path' ) === 0 ) { | |||
return wc_admin_url( $action->url ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to go this route, as &path
seemed to be the only examples I could find of when we were linking to WCA pages.
As the url_is_admin_query
entails, we likely want to phase out that support and always provide a WP Admin link even for WCA pages, but that is just a thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it will catch most known cases. Just for the sake of discussion, is there any chance we can reuse @joelclimbsthings's PR ( https://github.com/woocommerce/woocommerce/pull/33124/files ) to detect and navigate to links in the client?
As the url_is_admin_query entails, we likely want to phase out that support and always provide a WP Admin link even for WCA pages, but that is just a thought.
Completely agree with this. It probably would have been wise in retrospect to never allow this specific level of partial URLs only for WCA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for the sake of discussion, is there any chance we can reuse @joelclimbsthings's PR ( https://github.com/woocommerce/woocommerce/pull/33124/files ) to detect and navigate to links in the client?
We could use his navigateTo
function in the inbox-note, but that would still require the above logic. As the current logic in Joel's PR can't differentiate between going to &path=wc-addons
or plugins.php
.
So it would only work well for going to either WCA pages or non wp admin pages.
The one benefit of using Joel's navigateTo
in the inbox-note is that if we were going to a WCA page, it won't do a full page refresh, but makes use of the react router (I think) not a 100% on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, that makes sense. This was definitely an oversight on our part allowing partial (WCA only) paths as options.
I may p2 this later to make sure we're all on the same page going forward.
📊 Test reports for this pull request have been published and are accessible through the following links:
Latest commit referenced in the reports: Visit the WooCommerce Test Reports homepage to view all published reports. See the FAQs page if you're having problems accessing them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall; just dropped a question in the code.
Also curious if we might have any use cases for navigating to non-admin URLs in the future.
@@ -101,7 +101,10 @@ private static function get_url( $action ) { | |||
} | |||
|
|||
if ( isset( $action->url_is_admin_query ) && $action->url_is_admin_query ) { | |||
return wc_admin_url( $action->url ); | |||
if ( strpos( $action->url, '&path' ) === 0 ) { | |||
return wc_admin_url( $action->url ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it will catch most known cases. Just for the sake of discussion, is there any chance we can reuse @joelclimbsthings's PR ( https://github.com/woocommerce/woocommerce/pull/33124/files ) to detect and navigate to links in the client?
As the url_is_admin_query entails, we likely want to phase out that support and always provide a WP Admin link even for WCA pages, but that is just a thought.
Completely agree with this. It probably would have been wise in retrospect to never allow this specific level of partial URLs only for WCA.
/** | ||
* class WC_Admin_Tests_RemoteInboxNotifications_SpecRunner | ||
*/ | ||
class WC_Admin_Tests_RemoteInboxNotifications_SpecRunner extends WC_Unit_Test_Case { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
We might, I think one example would be to check out the users homepage for example and link there. |
The only issue with this is that |
Aaah yeah, I forgot about that, thanks for the reminder. In that case if the user has |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing well and code looks good! Thanks for the added tests ❤️
@joelclimbsthings Your navigateTo
function will be a great add-on to the note actions. There are some good test cases in here worth checking.
@@ -101,7 +101,10 @@ private static function get_url( $action ) { | |||
} | |||
|
|||
if ( isset( $action->url_is_admin_query ) && $action->url_is_admin_query ) { | |||
return wc_admin_url( $action->url ); | |||
if ( strpos( $action->url, '&path' ) === 0 ) { | |||
return wc_admin_url( $action->url ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, that makes sense. This was definitely an oversight on our part allowing partial (WCA only) paths as options.
I may p2 this later to make sure we're all on the same page going forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing well and code looks good! Thanks for the added tests ❤️
@joelclimbsthings Your navigateTo
function will be a great add-on to the note actions. There are some good test cases in here worth checking.
Hi @louwie17, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
All Submissions:
Changes proposed in this Pull Request:
Make use of
admin_url
by default for action urls, and only usewc_admin_url
when the url starts with&path
.This would mean that this might break on older versions of WC, so whomever adds a new note will have to add this condition (other suggestions are welcome):
Closes #32129 .
How to test the changes in this Pull Request:
mu-plugin
if you don't have one already and add this filter to it:This add's this gist to the remote inbox notifications that will add 3 new notes.
3. Go to Tools > WCA Test Helper > Tools and trigger the
wc_admin_daily_job
4. Go to WooCommerce > Home and 4 new notes should be present (Navigate to plugins, Where did this note come from?, Navigate to add products, and Navigate to onboarding )
5. Click on the action of each of them, and they should all direct correctly to it's designated location (as implied by the title and description). The Navigate to add products and the Navigate to plugins are the notes that contains the Admin url, see line 24 and 147 in the Gist ).
Other information:
pnpm nx changelog <project>
?FOR PR REVIEWER ONLY: