The personal finance app for everyone (by everyone)
Ruby
<%# locals: (rule:) %>
<% has_title = rule.name.present? || rule.stop_processing? || rule.apply_immediately? %>
<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 %>
<% if rule.apply_immediately? %>
<%= render DS::Pill.new(label: t(".apply_immediately"), tone: :info, marker: false, title: t(".apply_immediately_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 %>
<%# Folding hides the details; a rule without a name keeps its
condition as its title. %>
<%= tag.div class: "flex items-center gap-2 mt-1", data: { rule_details: rule.name.present? || nil } do %>
<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 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 %>
<%= t("rules.no_condition") %>
<% end %>
</span>
<% if additional_condition_count.positive? %>
<%= t(".and_more_conditions", count: additional_condition_count) %>
<% end %>
</p>
<% end %>
<% end %>
<div id="<%= dom_id(rule, :details) %>" class="space-y-1.5" data-rule-details>
<div class="flex items-center gap-2 mt-1">
<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 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">
<% displayed_action = rule.displayed_action %>
<% if displayed_action.nil? %>
<%= t("rules.no_action") %>
<% else %>
<% if displayed_action.value && displayed_action.options %>
<%= t(".action_label_to", label: displayed_action.executor.label, value: displayed_action.value_display) %>
<% else %>
<%= displayed_action.executor.label %>
<% end %>
<% end %>
</span>
<% if rule.actions.size > 1 %>
<%= t(".and_more_actions", count: rule.actions.size - 1) %>
<% end %>
</p>
</div>
<div class="flex items-center gap-2 mt-1">
<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 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 %>
<%= t(".on_or_after", resource: rule.resource_type.pluralize, date: rule.effective_date.strftime("%b %-d, %Y")) %>
<% end %>
</span>
</p>
</div>
</div>
</div>
<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 %>
<% unless Current.user&.guest? %>
<%= render DS::Menu.new do |menu| %>
<% menu.with_item(variant: "link", text: t(".edit"), href: edit_rule_path(rule), icon: "pencil", data: { turbo_frame: "modal" }) %>
<% menu.with_item(variant: "link", text: t(".re_apply_rule"), href: confirm_rule_path(rule), icon: "refresh-cw", data: { turbo_frame: "modal" }) %>
<% menu.with_item(
variant: "button",
text: t(".delete"),
href: rule_path(rule),
icon: "trash-2",
method: :delete,
confirm: CustomConfirm.for_resource_deletion("rule")) %>
<% end %>
<% end %>
</div>
</div>