1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 15:35:22 +02:00

Add primary_condition_title field to rule model

This commit is contained in:
hatz 2025-05-11 12:46:20 -05:00
parent 1aa94282f2
commit 2ea1c75544
No known key found for this signature in database
2 changed files with 14 additions and 6 deletions

View file

@ -46,6 +46,18 @@ class Rule < ApplicationRecord
RuleJob.perform_later(self, ignore_attribute_locks: ignore_attribute_locks) RuleJob.perform_later(self, ignore_attribute_locks: ignore_attribute_locks)
end end
def primary_condition_title
return "No conditions" if conditions.none?
first_condition = conditions.first
if first_condition.compound? && first_condition.sub_conditions.any?
first_sub_condition = first_condition.sub_conditions.first
"If #{first_sub_condition.filter.label.downcase} #{first_sub_condition.operator} #{first_sub_condition.value_display}"
else
"If #{first_condition.filter.label.downcase} #{first_condition.operator} #{first_condition.value_display}"
end
end
private private
def matching_resources_scope def matching_resources_scope
scope = registry.resource_scope scope = registry.resource_scope

View file

@ -4,12 +4,8 @@
<div class="text-sm space-y-1.5"> <div class="text-sm space-y-1.5">
<% if rule.conditions.any? %> <% if rule.conditions.any? %>
<p class="flex items-center flex-wrap gap-1.5"> <p class="flex items-center flex-wrap gap-1.5">
<span class="px-2 py-1 border border-alpha-black-200 rounded-full"> <span class="px-2 py-1 border border-secondary rounded-full">
<% if rule.conditions.first.compound? %> <%= rule.primary_condition_title %>
If <%= rule.conditions.first.sub_conditions.first.filter.label %> <%= rule.conditions.first.sub_conditions.first.operator %> <%= rule.conditions.first.sub_conditions.first.value_display %>
<% else %>
If <%= rule.conditions.first.filter.label %> <%= rule.conditions.first.operator %> <%= rule.conditions.first.value_display %>
<% end %>
</span> </span>
<% if rule.conditions.count > 1 %> <% if rule.conditions.count > 1 %>