mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 23:15:24 +02:00
Simplify logic since we don't process subconditions
This commit is contained in:
parent
df096c9b5f
commit
717277c466
2 changed files with 9 additions and 21 deletions
|
@ -24,7 +24,6 @@ export default class extends Controller {
|
||||||
// Find the parent rules controller before removing the condition
|
// Find the parent rules controller before removing the condition
|
||||||
const rulesEl = this.element.closest('[data-controller~="rules"]');
|
const rulesEl = this.element.closest('[data-controller~="rules"]');
|
||||||
|
|
||||||
// Remove the condition
|
|
||||||
if (e.params.destroy) {
|
if (e.params.destroy) {
|
||||||
this.destroyFieldTarget.value = true;
|
this.destroyFieldTarget.value = true;
|
||||||
this.element.classList.add("hidden");
|
this.element.classList.add("hidden");
|
||||||
|
@ -37,7 +36,6 @@ export default class extends Controller {
|
||||||
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") {
|
||||||
rulesController.updateConditionPrefixes();
|
rulesController.updateConditionPrefixes();
|
||||||
console.log("updated prefixes")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default class extends Controller {
|
||||||
];
|
];
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
// Update condition prefixes on first connection (form render)
|
// Update condition prefixes on first connection (form render on edit)
|
||||||
this.updateConditionPrefixes();
|
this.updateConditionPrefixes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,32 +57,22 @@ export default class extends Controller {
|
||||||
// This is also called by the rule/conditions_controller when a subcondition is removed
|
// This is also called by the rule/conditions_controller when a subcondition is removed
|
||||||
updateConditionPrefixes() {
|
updateConditionPrefixes() {
|
||||||
// Update conditions
|
// Update conditions
|
||||||
this.#updatePrefixesForList(this.conditionsListTarget);
|
const conditions = Array.from(this.conditionsListTarget.children);
|
||||||
|
|
||||||
// Update subconditions for each condition group
|
let conditionIndex = 0;
|
||||||
// We currently only support a single level of subconditions
|
|
||||||
const groupSubLists = this.conditionsListTarget.querySelectorAll('[data-rule--conditions-target="subConditionsList"]');
|
|
||||||
groupSubLists.forEach((subList) => {
|
|
||||||
this.#updatePrefixesForList(subList);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to update prefixes for a given list
|
conditions.forEach((condition) => {
|
||||||
#updatePrefixesForList(listEl) {
|
// Only process visible conditions, this prevents conditions that are marked for removal and hidden
|
||||||
const items = Array.from(listEl.children);
|
|
||||||
let conditionIdx = 0;
|
|
||||||
items.forEach((item) => {
|
|
||||||
// Only process visible items, this prevents conditions that are marked for removal and hidden
|
|
||||||
// from being added to the index. This is important when editing a rule.
|
// from being added to the index. This is important when editing a rule.
|
||||||
if (!item.classList.contains('hidden')) {
|
if (!condition.classList.contains('hidden')) {
|
||||||
const prefixEl = item.querySelector('[data-condition-prefix]');
|
const prefixEl = condition.querySelector('[data-condition-prefix]');
|
||||||
if (prefixEl) {
|
if (prefixEl) {
|
||||||
if (conditionIdx === 0) {
|
if (conditionIndex === 0) {
|
||||||
prefixEl.classList.add('hidden');
|
prefixEl.classList.add('hidden');
|
||||||
} else {
|
} else {
|
||||||
prefixEl.classList.remove('hidden');
|
prefixEl.classList.remove('hidden');
|
||||||
}
|
}
|
||||||
conditionIdx++;
|
conditionIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue