foxygit / RPA-Remisser Log in
commits tags

/webui/frontend/src/lib/handles.ts · 1.03 KB

raw
// Handtagsmodellen – speglar rpa/schema.py:node_handles().
//   vanlig nod : in  ->  out
//   if         : in  ->  case0 … caseN, else
//   loop       : in  ->  each, done

import type { Step } from "./api";
import type { Schema } from "./schema";

export function nodeControl(schema: Schema, type: string): "if" | "loop" | undefined {
  return schema.step_types.find((s) => s.type === type)?.control;
}

export function outputHandles(schema: Schema, node: Step): string[] {
  const ctrl = nodeControl(schema, node.type);
  if (ctrl === "if") {
    const n = Math.max(1, node.branches?.length ?? 1);
    return [...Array.from({ length: n }, (_, i) => `case${i}`), "else"];
  }
  if (ctrl === "loop") return ["each", "done"];
  return ["out"];
}

export const HANDLE_LABEL: Record<string, string> = {
  out: "",
  each: "varje",
  done: "klar",
  else: "annars",
};

export function handleLabel(h: string): string {
  if (h in HANDLE_LABEL) return HANDLE_LABEL[h];
  if (h.startsWith("case")) return `gren ${Number(h.slice(4)) + 1}`;
  return h;
}