updatePreview function presentation

Last updated: 2026-03-04T23:21:38.396Z

Metrics

LOC: 38 Complexity: 12 Params: 0

Signature

updatePreview(): : void

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'updatePreview' has cyclomatic complexity 12 (max 10)

Source Code

function updatePreview(): void {
  if (!rulePopupElement) return;

  const fixedInput =
    rulePopupElement.querySelector<HTMLInputElement>("#fa-rp-fixed");
  const previewValueEl = rulePopupElement.querySelector<HTMLElement>(
    "#fa-rp-preview-value",
  );
  const refreshBtn = rulePopupElement.querySelector<HTMLElement>(
    "#fa-rp-preview-refresh",
  );

  if (!fixedInput || !previewValueEl) return;

  const fixedVal = fixedInput.value.trim();

  if (fixedVal) {
    previewValueEl.textContent = fixedVal;
    previewValueEl.className = "fa-rp-preview-fixed";
    if (refreshBtn) refreshBtn.style.display = "none";
  } else {
    const selectedType = genSearchableSelect?.getValue() ?? "auto";
    const typeToGenerate: FieldType =
      selectedType === "auto"
        ? (currentSuggestedType ?? "text")
        : (selectedType as FieldType);

    try {
      const overrideParams = collectParamsFromUI();
      previewValueEl.textContent = generate(typeToGenerate, overrideParams);
    } catch {
      previewValueEl.textContent = "—";
    }

    previewValueEl.className = "fa-rp-preview-generated";
    if (refreshBtn) refreshBtn.style.display = "flex";
  }
}

Dependencies (Outgoing)

graph LR updatePreview["updatePreview"] collectParamsFromUI["collectParamsFromUI"] updatePreview -->|calls| collectParamsFromUI style updatePreview fill:#dbeafe,stroke:#2563eb,stroke-width:2px click updatePreview "dcabab4647818f61.html" click collectParamsFromUI "37fd92ff99d24fcf.html"
TargetType
collectParamsFromUI calls

Impact (Incoming)

graph LR updatePreview["updatePreview"] showRulePopup["showRulePopup"] setupPopupListeners["setupPopupListeners"] updateParamsSection["updateParamsSection"] showRulePopup -->|calls| updatePreview setupPopupListeners -->|calls| updatePreview updateParamsSection -->|calls| updatePreview style updatePreview fill:#dbeafe,stroke:#2563eb,stroke-width:2px click updatePreview "dcabab4647818f61.html" click showRulePopup "9a11db3b71d6ccf5.html" click setupPopupListeners "ca4c2bf69b7d4b11.html" click updateParamsSection "9e0d46bd06f35333.html"