-
-
Notifications
You must be signed in to change notification settings - Fork 708
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
[BUU] Change name of my products 🚧 #11208
Merged
filipefurtad0
merged 18 commits into
openfoodfoundation:master
from
dacook:buu-editing-11059
Aug 24, 2023
+716
−87
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a98242e
Capybara: enable_aria_label
dacook ae3cd6f
Add bulk_update product form for product name
dacook 6ffe1ec
Retain the order of products in the collection
dacook 71c3658
Retain order when saving.
dacook a0dba00
Attempt to save all records in bulk update
dacook a70f392
Show error messages
dacook ef63c52
Aggregate errors
dacook 565ea23
Hide borders from inputs until hover
dacook be24247
[wip] Left line for row hover
dacook 2b09ec7
[fixup] Left line for row hover
dacook 8440c44
Remove unused style
dacook 37d1113
Align row headers with input contents
dacook 3cc5d7b
Copy form styles to v3
dacook 7bf7944
Update link colours to match new design
dacook fccde96
Enable 'medium' style for reset buttons
dacook b0e77df
Style form actions area
dacook 2edf504
Ignore long classes for now
dacook a8d37d0
Apply suggestions from code review
dacook File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,74 @@ | ||
%table.products | ||
%col{ width:"15%" } | ||
%col{ width:"5%", style: "max-width:5em" } | ||
%col{ width:"8%" } | ||
%col{ width:"5%", style: "max-width:5em"} | ||
%col{ width:"5%", style: "max-width:5em"} | ||
%col{ width:"10%" }= # producer | ||
%col{ width:"10%" } | ||
%col{ width:"5%" } | ||
%col{ width:"5%", style: "max-width:5em" } | ||
%thead | ||
%tr | ||
%th.align-left= t('admin.products_page.columns.name') | ||
%th.align-right= t('admin.products_page.columns.sku') | ||
%th.align-right= t('admin.products_page.columns.unit') | ||
%th.align-right= t('admin.products_page.columns.price') | ||
%th.align-right= t('admin.products_page.columns.on_hand') | ||
%th.align-left= t('admin.products_page.columns.producer') | ||
%th.align-left= t('admin.products_page.columns.category') | ||
%th.align-left= t('admin.products_page.columns.tax_category') | ||
%th.align-left= t('admin.products_page.columns.inherits_properties') | ||
- products.each do |product| | ||
%tbody.relaxed | ||
= form_with url: bulk_update_admin_products_v3_index_path, method: :patch, | ||
html: {'data-reflex-serialize-form': true, 'data-reflex': 'submit->products#bulk_update'} do |form| | ||
.container | ||
.sixteen.columns.align-right | ||
#fieldset | ||
/ = t('.products_modified', count: 'X') | ||
= form.submit t('.reset'), type: :reset | ||
= form.submit t('.save') | ||
%table.products | ||
%col{ width:"15%" } | ||
%col{ width:"5%", style: "max-width:5em" } | ||
%col{ width:"8%" } | ||
%col{ width:"5%", style: "max-width:5em"} | ||
%col{ width:"5%", style: "max-width:5em"} | ||
%col{ width:"10%" }= # producer | ||
%col{ width:"10%" } | ||
%col{ width:"5%" } | ||
%col{ width:"5%", style: "max-width:5em" } | ||
%thead | ||
%tr | ||
%td.align-left.header | ||
.line-clamp-1= product.name | ||
%td.align-right | ||
.line-clamp-1= product.sku | ||
%td.align-right | ||
.line-clamp-1 | ||
= product.variant_unit.upcase_first | ||
/ TODO: properly handle custom unit names | ||
= WeightsAndMeasures::UNITS[product.variant_unit] && "(" + WeightsAndMeasures::UNITS[product.variant_unit][product.variant_unit_scale]["name"] + ")" | ||
%td.align-right | ||
-# empty | ||
%td.align-right | ||
-# TODO: new requirement "DISPLAY ON DEMAND IF ALL VARIANTS ARE ON DEMAND". And translate value | ||
.line-clamp-1= if product.variants.all?(&:on_demand) then "On demand" else product.on_hand || 0 end | ||
%td.align-left | ||
.line-clamp-1= product.supplier.name | ||
%td.align-left | ||
.line-clamp-1= product.primary_taxon.name | ||
%td.align-left | ||
%td.align-left | ||
.line-clamp-1= product.inherits_properties ? 'YES' : 'NO' #TODO: consider using https://github.com/RST-J/human_attribute_values, else use I18n.t (also below) | ||
- product.variants.each do |variant| | ||
%tr.condensed | ||
%td.align-left | ||
.line-clamp-1= variant.display_name | ||
%td.align-right | ||
.line-clamp-1= variant.sku | ||
%td.align-right | ||
.line-clamp-1= variant.unit_to_display | ||
%td.align-right | ||
.line-clamp-1= number_to_currency(variant.price) | ||
%td.align-right | ||
.line-clamp-1= variant.on_hand || 0 #TODO: spec for this according to requirements. | ||
%td.align-left | ||
.line-clamp-1= variant.product.supplier.name # same as product | ||
%td.align-left | ||
-# empty | ||
%td.align-left | ||
.line-clamp-1= variant.tax_category&.name || "None" # TODO: convert to dropdown, else translate hardcoded string. | ||
%td.align-left | ||
-# empty | ||
|
||
%th.align-left= t('admin.products_page.columns.name') | ||
%th.align-right= t('admin.products_page.columns.sku') | ||
%th.align-right= t('admin.products_page.columns.unit') | ||
%th.align-right= t('admin.products_page.columns.price') | ||
%th.align-right= t('admin.products_page.columns.on_hand') | ||
%th.align-left= t('admin.products_page.columns.producer') | ||
%th.align-left= t('admin.products_page.columns.category') | ||
%th.align-left= t('admin.products_page.columns.tax_category') | ||
%th.align-left= t('admin.products_page.columns.inherits_properties') | ||
- products.each do |product| | ||
= form.fields_for(product) do |product_form| | ||
%tbody.relaxed | ||
%tr | ||
%td.align-left.header | ||
.line-clamp-1= product_form.text_field :name, name: "[products][#{product.id}][name]", id: "_product_name_#{product.id}", 'aria-label': t('admin.products_page.columns.name') | ||
%td.align-right | ||
.line-clamp-1= product.sku | ||
%td.align-right | ||
.line-clamp-1 | ||
= product.variant_unit.upcase_first | ||
/ TODO: properly handle custom unit names | ||
= WeightsAndMeasures::UNITS[product.variant_unit] && "(" + WeightsAndMeasures::UNITS[product.variant_unit][product.variant_unit_scale]["name"] + ")" | ||
%td.align-right | ||
-# empty | ||
%td.align-right | ||
-# TODO: new requirement "DISPLAY ON DEMAND IF ALL VARIANTS ARE ON DEMAND". And translate value | ||
.line-clamp-1= if product.variants.all?(&:on_demand) then "On demand" else product.on_hand || 0 end | ||
%td.align-left | ||
.line-clamp-1= product.supplier.name | ||
%td.align-left | ||
.line-clamp-1= product.primary_taxon.name | ||
%td.align-left | ||
%td.align-left | ||
.line-clamp-1= product.inherits_properties ? 'YES' : 'NO' #TODO: consider using https://github.com/RST-J/human_attribute_values, else use I18n.t (also below) | ||
- product.variants.each do |variant| | ||
%tr.condensed | ||
%td.align-left | ||
.line-clamp-1= variant.display_name | ||
%td.align-right | ||
.line-clamp-1= variant.sku | ||
%td.align-right | ||
.line-clamp-1= variant.unit_to_display | ||
%td.align-right | ||
.line-clamp-1= number_to_currency(variant.price) | ||
%td.align-right | ||
.line-clamp-1= variant.on_hand || 0 #TODO: spec for this according to requirements. | ||
%td.align-left | ||
.line-clamp-1= variant.product.supplier.name # same as product | ||
%td.align-left | ||
-# empty | ||
%td.align-left | ||
.line-clamp-1= variant.tax_category&.name || "None" # TODO: convert to dropdown, else translate hardcoded string. | ||
%td.align-left | ||
-# empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that this is necessary when you want to support creating several new products in the same form. Then you can't use the id as index. But I find this approach of stuffing all kind of data into one action unnecessarily complex. Doing lots of stuff at once has the challenge of lots of things potentially failing and providing lots of error feedback while also adding a lot of logic regarding different actions to one thing. In this case the ModelSet encapsulates it quite well but it's still complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points. At this stage, we want to provide that behaviour (updating multiple at once) so I think it makes sense to use the one form, for now. So far we haven't hit any issues with this method, so I'd avoid complicating it. For now..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about new products or deleting products? Will there be a separate form or UX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume, new products will continue to be with a specific form, and deleting would be one-by-one.
But if we needed to do it in bulk here, then we could.. but like you say it makes things complicated!