-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix promotions admin UI inconsistency #5936
Fix promotions admin UI inconsistency #5936
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5936 +/- ##
=======================================
Coverage 89.53% 89.54%
=======================================
Files 782 782
Lines 17981 17987 +6
=======================================
+ Hits 16100 16106 +6
Misses 1881 1881 ☔ View full report in Codecov by Sentry. |
9d41eea
to
43a9dcd
Compare
There are three ways of activating a promotion, and they are mutually exclusive. This adds a few helper methods so we know when a promotion can have a code added, or promotion codes added, or whether it can change the `apply_automatically` Boolean.
Because promotion codes have the `-> {with_discarded}` scope on the `promotion` association, a promo code that's instantiated with `promotion.codes.new` will not have the promotion associated at the beginning, leading to errors. This passes in the promotion so that the promo code knows where it belongs.
This makes use of the previously defined methods to make the promotion activation form more user-friendly and add some features: - Activation is now a bootstrap menu - Only one option can ever be edited - Reintroduces feature where a promotion code batch is created with the promotion
43a9dcd
to
7c2b843
Compare
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 do not think a tabbed interface is the best approach here, because it might hide activation restrictions.
<%= text_field_tag :single_code, @promotion.codes.first.try!(:value), class: "fullwidth", disabled: f.object.apply_automatically || f.object.path.present? %> | ||
<div class="col-9"> | ||
<div class="tab-content" id="v-pills-tabContent"> | ||
<div class="tab-pane fade show active" id="v-pills-automatic" role="tabpanel" aria-labelledby="v-pills-automatic-tab"> |
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.
Can we use a more useful name for the Tab id?
<div class="tab-pane fade show active" id="activation-tab-automatic" role="tabpanel" aria-labelledby="v-pills-automatic-tab">
<%= label_tag :single_code, SolidusPromotions::PromotionCode.model_name.human %> | ||
<%= text_field_tag :single_code, @promotion.codes.first.try!(:value), class: "fullwidth", disabled: f.object.apply_automatically || f.object.path.present? %> | ||
<div class="col-9"> | ||
<div class="tab-content" id="v-pills-tabContent"> |
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.
This id does not seems to be necessary
<div class="tab-content" id="v-pills-tabContent"> | |
<div class="tab-content"> |
@@ -11,8 +11,7 @@ class PromotionsController < BaseController | |||
|
|||
def create | |||
@promotion = model_class.new(permitted_resource_params) | |||
@promotion.codes.new(value: params[:single_code]) if params[:single_code].present? | |||
|
|||
@promotion.codes.new(promotion: @promotion, value: params[:single_code]) if params[:single_code].present? |
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 think we can solve this by setting the inverse_of
instead on the association. (I opened a PR that does just that when I encountered this error locally: #5953)
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.
Sweet, thank you!
Let's close this for now. |
Summary
This improves the UI of the promotion edit page. The page now has an "activation" menu that allows for configuring either automatic, path-based, single-code or multiple-code activation, similar to how the legacy promotion system does it.
This PR also solves a bug with single-code promotions which previously could not be created without a persisted promotion.
After:
Before:
The following are mandatory for all PRs:
The following are not always needed: