foxygit / RPA-Remisser Log in
commits tags

/webui/frontend/src/lib/schema.ts · 1.77 KB

raw
// Speglar rpa/schema.py. Hämtas i runtime från GET /api/step-schema så det bara
// finns EN källa (Python-sidan).

export type FieldKind = "text" | "number" | "select" | "bool" | "field_list" | "image";

export interface Field {
  key: string;
  kind: FieldKind;
  options?: string[];
  default?: string | number | boolean;
  required?: boolean;
  label_sv: string;
  label_en: string;
  help?: string;
  interpolate?: boolean;
  /** Visa fältet bara när andra fält har vissa värden, t.ex. {source: "pdf"}. */
  visible_when?: Record<string, string | number | boolean>;
}

export interface StepType {
  type: string;
  category: string;
  label_sv: string;
  label_en: string;
  help?: string;
  fields: Field[];
  /** kontrollflödesnod: "if" (case0…/else-utgångar) eller "loop" (each/done). */
  control?: "if" | "loop";
  selector?: boolean;
  produces_vars?: string[];
  consumes_vars?: string[];
}

export interface ConditionKind {
  kind: string;
  label_sv: string;
  label_en: string;
  fields: Field[];
}

export interface Setting {
  key: string;
  kind: "text" | "number" | "bool";
  default: string | number | boolean;
  label_sv: string;
  label_en: string;
  help?: string;
}

export interface Schema {
  step_types: StepType[];
  condition_kinds: ConditionKind[];
  settings: Setting[];
  input_fields: Field[];
  close_modes: string[];
}

export function stepType(schema: Schema, type: string): StepType | undefined {
  return schema.step_types.find((s) => s.type === type);
}

export function conditionKind(schema: Schema, kind: string): ConditionKind | undefined {
  return schema.condition_kinds.find((c) => c.kind === kind);
}

export function fieldLabel(f: { label_sv: string; label_en: string }, lang: "sv" | "en"): string {
  return lang === "sv" ? f.label_sv : f.label_en;
}