index.tsx


Overview

index.tsx defines a React functional component named SwitchForm that implements a dynamic, nested conditional form interface for building switch-case style logic flows within a UI. The form allows users to configure multiple "cases," each containing one or more logical conditions, and specify the next step (or branch) to take in a workflow based on those conditions. An ELSE branch can also be configured to handle conditions not matched by any case.

This component leverages Ant Design UI components (Form, Select, Input, Card, Button) and integrates translation support via react-i18next. It uses custom hooks to build dynamic select options based on the current node context, and supports adding/removing cases and conditions dynamically.


Detailed Explanation

Component: SwitchForm

A React functional component that renders a configurable switch-case form.

Props

interface IOperatorForm {
  onValuesChange: (changedValues: any, allValues: any) => void;
  node: {
    id: string;
    parentId?: string;
    // other node properties
  };
  form: FormInstance; // Ant Design form instance
}

Return


Key Internal Constants and Hooks


Form Structure and Behavior


Usage Example

import React from 'react';
import { Form } from 'antd';
import SwitchForm from './index';

const MySwitchFormWrapper = () => {
  const [form] = Form.useForm();

  const onFormChange = (changedValues, allValues) => {
    console.log('Form changed:', allValues);
  };

  const node = { id: 'node-1', parentId: 'parent-1' };

  return (
    <SwitchForm onValuesChange={onFormChange} node={node} form={form} />
  );
};

export default MySwitchFormWrapper;

Important Implementation Details


Interaction with Other Parts of the System

This component likely serves as part of a UI builder or workflow editor where users visually configure conditional branching logic.


Visual Diagram

componentDiagram
    component SwitchForm {
        +onValuesChange
        +node
        +form
        -- Hooks & State --
        useTranslation()
        useBuildFormSelectOptions()
        useBuildComponentIdSelectOptions()
        useMemo() for options
        -- Form Structure --
        Form.List "conditions" (Cases)
        ├─ Card per Case
        │  ├─ Logical Operator Select (conditional)
        │  ├─ Next Step ("to") Select
        │  └─ Form.List "items" (Conditions)
        │     ├─ Card per Condition
        │     │  ├─ ComponentId Select
        │     │  ├─ Operator Select
        │     │  └─ Value Input
        │     └─ Add Condition Button
        ├─ Add Case Button
        ELSE Select (outside cases)
    }

Summary

index.tsx exports a sophisticated form component to visually build switch-case logic with nested conditions and branching options. It carefully manages dynamic form fields, localized UI, and contextual select options to enable users to create complex logical flows in an intuitive interface. This component integrates tightly with the system's workflow node context and data sources via custom hooks and utilities.