Skip to content

Conversation

@joshuatf
Copy link
Contributor

@joshuatf joshuatf commented Oct 6, 2022

All Submissions:

Changes proposed in this Pull Request:

Adds the SKU field and inventory section to the new product management experience.

Closes #34386 .
Screen Shot 2022-10-06 at 7 12 24 AM
Screen Shot 2022-10-06 at 7 12 10 AM
Screen Shot 2022-10-06 at 7 11 59 AM

How to test the changes in this Pull Request:

  1. Visit the new product page Products -> Add new (MVP)
  2. Type in a product name and blur the input
  3. Note the SKU has been added in slug format to the SKU field
  4. Change the SKU to a bad format including non-alphanumeric characters and spaces
  5. Note the error
  6. Make a very long SKU (greater than 160 characters) and note the error
  7. Save and make sure the SKU persists on refresh
  8. Remove the product name so it's empty
  9. Blur the field and make sure the error appears

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 successfully run tests with your changes locally?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> run 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.

@joshuatf joshuatf requested a review from a team October 6, 2022 14:15
@joshuatf joshuatf self-assigned this Oct 6, 2022
@github-actions github-actions bot added focus: react admin plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Oct 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2022

Test Results Summary

Commit SHA: 91ef513

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests18800201900m 44s
E2E Tests124428013813m 46s

⚠️ Warning

Please address the following issues prior to merging this pull request:
  • FAILED/BROKEN TESTS. There were failed and/or broken API and E2E tests.
  • INCOMPLETE E2E TEST RUN. We have a total of 189 E2E tests, but only 138 were executed. Note that in CI, E2E tests automatically end when they encounter too many failures.

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.

@github-actions github-actions bot added the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Oct 6, 2022
@joshuatf
Copy link
Contributor Author

joshuatf commented Oct 7, 2022

Thanks for the review, Maikel! This PR is ready for another look when you have time.

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.

Nice work on this so far, @joshuatf !

My comments mainly revolve around validation.

I totally missed that we were proposing changing the validation rules for SKU in the original issue. I don't think we should do so, since it will introduce compatibility issues with products added via other means (existing UI, API). /cc @pmcpinto @jarekmorawski

@pmcpinto
Copy link

pmcpinto commented Oct 7, 2022

I totally missed that we were proposing changing the validation rules for SKU in the original issue. I don't think we should do so, since it will introduce compatibility issues with products added via other means (existing UI, API). /cc @pmcpinto @jarekmorawski

Good point. I agree with @mattsherman assessment. IMO the benefits of this change don't outweigh the associated risks

mdperez86
mdperez86 previously approved these changes Oct 7, 2022
@github-actions github-actions bot removed the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Oct 10, 2022
@joshuatf
Copy link
Contributor Author

@mattsherman @mdperez86 This PR has been updated to remove any validation/sanitization logic around SKUs. I addressed a couple of @mattsherman's feedback requests, though a follow-up to improve form context callbacks may be a nice addition in the future.

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 trying to improve the onBlur handling, @joshuatf! Unfortunately, I believe that your original implementation, while coupling the different UI sections less-than-ideally, functioned better. I left a comment suggesting we either go back to that implementation or change to an implementation where the SKU is updated on-the-fly as the name field changes.

};

const isNameBlurred = ! prevTouchedName && touched.name;
useEffect( setSkuIfEmpty, [ isNameBlurred ] );
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not handle the scenario where the user:

  1. Focuses on empty name field
  2. Blurs to another field (without first entering anything in name field)
  3. Focuses on empty name field
  4. Enters name
  5. Blurs to another field

Perhaps it would be better to go back to our original implementation, which tied to the onBlur of the field itself. I don't love that, since it couples the two UI implementations more than ideal, but it does work better.

Perhaps the more ideal solution needs to be addressed in the future. Maybe we need a way to hook into focus change at the Form level, so we (and extensions) could hook into whether the focus changed from one component to another at the Form level.

Or, if you changed the implementation to always update the SKU on the fly as the name value changed, keystroke by keystroke, as long as it was a new product and the user hadn't manually modified the SKU. That would be pretty slick, as long as it wasn't a performance issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was definitely a hacky solution at best. I agree with moving back to the onBlur. I'll open an issue to introduce a state handler to form context so we can detect various state changes to the form outside of specific components.

I've reverted this in 60da981

target="_blank"
type="wp-admin"
onClick={ () => {
recordEvent( 'add_product_inventory_help' );
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't love clean up issues, but perhaps it would be best to address Tracks naming across the board in a follow up clean up issue, so we can get this functionality merged to unblock further MVP work.

As you mention, you were just following existing naming conventions on the new product experience. And, those existing conventions are not in line with best practices/guidelines. /cc @AnnaMag @pmcpinto

@joshuatf
Copy link
Contributor Author

Thanks for the review @mattsherman! I reverted the to the original onBlur method and this PR is ready for another review.

mattsherman
mattsherman previously approved these changes Oct 12, 2022
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.

Nice work on this @joshuatf ! LGTM!

I have tested the latest, and it works as expected, with one ambiguous case. The original acceptance criteria didn't detail this, and I can see reasoning behind either behavior, so I'm going to approve this and we can follow up with a future issue if need be...

Scenario:

  1. User enters in a name (SKU updates automatically)
  2. User clears the SKU
  3. User modifies the name (SKU updates automatically)

It is unclear to me what the "best" behavior is in this scenario... should the SKU stay blank because the user manually cleared it, or should it be auto-filled in, since it was blank? It's easy to clear out the SKU again, so I think that how you have it implemented is the preferred way, but it did not meet my expectations when testing, so I'm raising it for discussion.

/cc @jarekmorawski

@mattsherman
Copy link
Contributor

@joshuatf Btw... I see the failing "Run tests against PR / Runs E2E tests", but the failures appear completely unrelated, so I think it is safe to bypass branch protections.

@joshuatf
Copy link
Contributor Author

Thanks for the quick review, @mattsherman!

It's easy to clear out the SKU again, so I think that how you have it implemented is the preferred way

I think so as well. Worst case scenario, are there any detrimental effects to having a SKU filled in? Or reasons a user might want a blank SKU?

@jarekmorawski if you have an opinion on this, please let us know and we'll follow up with another issue.

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.

Changes still look good to me.

@joshuatf joshuatf merged commit 0ca3f6d into trunk Oct 12, 2022
@joshuatf joshuatf deleted the add/34386 branch October 12, 2022 20:11
@github-actions github-actions bot added this to the 7.1.0 milestone Oct 12, 2022
@github-actions
Copy link
Contributor

Hi @joshuatf, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

@jarekmorawski
Copy link

Worst case scenario, are there any detrimental effects to having a SKU filled in?

I don't think so. I'd go further and say that it's only beneficial since both WooCommerce and many inventory management systems that the merchants use treat the SKU as a product UID. It's perfectly fine to have it filled in again when the name changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Inventory] SKU field

8 participants