-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add close button for store alerts #37710
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
Conversation
Test Results SummaryCommit SHA: 0896303
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
69dc45c to
50ab26b
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## trunk #37710 +/- ##
==========================================
+ Coverage 51.5% 51.6% +0.1%
+ Complexity 17281 17261 -20
==========================================
Files 430 429 -1
Lines 80030 79942 -88
==========================================
- Hits 41215 41212 -3
+ Misses 38815 38730 -85 |
|
Hi @mattsherman, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
@nathanss Some suggestions on how to improve testing instructions in the future:
|
You can also just use the "Delete all admin notes" action in the WCA Test Helper > Admin notes screen. |
mattsherman
left a comment
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.
It would be good to add a test for the new dismiss button. To make sure it shows the previous alert, and dismisses the current alert.
Should we get rid of the Dismiss button for notes that have them? I iamgine that involves modiying the notes data source on WooCommerce.com.
| expect( getByText( 'Click me!' ) ).toBeVisible(); | ||
| expect( getByText( 'Click me!' ).getAttribute( 'href' ) ).toBe( '#' ); |
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.
❤️
| await removeNote( alert.id ); | ||
| this.previousAlert(); | ||
| invalidateResolutionForStoreSelector( 'getNotes' ); |
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.
It would be nice to move this to a function outside of the JSX, to keep the code a bit more readable.
| invalidateResolutionForStoreSelector( 'getNotes' ); | ||
| } } | ||
| > | ||
| <Icon icon={ close } /> |
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.
It would be good to have a tooltip or some other accessible way to know what this button is.
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.
How about Dismiss message?
That's awesome. Thanks for sharing!
Yes, it involves modifying it on woocommerce.com. That would be pretty hard. I prefer not to do this for now. |
I'm concerned that the UX is kinda confusing with both the "Dismiss" buttons and the "X" close button. It shouldn't be hard to remove the "Dismiss" button for notes. We should create a follow-up issue to do so. @jarekmorawski Do you have any thoughts on having both the "Dismiss" and the "X" button on notes in the mean time? |
mattsherman
left a comment
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.
Overall, code looks good (I did not re-test yet).
Left a question about a div added.
I'll re-test later this evening.
| { interpolateComponents( { | ||
| mixedString: __( | ||
| '{{current /}} of {{total /}}', | ||
| <div> |
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.
Why was this extra div needed?
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.
mattsherman
left a comment
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 is overall looking quite good. Nice job!
I think we should have a Tracks event when the "X" is clicked and the note is removed (see comment in code).
| const { removeNote, invalidateResolutionForStoreSelector } = this.props; | ||
|
|
||
| const removeNoteAndInvalidate = async () => { | ||
| await removeNote( alert.id ); |
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 should record a Tracks event when the "X" is clicked and the note is removed.
Something similar to wcadmin_store_alert_action, with similar params if possible.
| wc_admin_record_tracks_event( 'store_alert_action', $event_params ); |
@mattsherman I'm just not sure how we're going to maintain support for previous versions, since the admin notes don't seem to have versions, so if we just removed the Dismiss actions from woocommerce.com, all alerts would become undismissable on installations without this code. There might be a way, though. I just couldn't think of it. |
There's no need to have both since this could confuse people regarding each button's function. Before we go any further, can you explain why we need the |
|
@jarekmorawski I agree with you. The problem is that all the buttons that come from remote inbox are generic, there's no "native" dismiss button. Here's an example of what is received from the server: {
"name": "woocommerce-core-paypal-march-2022-dismiss",
"locales": [
{
"locale": "en_US",
"label": "Dismiss"
}
],
"url": "",
"url_is_admin_query": false,
"is_primary": false,
"status": "actioned"
}There's no good way of knowing this is a Dismiss button from my point of view. The best I could do is test if the button label is equal "Dismiss" (accounting for translation as well),which seems to be a pattern currently, and hide it in that case. @mattsherman what do you think? |
| this.previousAlert(); | ||
| invalidateResolutionForStoreSelector( 'getNotes' ); | ||
| recordEvent( 'store_alert_close', { | ||
| alert_id: alert.id, |
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.
Is this alert.id unique to the store/db? If so, there is probably no benefit in including it.
| alert_name: alert.name, | ||
| alert_title: alert.title, | ||
| alert_content: alert.content, |
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.
For consistency with the store_alert_action, I would name these:
note_namenote_titlenote_content
Do you have access to note_type? I see that in the store_alert_action event, as well as screen... those would be useful too.
2eaa5dc to
0896303
Compare
Note: I'm leaving this rambling at the beginning of this comment just to show my thought process. Skip to POSSIBLE SOLUTION below for what I think actually is what we should do! Okay, so, could we safely conclude that if a note's action meets the following criteria it is just a "stock" Dismiss action that we could hook up our own handling to?
If an action met all those criteria, what if we replaced the default action handling hooked up to it with the new code you wrote for the "X" button? And, got rid of the "X" button (unless Jarek likes that UX better). Seems pretty safe and robust? The one unknown I wonder about is whether there is any code on the backend that is tracking the "actioning" of the dismisses... I see that Also, there are filters that are called when actions are triggered:
Thinking about this more right now though... why does your implementation of calling I'm beginning to question whether this is the correct approach to fixing the issue. POSSIBLE SOLUTION We believe the heart of the problem is that some actions have a
We don't have any guarantee that the Here is a quick test I did changing the implementation... onClick={ async ( event ) => {
const url = event.currentTarget.getAttribute( 'href' );
event.preventDefault();
console.log( 'triggering action...' );
await triggerNoteAction( alert.id, action.id );
console.log( '...action triggered' );
if ( url ) {
console.log( `navigating to url (${ url })...` );
window.location.href = url;
}
} }This should guarantee that the note action is triggered before we navigate. We could even go further and "ignore" |
|
Just o let you know that in the inbox list we actually have a dismiss button and not an |
|
Closed in favor of #38047 |


Submission Review Guidelines:
Changes proposed in this Pull Request:
We were having issues with Undismissable notices.
Currently we have multiple messages that manually add a "Dismiss" button, which need to have a url to navigate to. This is not ideal because it can create a race condition, and also, navigating outside the home page when dismissing an alert doesn't make sense.
I'm adding an X button for all alerts which should always dismiss it.
Closes #36913 .
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
DELETE FROM wp_customer_wc_admin_notes;andDELETE FROM wp_customer_wc_admin_note_actions;