-
-
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
Open
mamhoff
wants to merge
3
commits into
solidusio:main
Choose a base branch
from
mamhoff:fix-promotions-admin-ui-inconsistency
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+173
−39
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
10 changes: 5 additions & 5 deletions
10
...s/lib/views/backend/solidus_promotions/admin/promotion_code_batches/_form_fields.html.erb
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,22 +1,22 @@ | ||
<div class="form-group"> | ||
<%= batch.label :base_code, class: "required" %> | ||
<%= batch.text_field :base_code, class: "fullwidth", required: true %> | ||
<%= batch.text_field :base_code, class: "fullwidth #{'enable' if promotion.can_change_codes?}", required: true, disabled: disabled %> | ||
</div> | ||
<div class="form-group"> | ||
<%= batch.label :number_of_codes, class: "required" %> | ||
<%= batch.number_field :number_of_codes, class: "fullwidth", min: 1, required: true %> | ||
<%= batch.number_field :number_of_codes, class: "fullwidth #{'enable' if promotion.can_change_codes?}", min: 1, required: true, disabled: disabled %> | ||
</div> | ||
<div class="form-group"> | ||
<%= batch.label :join_characters %> | ||
<%= batch.text_field :join_characters, class: "fullwidth" %> | ||
<%= batch.text_field :join_characters, class: "fullwidth #{'enable' if promotion.can_change_codes?}", disabled: disabled %> | ||
</div> | ||
<% unless promotion_id %> | ||
<div class="form-group"> | ||
<%= f.label :per_code_usage_limit %> | ||
<%= f.text_field :per_code_usage_limit, class: "fullwidth" %> | ||
<%= f.text_field :per_code_usage_limit, class: "fullwidth #{'enable' if promotion.can_change_codes?}", disabled: disabled %> | ||
</div> | ||
<% end %> | ||
<div class="form-group"> | ||
<%= batch.label :email %> | ||
<%= batch.text_field :email, class: "fullwidth" %> | ||
<%= batch.text_field :email, class: "fullwidth #{'enable' if promotion.can_change_codes?}", disabled: disabled %> | ||
</div> |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -85,40 +85,81 @@ | |||||
</div> | ||||||
</fieldset> | ||||||
|
||||||
<fieldset class="form-group row no-border-bottom"> | ||||||
<fieldset class="no-border-bottom"> | ||||||
<legend><%= t '.activation' %></legend> | ||||||
|
||||||
<div class="col-4"> | ||||||
<%= f.field_container :apply_automatically do %> | ||||||
<%= f.label :apply_automatically do %> | ||||||
<%= f.check_box :apply_automatically, disabled: f.object.codes.any? || f.object.path.present? %> | ||||||
<%= SolidusPromotions::Promotion.human_attribute_name(:apply_automatically) %> | ||||||
<%= f.field_hint :promo_code_will_be_disabled %> | ||||||
<% end %> | ||||||
<% end %> | ||||||
</div> | ||||||
|
||||||
<% if f.object.new_record? || f.object.present? %> | ||||||
<div class="col-4"> | ||||||
<%= f.field_container :path do %> | ||||||
<%= f.label :path %> | ||||||
<%= f.text_field :path, class: "fullwidth", disabled: f.object.apply_automatically || f.object.codes.present? %> | ||||||
<% end %> | ||||||
<div class="row"> | ||||||
<div class="col-3"> | ||||||
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical"> | ||||||
<button class="nav-link mb-1 active" id="v-pills-automatic-tab" data-toggle="pill" data-target="#v-pills-automatic" type="button" role="tab" aria-controls="v-pills-automatic" aria-selected="true"> | ||||||
<%= t(".automatic") %> | ||||||
</button> | ||||||
<button class="nav-link mb-1" id="v-pills-path-tab" data-toggle="pill" data-target="#v-pills-path" type="button" role="tab" aria-controls="v-pills-path" aria-selected="false"> | ||||||
<%= t(".path") %> | ||||||
</button> | ||||||
<button class="nav-link mb-1" id="v-pills-single-code-tab" data-toggle="pill" data-target="#v-pills-single-code" type="button" role="tab" aria-controls="v-pills-single-code" aria-selected="false"> | ||||||
<%= t(".single_code") %> | ||||||
</button> | ||||||
<button class="nav-link mb-1" id="v-pills-multiple-codes-tab" data-toggle="pill" data-target="#v-pills-multiple-codes" type="button" role="tab" aria-controls="v-pills-multiple-codes" aria-selected="false"> | ||||||
<%= t(".multiple_codes") %> | ||||||
</button> | ||||||
</div> | ||||||
</div> | ||||||
<% end %> | ||||||
|
||||||
<div class="col-4"> | ||||||
<% if f.object.new_record? %> | ||||||
<div id="promotion_single_code" class="form-group"> | ||||||
<%= 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 commentThe reason will be displayed to describe this comment to others. Learn more. This id does not seems to be necessary
Suggested change
|
||||||
<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 commentThe reason will be displayed to describe this comment to others. Learn more. Can we use a more useful name for the Tab id?
|
||||||
<%= f.field_container :apply_automatically do %> | ||||||
<%= f.label :apply_automatically do %> | ||||||
<%= f.check_box :apply_automatically, {disabled: !f.object.can_change_apply_automatically?, class: "#{'enable' if f.object.can_change_apply_automatically?}"} %> | ||||||
<%= SolidusPromotions::Promotion.human_attribute_name(:apply_automatically) %> | ||||||
<%= f.field_hint :promo_code_will_be_disabled %> | ||||||
<% end %> | ||||||
<% if f.object.codes.present? %> | ||||||
<div class="codes-present"> | ||||||
<p> | ||||||
<%= t('.codes_present') %> | ||||||
</p> | ||||||
</div> | ||||||
<% end %> | ||||||
<% end %> | ||||||
</div> | ||||||
<% else %> | ||||||
<div class="codes-present"> | ||||||
<p> | ||||||
<%= t('.codes_present') %> | ||||||
</p> | ||||||
<div class="tab-pane fade" id="v-pills-path" role="tabpanel" aria-labelledby="v-pills-path-tab"> | ||||||
<%= f.field_container :path do %> | ||||||
<%= f.label :path %> | ||||||
<%= f.text_field :path, class: "fullwidth #{'enable' if f.object.can_change_path?}", disabled: true %> | ||||||
<% end %> | ||||||
</div> | ||||||
<% end %> | ||||||
<div class="tab-pane fade" id="v-pills-single-code" role="tabpanel" aria-labelledby="v-pills-single-code-tab"> | ||||||
<%= f.field_container :single_code do%> | ||||||
<%= label_tag :single_code, SolidusPromotions::PromotionCode.model_name.human %> | ||||||
<%= text_field_tag :single_code, @promotion.codes.first.try!(:value), class: "fullwidth #{'enable' if f.object.can_change_codes?}", disabled: true %> | ||||||
<% end %> | ||||||
</div> | ||||||
<div class="tab-pane fade" id="v-pills-multiple-codes" role="tabpanel" aria-labelledby="v-pills-multiple-codes-tab"> | ||||||
<%= fields_for :promotion_code_batch, @promotion.code_batches.new do |batch| %> | ||||||
<%= render partial: 'solidus_promotions/admin/promotion_code_batches/form_fields', locals: {f: f, batch: batch, promotion: @promotion, disabled: true, promotion_id: params[:promotion_id]} %> | ||||||
<% end %> | ||||||
</div> | ||||||
</div> | ||||||
</div> | ||||||
</div> | ||||||
</fieldset> | ||||||
|
||||||
<script> | ||||||
function disableInactiveTabFields(event) { | ||||||
const panes = document.querySelectorAll(".tab-pane"); | ||||||
panes.forEach(pane => { | ||||||
if (pane.id == event.target.dataset.target.slice(1)) { | ||||||
pane.querySelectorAll("input.enable, select.enable").forEach(input => { | ||||||
input.removeAttribute("disabled"); | ||||||
}); | ||||||
} else { | ||||||
pane.querySelectorAll("input, select").forEach(input => { | ||||||
input.setAttribute("disabled", true); | ||||||
}); | ||||||
} | ||||||
}); | ||||||
} | ||||||
document.addEventListener("DOMContentLoaded", function() { | ||||||
$(".nav-link").on("show.bs.tab", disableInactiveTabFields); | ||||||
}); | ||||||
</script> |
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 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)