Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Conversation

@louwie17
Copy link
Contributor

@louwie17 louwie17 commented Oct 4, 2021

Fixes #7741

Add status query param to delete_all_notes so query is run correctly.
The underlying issue was that the delete/all query queried for any status, causing the notes to be returned to be greater than 25 (the page limit). Although on our client we only display unactioned notes, I added support for this query arg.

note
I only added support for status to fix this particular issue. We could potentially support any query arg in the same way we support this for the notes/all endpoint.

Screenshots

dismiss-all-notes

Detailed test instructions:

  • Load this branch
  • On a fresh WC installation finish the Onboarding flow, make sure you install all the free extensions (important).
  • Go to WooCommerce > Home and scroll down to the notes
  • Click on Dismiss of one of the notes and click Dismiss all messages
  • Click Yes, I'm sure
  • Note that all notes should be removed and the empty inbox message should show up (see GIF as well)
  • Click undo on the little notice that pops up in the bottom left, and make sure all the notes appeared again.

@mattsherman
Copy link
Contributor

causing the notes to be returned to be greater than 25 (the page limit)

So, would we still see this issue if there were more than 25 unactioned notes?

Copy link
Contributor

@mattsherman mattsherman left a comment

Choose a reason for hiding this comment

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

Tested, works as expected. Nice work.

Left a comment about unit tests -- I think it would be good to have a unit test or two in place to test this new functionality.

I also left a general question about whether this issue would will crop up if there were actually more than 25 unactioned notes. I think it is okay for now to live with that limitation if that is the case. However, we should add a new issue in the backlog about that, so we don't forget to cycle back and full address it later.

'methods' => \WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_all_items' ),
'permission_callback' => array( $this, 'update_items_permissions_check' ),
'args' => array(
Copy link
Contributor

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 unit test(s) around this new capability.

public function test_delete_all_notes() {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattsherman good suggestion, I added a test case here: 39a4647

@joshuatf
Copy link
Contributor

joshuatf commented Oct 4, 2021

So, would we still see this issue if there were more than 25 unactioned notes?

I think it will delete the first 25, but the next deletion would get the subsequent 25 since it filters by is_deleted. So you can only dismiss 25 at a time.

Not sure if this is better or genuinely deleting all. I can see an argument being made for either case.

@mattsherman
Copy link
Contributor

Not sure if this is better or genuinely deleting all. I can see an argument being made for either case.

Yeah, I too think this might actually be desirable behavior. Any time the store merchant is dealing with more than 25 inbox notes, I would be concerned that they might mistakenly delete ones they didn't notice. Of course, the UI then "lies" by saying "Delete All", but is it really that harmful of a lie? :-) If a merchant really wanted to get rid of any of the remaining notes, they would likely try "Delete All" again before contacting support.

@louwie17
Copy link
Contributor Author

louwie17 commented Oct 5, 2021

Yeah, I too think this might actually be desirable behavior. Any time the store merchant is dealing with more than 25 inbox notes, I would be concerned that they might mistakenly delete ones they didn't notice. Of course, the UI then "lies" by saying "Delete All", but is it really that harmful of a lie? :-) If a merchant really wanted to get rid of any of the remaining notes, they would likely try "Delete All" again before contacting support.

Yeah I was thinking something similar, given we only display 25 max on the client, I would take 'Delete all' to mean, delete all the one's visible, not the one's invisible. Although this would almost require some kind of page identifier, we are displaying 25, but there are more.
This is why I didn't change the page size, and kept it the same as the client.

wp_set_current_user( $this->user );

// It deletes only unactioned notes.
$request = new WP_REST_Request( 'DELETE', $this->endpoint . '/delete/all' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a side comment... that's pretty bizarre that our API uses both the DELETE HTTP verb and a URL that includes /delete... such a mismash.

Copy link
Contributor

@mattsherman mattsherman left a comment

Choose a reason for hiding this comment

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

Thanks for adding the unit test! I had trouble with my unit testing setup locally, but the test code looks valid so I think this is good to go!

@louwie17 louwie17 merged commit 66603e6 into main Oct 5, 2021
@louwie17 louwie17 deleted the fix/7741_dismiss_all_notes branch October 5, 2021 18:37
mattsherman pushed a commit that referenced this pull request Oct 6, 2021
* Add status param support for dismissing all notes

* Add changelog

* Add unit test for new arg in /delete/all endpoint
ObliviousHarmony pushed a commit to woocommerce/woocommerce that referenced this pull request Mar 18, 2022
…merce-admin#7743)

* Add status param support for dismissing all notes

* Add changelog

* Add unit test for new arg in /delete/all endpoint
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GlobalStep - 2.8.0 Beta-1] Some inbox messages fail to dismiss upon clicking the "Dismiss all messages" option on "WooCommerce >> Home" screen.

4 participants