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

Add back explicit show_prefixes to ensure subconditions never have a prefix

This commit is contained in:
hatz 2025-05-10 12:59:46 -05:00
parent 1058d17b36
commit 11626b4d0f
No known key found for this signature in database
3 changed files with 12 additions and 8 deletions

View file

@ -32,7 +32,7 @@ export default class extends Controller {
this.element.remove(); this.element.remove();
} }
// Update the prefixes of all siblings from the parent rules controller // Update the prefixes of all conditions from the parent rules controller
if (rulesEl) { if (rulesEl) {
const rulesController = this.application.getControllerForElementAndIdentifier(rulesEl, "rules"); const rulesController = this.application.getControllerForElementAndIdentifier(rulesEl, "rules");
if (rulesController && typeof rulesController.updateConditionPrefixes === "function") { if (rulesController && typeof rulesController.updateConditionPrefixes === "function") {

View file

@ -1,14 +1,18 @@
<%# locals: (form:) %> <%# locals: (form:, show_prefix: true) %>
<% condition = form.object %> <% condition = form.object %>
<% rule = condition.rule %> <% rule = condition.rule %>
<li data-controller="rule--conditions" data-rule--conditions-condition-filters-value="<%= rule.condition_filters.to_json %>" class="flex items-center gap-3"> <li data-controller="rule--conditions" data-rule--conditions-condition-filters-value="<%= rule.condition_filters.to_json %>" class="flex items-center gap-3">
<%# Show prefix on conditions, except the first one %> <%# Conditionally render the prefix %>
<div class="pl-2" data-condition-prefix> <%# Condition groups pass in show_prefix: false for subconditions since the ANY/ALL selector makes that clear %>
<span class="font-medium uppercase text-xs">and</span> <% if show_prefix %>
</div> <div class="pl-2" data-condition-prefix>
<span class="font-medium uppercase text-xs">and</span>
</div>
<% end %>
<div class="grow flex gap-2 items-center h-full"> <div class="grow flex gap-2 items-center h-full">
<%= form.hidden_field :_destroy, value: false, data: { rule__conditions_target: "destroyField" } %> <%= form.hidden_field :_destroy, value: false, data: { rule__conditions_target: "destroyField" } %>

View file

@ -29,13 +29,13 @@
<%# Sub-condition template, used by Stimulus controller to add new sub-conditions dynamically %> <%# Sub-condition template, used by Stimulus controller to add new sub-conditions dynamically %>
<template data-rule--conditions-target="subConditionTemplate"> <template data-rule--conditions-target="subConditionTemplate">
<%= form.fields_for :sub_conditions, Rule::Condition.new(parent: condition, condition_type: rule.condition_filters.first.key), child_index: "IDX_PLACEHOLDER" do |scf| %> <%= form.fields_for :sub_conditions, Rule::Condition.new(parent: condition, condition_type: rule.condition_filters.first.key), child_index: "IDX_PLACEHOLDER" do |scf| %>
<%= render "rule/conditions/condition", form: scf %> <%= render "rule/conditions/condition", form: scf, show_prefix: false %>
<% end %> <% end %>
</template> </template>
<ul data-rule--conditions-target="subConditionsList" class="space-y-3"> <ul data-rule--conditions-target="subConditionsList" class="space-y-3">
<%= form.fields_for :sub_conditions do |scf| %> <%= form.fields_for :sub_conditions do |scf| %>
<%= render "rule/conditions/condition", form: scf %> <%= render "rule/conditions/condition", form: scf, show_prefix: false %>
<% end %> <% end %>
</ul> </ul>