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

View all

  • [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)

graph LR showRulePopup["showRulePopup"] getRulePopupHTML["getRulePopupHTML"] setupPopupListeners["setupPopupListeners"] SearchableSelect["SearchableSelect"] updateParamsSection["updateParamsSection"] updatePreview["updatePreview"] positionRulePopup["positionRulePopup"] showRulePopup -->|calls| getRulePopupHTML showRulePopup -->|calls| setupPopupListeners showRulePopup -.->|instantiates| SearchableSelect showRulePopup -->|calls| updateParamsSection showRulePopup -->|calls| updatePreview showRulePopup -->|calls| positionRulePopup style showRulePopup fill:#dbeafe,stroke:#2563eb,stroke-width:2px click showRulePopup "9a11db3b71d6ccf5.html" click getRulePopupHTML "9f97c911ee78d2da.html" click setupPopupListeners "ca4c2bf69b7d4b11.html" click SearchableSelect "194c113b97ce486d.html" click updateParamsSection "9e0d46bd06f35333.html" click updatePreview "dcabab4647818f61.html" click positionRulePopup "25cfebd1421f5b74.html"
TargetType
getRulePopupHTML calls
setupPopupListeners calls
SearchableSelect instantiates
updateParamsSection calls
updatePreview calls
positionRulePopup calls
change dynamic_call

Impact (Incoming)

graph LR showRulePopup["showRulePopup"] handleRuleButtonClick["handleRuleButtonClick"] handleRuleButtonClick -->|calls| showRulePopup style showRulePopup fill:#dbeafe,stroke:#2563eb,stroke-width:2px click showRulePopup "9a11db3b71d6ccf5.html" click handleRuleButtonClick "302ac6e6209ebb8e.html"
SourceType
handleRuleButtonClick calls