/** * Start node (Formular) — define fields that appear at run time (payload.*). */ import React, { useMemo } from 'react'; import type { NodeConfigRendererProps } from '../shared/types'; import type { FormField } from '../shared/types'; import { FORM_FIELD_TYPES, FORM_FIELD_TYPE_LABELS } from '../../../../utils/attributeTypeMapper'; import styles from '../../editor/Automation2FlowEditor.module.css'; import { useAutomation2DataFlow } from '../../context/Automation2DataFlowContext'; import { useLanguage } from '../../../../providers/language/LanguageContext'; function _parseFields(params: Record, t: (key: string) => string): FormField[] { const raw = params.formFields; if (!Array.isArray(raw)) return [{ name: 'field1', label: t('Feld 1'), type: 'text' }]; return raw.map((f, i) => { if (f && typeof f === 'object' && !Array.isArray(f)) { const o = f as Record; const rawType = String(o.type ?? 'text'); const name = String(o.name ?? `field${i + 1}`); const label = String(o.label ?? `${t('Feld')} ${i + 1}`); const type = (FORM_FIELD_TYPES as readonly string[]).includes(rawType) ? rawType : 'text'; return { name, label, type } as FormField; } return { name: `field${i + 1}`, label: `${t('Feld')} ${i + 1}`, type: 'text' as const }; }); } export const FormStartNodeConfig: React.FC = ({ params, updateParam }) => { const { t } = useLanguage(); const ctx = useAutomation2DataFlow(); const fieldTypeOptions = ctx?.formFieldTypes?.length ? ctx.formFieldTypes : FORM_FIELD_TYPES.map((ft) => ({ id: ft, label: FORM_FIELD_TYPE_LABELS[ft] ?? ft, portType: 'str' })); const fields = useMemo(() => _parseFields(params, t), [params, t]); const setFields = (next: FormField[]) => { updateParam('formFields', next); }; return (

{t('Formular-Felder')}{' '} {t('werden beim Start ausgefüllt und liegen unter')}{' '} payload.<name> {t('in der Start-Ausgabe.')}

{fields.map((f, idx) => (
{ const next = [...fields]; next[idx] = { ...f, name: e.target.value }; setFields(next); }} /> { const next = [...fields]; next[idx] = { ...f, label: e.target.value }; setFields(next); }} />
))}
); };