Skip to content

Conversation

@louwie17
Copy link
Contributor

@louwie17 louwie17 commented Nov 25, 2022

All Submissions:

Changes proposed in this Pull Request:

This add's initial logic to make it easy to track if users leave pages with un-saved changes, for showing a feedback notice.
This would only be enabled if the user has enabled tracking.

Partially addresses #35126 .

Kapture.2022-11-25.at.11.16.31.mp4

How to test the changes in this Pull Request:

  1. Load this branch, build it, and make sure you have the new-product-management-experience feature flag enabled (you can do so using the latest version of the Beta tester within the mono repo).
  2. Make sure you have tracks enabled and also outputted in the console: localStorage.setItem( 'debug', 'wc-admin:*' );
  3. Go to Product > Add New and make some changes
  4. Now go to another page like WooCommerce > Home and select Leave when it warns you about unsaved changes.
  5. A notice should show on the new page that allows you to share feedback, something to the affect of We noticed you started editing a product, then left....
  6. Click the share feedback and submit feedback, notice how the wcadmin_ces_snackbar_view, wcadmin_ces_view, and wcadmin_ces_feedback include the ces_location prop with the outside value.
    You may also want to try dismissing the notice and see if the prop has been added to wcadmin_ces_snackbar_dismiss
  7. Repeat steps 4-6 for all these pages: Product edit page, New product MVP page, edit product MVP page.
  8. Now delete the woocommerce_ces_shown_for_actions option and disable tracking under WooCommerce > Settings > Advanced > Woocommerce.com
  9. Make sure the notice doesn't show up for the above anymore and that customer-effort-score-exit-page in local storage does not get updated, but stays empty.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added focus: react admin plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Nov 25, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2022

Test Results Summary

Commit SHA: 104a1e3

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 50s
E2E Tests187006019313m 18s

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.

}
window.addEventListener( 'beforeunload', function ( event ) {
// Check if button disabled or triggered delete to see if user saved or deleted the product instead.
if ( checkIfSubmitButtonsDisabled() || triggeredDelete ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the comment implies, it was hard to differentiate if the beforeunload was happening because a user was saving or deleting a product or if they were exiting.
These two checks were the main differentiator I could add to check against this.

@louwie17 louwie17 force-pushed the add/35126_ces_exit_prompt branch from 4b85bcd to d919d68 Compare November 28, 2022 09:27
@louwie17 louwie17 marked this pull request as ready for review November 28, 2022 09:28
@louwie17 louwie17 self-assigned this Nov 29, 2022
@octaedro octaedro self-requested a review December 2, 2022 13:02
Comment on lines 1 to 4
export const SHOWN_FOR_ACTIONS_OPTION_NAME =
'woocommerce_ces_shown_for_actions';
export const ADMIN_INSTALL_TIMESTAMP_OPTION_NAME =
'woocommerce_admin_install_timestamp';
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't find the place where these two const are being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aaah yeah, I kinda copy pasted them from another PR, that one is merged now, so all of them should be used in a couple other files now.


let items = getExitPageData();

items = items.filter( ( item ) => item !== pageId );
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not clear about this part. Why do we remove the item from the array and add it again?
Maybe we can check if the item is present in the array and add it if not.
It would look like this:

if ( ! items.find( ( pageExitedId ) => pageExitedId === pageId ) ) {
    items.push( pageId );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplicity mostly, but I can use your approach as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also to make sure we never have duplicates.


let items = getExitPageData();

items = items.filter( ( item ) => item !== pageId );
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about renaming item to pageExitedId or something less generic?

}

/**
* checks the exit page list and triggers a CES survey for the first item in the list.
Copy link
Contributor

Choose a reason for hiding this comment

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

Really nitpick: it should start with a capital letter.

Copy link
Contributor

@octaedro octaedro left a comment

Choose a reason for hiding this comment

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

Fantastic work @louwie17! The code looks good and it's testing pretty well here. I only left a couple of small comments and I saw something unexpected when I was saving the product.

Screenshot 2022-12-02 at 10 35 19

@louwie17 louwie17 force-pushed the add/35126_ces_exit_prompt branch from 049815d to a8ee37c Compare December 8, 2022 09:50
@louwie17
Copy link
Contributor Author

louwie17 commented Dec 8, 2022

Thanks for the review @octaedro, I addressed your PR feedback and fixed the issue you found. This should be ready for re-review.

@louwie17 louwie17 requested a review from octaedro December 8, 2022 09:51
@github-actions github-actions bot added the package: @woocommerce/customer-effort-score issues related to @woocommerce/customer-effort-score label Dec 9, 2022
@louwie17 louwie17 force-pushed the add/35126_ces_exit_prompt branch from 9ebe306 to 104a1e3 Compare December 12, 2022 10:27
isResolving( 'getOption', [ ALLOW_TRACKING_OPTION_NAME ] );
! hasFinishedResolution( 'getOption', [
ALLOW_TRACKING_OPTION_NAME,
] );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made use of hasFinishedResolution to fix a bug where if one of the above options was being retrieved again isResolving would be set to true again, which in turn set resolving to true and in turn caused this component to return null.
Once the resolving finished it would render the CustomerEffortScore again and in turn trigger a new notice, something we don't want.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

@louwie17 louwie17 force-pushed the add/35126_ces_exit_prompt branch from 96eb9af to 104a1e3 Compare December 12, 2022 13:16
Copy link
Contributor

@octaedro octaedro left a comment

Choose a reason for hiding this comment

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

Thank you for adding the changes! LGTM 🚀
Good job @louwie17

@louwie17 louwie17 merged commit 613e58c into trunk Dec 12, 2022
@louwie17 louwie17 deleted the add/35126_ces_exit_prompt branch December 12, 2022 13:56
@github-actions github-actions bot added this to the 7.3.0 milestone Dec 12, 2022
samueljseay pushed a commit that referenced this pull request Dec 15, 2022
* Add exit page tracker logic and implement it for product pages

* Add changelog

* Fix lint errors and add comments

* Add ces_location prop

* Add mock to fix broken test

* Add CES exit page survey tests

* Fix a bug with React pages redirects and update actions

* Fix test

* Fix lint

* Add default inside location prop

* Remove exit prefix within action

* Address PR feedback and make sure its not triggered on save

* Update copy of exit feedback notice

* Add changelog

* Update name of param

* Fix lint error

* Use hasFinishedResolution vs isResolved in customerEffortScoreTracks
@louwie17 louwie17 mentioned this pull request Jan 12, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: @woocommerce/customer-effort-score issues related to @woocommerce/customer-effort-score plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants