showRulePopup function
Last updated: 2026-03-04T23:21:38.396Z
Metrics
LOC: 70
Complexity: 14
Params: 2
Signature
showRulePopup(anchor: HTMLElement, onDismiss: () => void): : void
Architecture violations
- [warning] max-cyclomatic-complexity: 'showRulePopup' has cyclomatic complexity 14 (max 10)
Source Code
function showRulePopup(anchor: HTMLElement, onDismiss: () => void): void {
currentOnDismiss = onDismiss;
if (!rulePopupElement) {
rulePopupElement = document.createElement("div");
rulePopupElement.id = RULE_POPUP_ID;
rulePopupElement.innerHTML = getRulePopupHTML();
document.body.appendChild(rulePopupElement);
setupPopupListeners();
}
if (!genSearchableSelect) {
const wrap = rulePopupElement.querySelector<HTMLElement>(
"#fa-rp-generator-wrap",
);
if (wrap) {
genSearchableSelect = new SearchableSelect({
entries: buildGeneratorSelectEntries(),
value: "auto",
placeholder: "Pesquisar tipo…",
});
genSearchableSelect.mount(wrap);
genSearchableSelect.on("change", () => {
updateParamsSection();
updatePreview();
});
}
}
const nameEl =
rulePopupElement.querySelector<HTMLElement>("#fa-rp-field-name");
if (nameEl) nameEl.textContent = currentRuleField?.label || "";
const fixedInput =
rulePopupElement.querySelector<HTMLInputElement>("#fa-rp-fixed");
if (fixedInput) fixedInput.value = "";
const suggestionEl =
rulePopupElement.querySelector<HTMLElement>("#fa-rp-suggestion");
const suggestionTypeEl = rulePopupElement.querySelector<HTMLElement>(
"#fa-rp-suggestion-type",
);
const saveBtn =
rulePopupElement.querySelector<HTMLButtonElement>("#fa-rp-save");
if (saveBtn) {
saveBtn.textContent = "💾 Salvar";
saveBtn.disabled = false;
}
genSearchableSelect?.setValue(currentSuggestedType ?? "auto");
if (suggestionEl && suggestionTypeEl) {
if (currentSuggestedType) {
const label =
getFieldTypeOptions().find((o) => o.value === currentSuggestedType)
?.label ?? currentSuggestedType;
suggestionTypeEl.textContent = label;
suggestionEl.style.display = "flex";
} else {
suggestionEl.style.display = "none";
}
}
updateParamsSection();
updatePreview();
positionRulePopup(anchor);
rulePopupElement.style.display = "block";
fixedInput?.focus();
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| getRulePopupHTML | calls |
| setupPopupListeners | calls |
| SearchableSelect | instantiates |
| updateParamsSection | calls |
| updatePreview | calls |
| positionRulePopup | calls |
| change | dynamic_call |
Impact (Incoming)
| Source | Type |
|---|---|
| handleRuleButtonClick | calls |