Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Keep the rules list and settings header inside phone screens (#4473)

GFR958566e719ce
diff --git a/app/views/layouts/settings.html.erb b/app/views/layouts/settings.html.erb
index f14a94eb7c..a3121dfe81 100644
--- a/app/views/layouts/settings.html.erb
+++ b/app/views/layouts/settings.html.erb
@@ -19,16 +19,16 @@
<%= render "layouts/shared/breadcrumbs", breadcrumbs: breadcrumbs %>
<% end %>
- <div class="flex items-center justify-between gap-4 mt-1.5 min-h-9">
+ <div class="flex flex-wrap items-center justify-between gap-x-4 gap-y-2 mt-1.5 min-h-9">
<% if content_for?(:page_title) %>
- <h1 class="text-primary text-xl font-medium">
+ <h1 class="text-primary text-xl font-medium min-w-0 break-words">
<%= content_for :page_title %>
</h1>
<% else %>
<div></div>
<% end %>
<% if content_for?(:page_actions) %>
- <div class="flex items-center gap-2 shrink-0">
+ <div class="ml-auto flex flex-wrap items-center justify-end gap-2">
<%= yield :page_actions %>
</div>
<% end %>
diff --git a/app/views/rules/_rule.html.erb b/app/views/rules/_rule.html.erb
index 7cbb7773f9..27ce6e52ed 100644
--- a/app/views/rules/_rule.html.erb
+++ b/app/views/rules/_rule.html.erb
@@ -1,17 +1,17 @@
<%# locals: (rule:) %>
-<div id="<%= dom_id(rule) %>" class="flex justify-between items-center p-4 <%= rule.active? ? "text-primary" : "text-secondary" %>">
-
- <div class="text-sm space-y-1.5">
- <% if rule.name.present? || rule.stop_processing? %>
- <div class="flex items-center gap-2">
- <% if rule.name.present? %>
- <h3 class="font-medium text-md"><%= rule.name %></h3>
- <% end %>
- <% if rule.stop_processing? %>
- <%= render DS::Pill.new(label: t(".stop_processing"), tone: :neutral, marker: false, title: t(".stop_processing_hint")) %>
- <% end %>
- </div>
- <% end %>
+<% has_title = rule.name.present? || rule.stop_processing? %>
+<div id="<%= dom_id(rule) %>" class="grid grid-cols-[minmax(0,1fr)_auto] items-start gap-x-3 gap-y-0.5 p-3 text-sm sm:items-center sm:p-4 <%= rule.active? ? "text-primary" : "text-secondary" %>">
+ <% if has_title %>
+ <div class="col-start-1 row-start-1 flex min-w-0 flex-wrap items-center gap-2 self-center">
+ <% if rule.name.present? %>
+ <h3 class="min-w-0 break-words font-medium text-md"><%= rule.name %></h3>
+ <% end %>
+ <% if rule.stop_processing? %>
+ <%= render DS::Pill.new(label: t(".stop_processing"), tone: :neutral, marker: false, title: t(".stop_processing_hint")) %>
+ <% end %>
+ </div>
+ <% end %>
+ <div class="col-span-2 row-start-2 min-w-0 space-y-1.5 sm:col-span-1 sm:col-start-1 <%= "sm:row-start-1" unless has_title %>">
<% if rule.conditions.any? %>
<% displayed_condition = rule.displayed_condition %>
<% additional_condition_count = rule.additional_displayable_conditions_count %>
@@ -19,8 +19,8 @@
<div class="flex items-center gap-1 text-secondary w-16 shrink-0">
<span class="font-mono text-xs">IF</span>
</div>
- <p class="flex items-center flex-wrap gap-1.5 m-0">
- <span class="px-2 py-1 border border-secondary rounded-full">
+ <p class="flex min-w-0 items-center flex-wrap gap-x-1.5 gap-y-1 m-0">
+ <span class="max-w-full truncate px-2 py-1 border border-secondary rounded-full">
<% if displayed_condition.present? %>
<%= displayed_condition.filter.label %> <%= displayed_condition.operator %> <%= displayed_condition.value_display %>
<% else %>
@@ -37,8 +37,8 @@
<div class="flex items-center gap-1 text-secondary w-16 shrink-0">
<span class="font-mono text-xs"><%= t(".then") %></span>
</div>
- <p class="flex items-center flex-wrap gap-1.5 m-0">
- <span class="px-2 py-1 border border-secondary rounded-full">
+ <p class="flex min-w-0 items-center flex-wrap gap-x-1.5 gap-y-1 m-0">
+ <span class="max-w-full truncate px-2 py-1 border border-secondary rounded-full">
<% if rule.actions.first.nil? %>
<%= t("rules.no_action") %>
<% else %>
@@ -58,8 +58,8 @@
<div class="flex items-center gap-1 text-secondary w-16 shrink-0">
<span class="font-mono text-xs">FOR</span>
</div>
- <p class="flex items-center flex-wrap gap-1.5 m-0">
- <span class="px-2 py-1 border border-secondary rounded-full">
+ <p class="flex min-w-0 items-center flex-wrap gap-x-1.5 gap-y-1 m-0">
+ <span class="max-w-full truncate px-2 py-1 border border-secondary rounded-full">
<% if rule.effective_date.nil? %>
<%= t(".all_past_and_future", resource: rule.resource_type.pluralize) %>
<% else %>
@@ -69,7 +69,7 @@
</p>
</div>
</div>
- <div class="flex items-center gap-4">
+ <div class="col-start-2 row-start-1 flex items-center gap-4 self-start sm:self-center <%= "sm:row-span-2" if has_title %>">
<%= styled_form_with model: rule, namespace: "rule_#{rule.id}", data: { controller: "auto-submit-form" } do |f| %>
<%= f.toggle :active, { disabled: Current.user&.guest?, data: { auto_submit_form_target: "auto" } } %>
<% end %>
diff --git a/test/system/rules_test.rb b/test/system/rules_test.rb
index 73f7f5114e..e87fcebfe9 100644
--- a/test/system/rules_test.rb
+++ b/test/system/rules_test.rb
@@ -184,4 +184,42 @@ class RulesTest < ApplicationSystemTestCase
assert_equal "set_transaction_category", rule.actions.first.action_type
assert rule.actions.first.value.present?
end
+
+ test "keeps a rule with long text inside a phone-width screen" do
+ @user.family.rules.destroy_all
+ rule = @user.family.rules.create!(
+ name: "Gift card promotion savings plan with a very long descriptive name",
+ resource_type: "transaction",
+ conditions: [
+ Rule::Condition.new(condition_type: "transaction_name", operator: "like", value: "EXAMPLEMARKETPLACEPAYMENTSEUROPESARL")
+ ],
+ actions: [
+ Rule::Action.new(action_type: "set_transaction_category", value: categories(:food_and_drink).id)
+ ]
+ )
+
+ page.current_window.resize_to(320, 640)
+ visit rules_path
+
+ row = find("##{ActionView::RecordIdentifier.dom_id(rule)}")
+ viewport_width = page.evaluate_script("document.documentElement.clientWidth")
+
+ row_right = row.native.rect.x + row.native.rect.width
+ assert_operator row_right, :<=, viewport_width
+
+ [ "h3", "span.truncate", "button[aria-haspopup]", "label" ].each do |selector|
+ element = row.find(selector, match: :first, visible: :all)
+ assert_operator element.native.rect.x + element.native.rect.width, :<=, row_right, "#{selector} runs past the rule row"
+ end
+ assert_operator row.find("h3").evaluate_script("this.scrollWidth - this.clientWidth"), :<=, 0, "rule name overflows"
+
+ # On a phone the toggle and menu sit next to the rule name.
+ name = row.find("h3").native.rect
+ menu = row.find("button[aria-haspopup]").native.rect
+ assert_operator menu.y, :<, name.y + name.height
+ assert_operator menu.x, :>=, name.x + name.width
+
+ new_rule = find("a", text: I18n.t("rules.index.new_rule"))
+ assert_operator new_rule.native.rect.x + new_rule.native.rect.width, :<=, viewport_width
+ end
end