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

12570 - Fix Variant Unit field is Out of Sync with the Pop-out #12602

Conversation

chahmedejaz
Copy link
Collaborator

@chahmedejaz chahmedejaz commented Jun 23, 2024

What? Why?

  • Closes [BUU] Unit field is out of sync with the popout #12570
  • We are creating a new variant object and passing it to the new variant row.
  • This variant is empty and hence has no unit_value present in it, due to which display_as field is also empty and variant is unable to be saved.
  • This PR creates and uses the helper to build this new variant object such that it has the unit_value of 1 x variant_unit_scale,
  • When the variant unit_value is present, then it sets the placeholder value for the display_as field, which was empty

What should we test?

  • The expected behavior mentioned in the issue should meet

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

@chahmedejaz chahmedejaz self-assigned this Jun 23, 2024
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 guess this solves it by ensuring there's value in the underlying field, but I don't see an answer as to why it was out of sync with what's displayed on the screen.

Looking at _variant_row.html.haml, I can see that unit_value_with_description introduces a default of 1, when unit_value is blank.

Your solution ensures unit_value is never blank, with a different default from the last variant. I think 1 is a better default (at least that's the current behaviour).

So I think that your helper should provide a default of 1, and we can remove the 1 from _variant_row.

@dacook
Copy link
Member

dacook commented Jun 24, 2024

Oh, it might be event more complicated than that.

We want variant_unit_scale to inherit from the product too. This affects what 1 means. We want the unit_value_with_description to appear as "1", for whatever the variant_unit_scale is (whether 1, or 1000 for example).

Sorry, this system is really complicated, it took me ages to understand it, and I was too tired to try and document it. I've created a screenshot to help: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Product-amounts-units#current-state

Also I have a diagram I drew to show the relationship between fields: (edit: moved diagram to wiki also )

@chahmedejaz
Copy link
Collaborator Author

Sure, thanks, David. I'll dig into this a bit more.

@dacook
Copy link
Member

dacook commented Jul 11, 2024

Hi @chahmedejaz , just letting you know there are more conflicts on the way 😞
Gaetan is currently working on move-variant-unit-attributes-to-variant (part of Product Refactor).
His PR won't be ready until at least next week though.

@chahmedejaz
Copy link
Collaborator Author

Hi @chahmedejaz , just letting you know there are more conflicts on the way 😞
Gaetan is currently working on move-variant-unit-attributes-to-variant (part of Product Refactor).
His PR won't be ready until at least next week though.

Thanks for the heads up @dacook. I'll wrap this ASAP.

- New variant unit_value is empty, so +VariantUnits::OptionValueNamer.new(variant).name+ returns ""
- Now we are making sure that new variant unit_value won't be empty
@chahmedejaz chahmedejaz force-pushed the bugfix/12570-variant-unit-field-out-of-sync branch from 2553945 to d835429 Compare July 12, 2024 13:03
@chahmedejaz
Copy link
Collaborator Author

I guess this solves it by ensuring there's value in the underlying field, but I don't see an answer as to why it was out of sync with what's displayed on the screen.
Looking at _variant_row.html.haml, I can see that unit_value_with_description introduces a default of 1, when unit_value is blank.

Sorry I just noticed the description of PR is kind of misleading, I've updated it now.
Moreover, here's a brief loom on the issue. Please review and let me know if you have any questions.
https://www.loom.com/share/fcd1e9c7991a456ba55ee6a9f67ba16d

@chahmedejaz
Copy link
Collaborator Author

@dacook - PR is ready for review now. Thanks

@chahmedejaz chahmedejaz marked this pull request as ready for review July 12, 2024 14:03
@chahmedejaz chahmedejaz requested a review from dacook July 12, 2024 14:03
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

That looks good, thanks @chahmedejaz !
It's going to clash with the product refactor but I'll address that in due time.

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.

Yay, thanks for fixing this longrunning issue!

I think this is good, but I have a few questions where I think the code could be simpler.

app/views/admin/products_v3/_variant_row.html.haml Outdated Show resolved Hide resolved
spec/system/admin/products_v3/create_spec.rb Outdated Show resolved Hide resolved
spec/system/admin/products_v3/create_spec.rb Outdated Show resolved Hide resolved
@chahmedejaz
Copy link
Collaborator Author

Yay, thanks for fixing this longrunning issue!

I think this is good, but I have a few questions where I think the code could be simpler.

@dacook - I've addressed your comments in this commit here: 5b7fbc8 Thanks.

@chahmedejaz chahmedejaz requested a review from dacook July 15, 2024 17:57
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.

Looks great!

@drummer83 drummer83 self-assigned this Jul 18, 2024
@drummer83 drummer83 added no-staging-AU A tag which does not trigger deployments, indicating a server is being used pr-staged-au staging.openfoodnetwork.org.au and removed no-staging-AU A tag which does not trigger deployments, indicating a server is being used labels Jul 18, 2024
@drummer83
Copy link
Contributor

Hi @chahmedejaz,
Thanks for working on this fix.

Before staging

I could not reproduce the exact original issue:

  • After adding a new variant I was able to save without error (as long as any other information was changed).
  • The unit value was always set in such way that it will be displayed as 1 g (or 1 L for Volume):
    • 0.001 for Weight (kg)
    • 1 for Weight (g)
    • 1000 for Weight (mg)
  • The unit value however is only displayed after changing it (it returns to blank if closing the pop-out without changing the value).

After staging

  • The unit value is always set to 1.
  • The unit value is immediately displayed after adding the new variant.

Conclusion

I found no issues with your solution.
Ready to go! 🚀 Merging!! 🥳
Thanks again!

@drummer83 drummer83 merged commit 4c9507c into openfoodfoundation:master Jul 18, 2024
54 checks passed
@drummer83 drummer83 removed the pr-staged-au staging.openfoodnetwork.org.au label Jul 18, 2024
@filipefurtad0 filipefurtad0 added feature toggled These pull requests' changes are invisible by default and are grouped in release notes user facing changes Thes pull requests affect the user experience labels Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature toggled These pull requests' changes are invisible by default and are grouped in release notes user facing changes Thes pull requests affect the user experience
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BUU] Unit field is out of sync with the popout
5 participants