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

Fix promotions admin UI inconsistency #5936

Closed

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Nov 16, 2024

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:

grafik

Before:
grafik

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@mamhoff mamhoff requested a review from a team as a code owner November 16, 2024 17:02
@github-actions github-actions bot added the changelog:repository Changes to the repository not within any gem label Nov 16, 2024
Copy link

codecov bot commented Nov 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.54%. Comparing base (2632096) to head (7c2b843).
Report is 29 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added changelog:solidus_promotions Changes to the solidus_promotions gem and removed changelog:repository Changes to the repository not within any gem labels Nov 18, 2024
@mamhoff mamhoff force-pushed the fix-promotions-admin-ui-inconsistency branch from 9d41eea to 43a9dcd Compare November 18, 2024 08:53
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
@mamhoff mamhoff force-pushed the fix-promotions-admin-ui-inconsistency branch from 43a9dcd to 7c2b843 Compare November 18, 2024 09:11
Copy link
Member

@tvdeyen tvdeyen left a 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">
Copy link
Member

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">
Copy link
Member

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

Suggested change
<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?
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sweet, thank you!

@mamhoff
Copy link
Contributor Author

mamhoff commented Dec 3, 2024

Let's close this for now.

@mamhoff mamhoff closed this Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_promotions Changes to the solidus_promotions gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants