-
-
Notifications
You must be signed in to change notification settings - Fork 719
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
Changes from 2 commits
1580d53
f8d3467
76fdf37
5be53a4
243a4a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should rename this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fixed here: 5be53a4 |
||
|
||
def self.for(user, action_name) | ||
stored_preferences = where(user_id: user.id, action_name:) | ||
default_preferences = __send__("#{action_name}_columns") | ||
default_preferences = get_default_preferences(action_name, user) | ||
filter(default_preferences, user, action_name) | ||
default_preferences.each_with_object([]) do |(column_name, default_attributes), preferences| | ||
stored_preference = stored_preferences.find_by(column_name:) | ||
|
@@ -36,7 +37,7 @@ def self.for(user, action_name) | |
end | ||
|
||
def self.valid_columns_for(action_name) | ||
__send__("#{action_name}_columns").keys.map(&:to_s) | ||
get_default_preferences(action_name, Spree::User.new).keys.map(&:to_s) | ||
end | ||
|
||
def self.known_actions | ||
|
@@ -52,4 +53,13 @@ def self.filter(default_preferences, user, action_name) | |
|
||
default_preferences.delete(:schedules) | ||
end | ||
|
||
def self.get_default_preferences(action_name, user) | ||
case action_name | ||
when 'products_v3_index' | ||
products_v3_index_columns(user) | ||
else | ||
__send__("#{action_name}_columns") | ||
end | ||
end | ||
rioug marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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' : '') } | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's the existing style: openfoodnetwork/app/webpacker/css/admin/products_v3.scss Lines 185 to 195 in 6849155
We need it because JS takes time to load and hide the column. Using it in the HTML immediately hides it when necessary. |
||||||||||||||||||||||||
%colgroup | ||||||||||||||||||||||||
-# The `min-width` property works in Chrome but not Firefox so is considered progressive enhancement. | ||||||||||||||||||||||||
%col.col-image{ width:"44px" }= # (image size + padding) | ||||||||||||||||||||||||
|
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.
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.
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.
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.