handleSelect function

Last updated: 2026-03-05T20:45:07.036Z

Metrics

LOC: 34 Complexity: 11 Params: 1

Signature

handleSelect(step: FlowStep): : StepResult

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'handleSelect' has cyclomatic complexity 11 (max 10)

Source Code

function handleSelect(step: FlowStep): StepResult {
  const el = requireElement(step);
  ensureVisible(el);

  if (!(el instanceof HTMLSelectElement)) {
    return { status: "failed", error: "Select target is not a <select>" };
  }

  if (step.selectIndex != null) {
    if (step.selectIndex >= 0 && step.selectIndex < el.options.length) {
      el.selectedIndex = step.selectIndex;
    } else {
      return {
        status: "failed",
        error: `Select index ${step.selectIndex} out of range`,
      };
    }
  } else if (step.selectText != null) {
    const option = Array.from(el.options).find(
      (o) => o.text === step.selectText || o.value === step.selectText,
    );
    if (option) {
      el.value = option.value;
    } else {
      return {
        status: "failed",
        error: `Option "${step.selectText}" not found`,
      };
    }
  }

  el.dispatchEvent(new Event("change", { bubbles: true }));
  return { status: "success" };
}

Dependencies (Outgoing)

graph LR handleSelect["handleSelect"] requireElement["requireElement"] ensureVisible["ensureVisible"] handleSelect -->|calls| requireElement handleSelect -->|calls| ensureVisible style handleSelect fill:#dbeafe,stroke:#2563eb,stroke-width:2px click handleSelect "3c2550d444ab28e5.html" click requireElement "54b35883ca14f405.html" click ensureVisible "12336ba1f5ec5dde.html"
TargetType
requireElement calls
ensureVisible calls

Impact (Incoming)

graph LR handleSelect["handleSelect"] executeStep["executeStep"] executeStep -->|calls| handleSelect style handleSelect fill:#dbeafe,stroke:#2563eb,stroke-width:2px click handleSelect "3c2550d444ab28e5.html" click executeStep "a26ccfb820921de2.html"
SourceType
executeStep calls