Skip to content
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

[Product Refactor] Move variant unit sizes to variant #12787

Open
wants to merge 68 commits into
base: master
Choose a base branch
from

Conversation

rioug
Copy link
Collaborator

@rioug rioug commented Aug 19, 2024

⚠️ Please use clockify code #9105 REST API - Products when working on this ⚠️

What? Why?

Last step of the first part of product refactor #9069
Move variant unit sizes to variant :

  • variant_unit,
  • variant_unit_scale,
  • variant_unit_name

Review Note:

We should really refactor app/webpacker/controllers/variant_controller.js and app/webpacker/controllers/variant_controller.js to extract anything that's common for the "unit popout". We could probably move it to component. This PR is already big enough so I did not want to do it here.

What should we test?

Anything that touches unit sizes (non exhaustive list), check that unit sizes are displayed properly and can be updated when applicable :

  • Create a new Product
  • Create a new Variant
  • Update a variant
  • Bulk product edit page legacy, create/update variant
  • Bulk product edit page create/update variant
  • Inventory page
  • Producer shop page
  • order and fulfilment report

Update variant page, I replaced angular with StimulusJS, beside checking unit sizes check there is no feature loss.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@rioug rioug force-pushed the move-variant-unit-attributes-to-variant branch from 29d26d0 to 07c2b4e Compare August 19, 2024 05:41
@rioug rioug marked this pull request as ready for review August 19, 2024 05:48
@dacook dacook self-requested a review August 20, 2024 01:05
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Reviewed first half(up to "Prettify javascript").

Sorry lots of comments, mostly just comprehension but I have a few queries as well.

app/models/spree/variant.rb Show resolved Hide resolved
app/models/spree/variant.rb Outdated Show resolved Hide resolved
app/models/spree/variant.rb Show resolved Hide resolved
app/models/product_import/entry_validator.rb Show resolved Hide resolved
Comment on lines +89 to +90
# updating variant doesn't increment saved_count
# expect(product_set.saved_count).to eq 1
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Hmm, it probably should..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, this PR was not the place for it though

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Review in progress:

  • Fix DFC supplied product builder

@mkllnk mkllnk added the api changes These pull requests change the API and can break integrations label Aug 21, 2024
Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Epic! Great that you improved the code along the way and fixed little things.

I have to admit that I didn't read every line. But it looks pretty robust.

app/models/spree/product.rb Outdated Show resolved Hide resolved
app/models/spree/product.rb Show resolved Hide resolved
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Phew, done!
I have several comments, probably not all of them need changes, but I think some do (whether now or in a follow-up PR).
I will review my own review and mark any required changes with a ± in the comment.

Comment on lines +21 to +27
price = parseFloat(price);

if (isNaN(price)) {
return null;
}

return price;
Copy link
Member

Choose a reason for hiding this comment

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

This code made sense in the beautifully terse coffeescript, but the ugly JS caused me to wonder if this works just as well:

Suggested change
price = parseFloat(price);
if (isNaN(price)) {
return null;
}
return price;
return parseFloat(price) || null

It's not 100% the same logic, but the specs should be able to tell us if it matters or not.

app/webpacker/controllers/edit_variant_controller.js Outdated Show resolved Hide resolved
spec/lib/spree/core/product_duplicator_spec.rb Outdated Show resolved Hide resolved
spec/system/admin/products_v3/actions_spec.rb Outdated Show resolved Hide resolved
spec/system/admin/products_v3/update_spec.rb Show resolved Hide resolved
spec/system/admin/products_v3/update_spec.rb Show resolved Hide resolved
app/models/spree/product.rb Show resolved Hide resolved
app/models/spree/product.rb Show resolved Hide resolved
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

I've added some ± and one ❓ that I think require addressing, can you please check these?
Other comments might be worth addressing too, but I don't consider them blocking.

@rioug rioug force-pushed the move-variant-unit-attributes-to-variant branch from 333e7bc to 57eee15 Compare August 27, 2024 01:07
@rioug rioug requested review from dacook and mkllnk August 27, 2024 01:22
spec/system/admin/products_v3/update_spec.rb Outdated Show resolved Hide resolved
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

🏅 Awesome, an epic job!

@dacook dacook added the priority We focus on this issue right now label Aug 27, 2024
@drummer83
Copy link
Contributor

@rioug There's a conflict here, sorry. Could you please have a look?
Also Github is asking for more reviews. Do we need that?

@rioug rioug force-pushed the move-variant-unit-attributes-to-variant branch from d10359a to a2c4fd5 Compare September 2, 2024 05:24
@rioug
Copy link
Collaborator Author

rioug commented Sep 2, 2024

@drummer83 it's now ready to go.

@mkllnk
Copy link
Member

mkllnk commented Sep 3, 2024

@rioug, sorry, just created another merge conflict.

@rioug rioug force-pushed the move-variant-unit-attributes-to-variant branch from a2c4fd5 to 76cd3e2 Compare September 3, 2024 05:05
@rioug
Copy link
Collaborator Author

rioug commented Sep 3, 2024

@rioug, sorry, just created another merge conflict.

Sorted !

@rioug
Copy link
Collaborator Author

rioug commented Sep 3, 2024

Simplecov failed, I think it's because it re ran only the failed jobs, maybe something we need to look into.

Anyway, it doesn't block merging.

@drummer83 drummer83 self-assigned this Sep 4, 2024
@drummer83 drummer83 added the pr-staged-au staging.openfoodnetwork.org.au label Sep 4, 2024
@drummer83
Copy link
Contributor

Hi @rioug,

I'm sorry, I'm getting an error 500 on the /admin/products page on staging AU.
Bugsnag is here: https://app.bugsnag.com/yaycode/openfoodnetwork-aus/errors?filters[event.since]=30d&filters[error.status]=open&filters[app.release_stage]=staging

I'll move this back to In Progress until fixed. 🙏

@drummer83 drummer83 removed the pr-staged-au staging.openfoodnetwork.org.au label Sep 4, 2024
rioug and others added 25 commits September 30, 2024 11:46
- make sure the weight is only cleared when needed
- make sure the displayed unit is up to date
I disabled Metrics/AbcSize for ensure_standard_variant as I don't think
that's hard to understand the code. And utimately it will be removed
once product actually becomes optional.
The current spec is useless, but it has been addressed on master
After the product redactor it only checked for the "description" on
product, which is actually skipped when doing an update.
Client side validation messages depend on the browser's locale, which
we have no controll over. Now we just check a message is set.
There is no easy way to make the original product invalid, but we can
make sure the cloned product will be invalid. The cloned product add
"COPe OF " in front of the product's name, so by starting with a name
that's long enough, the cloned product will have a name longer that 255
char and will then be invalid.
@rioug rioug force-pushed the move-variant-unit-attributes-to-variant branch from 46d9ca7 to ee4f775 Compare September 30, 2024 01:47
@rioug
Copy link
Collaborator Author

rioug commented Sep 30, 2024

Hi @filipefurtad0,
I am not sure how you "deleted the migration" but is look likes it wasn't done from a database perspective. I fixed the database on both au-staging and fr-staging.

FYI if you need to retest the migration, while this PR is staged, you can run the following to revert the migration done by the PR:

bundle exec rails db:migrate:down VERSION=20240819045115
bundle exec rails db:migrate:down VERSION=20240618013850

However, I can see some issues pointed by @drummer83 are still relevant, like being able to select an empty unit value, when creating an product in the products page:

To be clear this has not been fixed so it's expected to be able to select an empty unit value (Rachel is happy for this to be fixed later on). However, if a variant was created before the PR, it shouldn't have an empty unit value after the PR has been staged.

@rioug rioug removed pr-staged-au staging.openfoodnetwork.org.au feedback-needed labels Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api changes These pull requests change the API and can break integrations priority We focus on this issue right now
Projects
Status: Test Ready 🧪
Development

Successfully merging this pull request may close these issues.

7 participants