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

[BUU2] Hide producer column when there's only one producer in the admin account #12854

Conversation

chahmedejaz
Copy link
Collaborator

@chahmedejaz chahmedejaz commented Sep 10, 2024

What? Why?

What should we test?

  • As mentioned in the issue

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

def prepare_new_variant(product, producer_options)
# e.g producer_options = [['producer name', id]]
product.variants.build do |new_variant|
new_variant.supplier_id = producer_options.first.second if producer_options.one?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If only one producer exists, the producer column will be hidden according to the issue. In that case, the producer should be auto-assigned so that UI doesn't show an error on saving the variant.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nicer to have producer_options as an array of hashes: [ { name: 'producer name', id: id } ], anyway its fine to keep it like this.

@chahmedejaz chahmedejaz changed the title 11200: coniditonally hide producer column [BUU2] Hide producer column when there's only one producer in the admin account Sep 10, 2024
@chahmedejaz chahmedejaz marked this pull request as ready for review September 10, 2024 21:17
@rioug rioug self-requested a review September 10, 2024 23:37
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.

It's a good start but I think we can improve/clarify a few things

spec/system/admin/products_v3/create_spec.rb Show resolved Hide resolved
app/models/column_preference.rb Show resolved Hide resolved
app/helpers/admin/products_helper.rb Outdated Show resolved Hide resolved
@@ -15,10 +15,11 @@ class ColumnPreference < ApplicationRecord
validates :column_name, presence: true, inclusion: { in: proc { |p|
valid_columns_for(p.action_name)
} }
scope :products, -> { where(action_name: 'products_v3_index') }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should rename this to bulk_edit_product so it's clear we are talking about a page and not a product.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's fixed here: 5be53a4

def prepare_new_variant(product, producer_options)
# e.g producer_options = [['producer name', id]]
product.variants.build do |new_variant|
new_variant.supplier_id = producer_options.first.second if producer_options.one?
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nicer to have producer_options as an array of hashes: [ { name: 'producer name', id: id } ], anyway its fine to keep it like this.

spec/system/admin/products_v3/actions_spec.rb Show resolved Hide resolved
@rioug rioug added the user facing changes Thes pull requests affect the user experience label Sep 11, 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.

Great, this has been on the list of things to do for a long time! I like the solution using the column defaults: it means the user can still choose to show it if they want to.

But it looks like there's some leftover code to remove?

# if user hasn't saved any preferences on products page and there's only one producer;
# we need to hide producer column
def hide_producer_column?(producer_options)
spree_current_user.column_preferences.bulk_edit_product.empty? && producer_options.one?
Copy link
Member

Choose a reason for hiding this comment

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

It seems unnecessary to create a scope for this single use. I think using the where command directly would have been fine here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think scopes are a more cleaner way to query, don't you think? 😅

Copy link
Member

Choose a reason for hiding this comment

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

I guess it's a matter of personal preference. In general, yes it's better to use a scope which ensures the logic about the model, is in the model 👍

@@ -13,7 +13,7 @@
= hidden_field_tag :producer_id, @producer_id
= hidden_field_tag :category_id, @category_id

%table.products{ 'data-column-preferences-target': "table" }
%table.products{ 'data-column-preferences-target': "table", class: (hide_producer_column?(producer_options) ? 'hide-producer' : '') }
Copy link
Member

Choose a reason for hiding this comment

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

I can't see a CSS rule for this class, did you forget to commit it?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm maybe it's not necessary at all: the column defaults take care of hiding it.
So I guess we don't need this hide_producer_column? helper.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can't see a CSS rule for this class, did you forget to commit it?

It's the existing style:

$columns:
"image", "name", "sku", "unit_scale", "unit", "price", "on_hand", "producer", "category",
"tax_category", "inherits_properties";
@each $col in $columns {
&.hide-#{$col} {
.col-#{$col} {
display: none;
}
}
}
}

the column defaults take care of hiding it.

We need it because JS takes time to load and hide the column. Using it in the HTML immediately hides it when necessary.

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.

Thanks for answering my questions, all good.

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.

Looks good 👍 , Thanks for adding the comments !

@filipefurtad0 filipefurtad0 self-assigned this Sep 19, 2024
@filipefurtad0 filipefurtad0 added pr-staged-fr staging.coopcircuits.fr pr-staged-uk staging.openfoodnetwork.org.uk and removed pr-staged-fr staging.coopcircuits.fr labels Sep 19, 2024
@filipefurtad0
Copy link
Contributor

Hey @chahmedejaz ,

I had a quick test on this one:

Before staging
image

After staging
image

The column is hidden by default, but the user can still opt-in, if desired.

Merging! 🎉

@filipefurtad0 filipefurtad0 merged commit 83ab959 into openfoodfoundation:master Sep 19, 2024
55 of 57 checks passed
@RachL RachL removed pr-staged-uk staging.openfoodnetwork.org.uk pr-staged-fr staging.coopcircuits.fr labels Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user facing changes Thes pull requests affect the user experience
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Hide producer column when there's only one producer in the admin account
5 participants