Skip to content

Conversation

@mdperez86
Copy link
Contributor

@mdperez86 mdperez86 commented Nov 21, 2022

All Submissions:

Changes proposed in this Pull Request:

Fixes #35194

  • This PR is a very minor change/addition and does not require testing instructions (if checked you can ignore/remove the next section).

How to test the changes in this Pull Request:

  1. Go to Products -> Add New (MVP) page
  2. After change any product field you should publish the product and get redirected to product edit page without seen any prompt modal.

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.

@mdperez86 mdperez86 requested a review from louwie17 November 21, 2022 17:05
@mdperez86 mdperez86 self-assigned this Nov 21, 2022
@github-actions github-actions bot added focus: react admin package: @woocommerce/components issues related to @woocommerce/components plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Nov 21, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 21, 2022

Test Results Summary

Commit SHA: 0605938

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests26000202620m 50s
E2E Tests186006019212m 39s

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.

@mdperez86 mdperez86 marked this pull request as ready for review November 21, 2022 17:58
navigateTo( {
url: 'admin.php?page=wc-admin&path=/product/' + product.id,
} );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic should also be as part of the onSaveDraft function right after line 58.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh!!! you are right. It's done now. Thanks @louwie17

@mdperez86 mdperez86 requested a review from louwie17 November 21, 2022 20:50
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Nice work @mdperez86, this was testing quite well. I did notice a React warning about a component state being changed, which disappeared after passing in the product to the resetForm.
Also let one tiny nit pick comment on the error notice text.

createProductWithStatus( values, 'publish' );
const product = await createProductWithStatus( values, 'publish' );
if ( product?.id ) {
resetForm();
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also pass in the product into the resetForm here.
The transition happens fast enough that the user doesn't notice, but I do get a uncontrolled component has been changed warning if we call it without any product object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, but I don't think the right way is passing the product obj here since we are reseting a creation form not an edition one. Which means that when creating the form starts empty. That why I didn't pass the product obj here. If there is a problem regarding to uncontrolled/controlled is because the invalid initial value of the form at the moment it was mounted. Remember the resetForm takes the form's initialValues by default if we don't pass any obj to the function.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case shouldn't we be resetting it to this object:

{
					reviews_allowed: true,
					name: '',
					sku: '',
					stock_quantity: 0,
					stock_status: 'instock',
				}

Which is the same object we initially start the form with.

createProductWithStatus( values, 'draft' );
const product = await createProductWithStatus( values, 'draft' );
if ( product?.id ) {
resetForm();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as below, we should pass the product into the resetForm here.

( error ) => {
createNotice(
'error',
__( 'Failed to moved product to Trash.', 'woocommerce' )
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be Failed to move product to Trash.
moved -> move

@mdperez86 mdperez86 requested a review from louwie17 November 22, 2022 14:11
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Nice work, and thanks for the updates! LGTM 🚀

@mdperez86 mdperez86 merged commit 29b9c69 into trunk Nov 22, 2022
@mdperez86 mdperez86 deleted the fix/unsaved-prompt branch November 22, 2022 14:56
@github-actions github-actions bot added this to the 7.3.0 milestone Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: @woocommerce/components issues related to @woocommerce/components plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Add a confirmation modal when the user tries to navigate away with unsaved changes

3 participants