index.tsx
Overview
This file defines a React functional component InvokeForm that provides a comprehensive form interface for configuring and invoking HTTP requests within a larger workflow or flow editor system. It leverages React Hook Form for form state management, integrates Monaco Editor for editing JSON headers, and supports dynamic variable management via modal dialogs and tables.
The form supports configuring key HTTP request parameters such as URL, method (GET, POST, PUT), timeout, headers (as JSON), proxy, and a toggle for cleaning HTML responses. It also allows the user to define, edit, and delete variables used within the request parameters. The form includes validation using Zod schemas and supports internationalization via react-i18next.
This component is memoized to optimize rendering performance and is designed to be embedded within a node-based workflow editor or similar system.
Detailed Explanation
Enumerations and Constants
enum Method
Defines HTTP methods supported by the form:
Value | Description |
|---|---|
GET | HTTP GET method |
POST | HTTP POST method |
PUT | HTTP PUT method |
MethodOptions
An array of objects mapping method names to { label, value } pairs for use in the method selection dropdown.
Interface: TimeoutInputProps
Props for the TimeoutInput component.
Property | Type | Description |
|---|---|---|
| [number \ | undefined](/projects/311/74002) |
| [(value: number \ | null) => void \ |
Component: TimeoutInput
A small controlled input component that allows users to input a numeric timeout value in seconds. It uses a custom NumberInput component and displays a localized label for "seconds".
Parameters:
value: current timeout valueonChange: callback when value changes
Usage Example:
<TimeoutInput value={10} onChange={(val) => console.log(val)} />
Main Component: InvokeForm
Primary exported component, memoized for performance.
Props:
Property | Type | Description |
|---|---|---|
|
| Represents the current workflow node this form configures. |
Functionality:
Initializes form state with default values merged with values from the current node.
Uses
react-hook-formwith Zod schema validation (FormSchema).Watches
variablesfield to dynamically update variable tables.Uses custom hooks (
useEditVariableRecord,useWatchFormChange) to manage variable editing and form change effects.Renders fields for:
URL (text input)
Method (select dropdown)
Timeout (custom numeric input with seconds label)
Headers (JSON editor via Monaco Editor)
Proxy (text input)
Clean HTML (boolean switch)
Hidden
variablesfield (to keep form state consistent)
Provides a collapsible section for managing variables:
Displays variables in a table
Allows adding new variables via a modal dialog
Supports deleting variables
Renders an output section displaying the output list derived from initial invoke values.
Properties and Methods within InvokeForm
Form Initialization:
const form = useForm<FormSchemaType>({ defaultValues, resolver: zodResolver(FormSchema), mode: 'onChange', });Uses
zodResolverfor schema validation.mode: 'onChange'triggers validation on each input change.
Variable Record Editing Hooks:
Provides modal visibility state, current editing record, and handlers for showing, hiding, submitting, and deleting variable records.
Form Field Rendering:
Uses
FormFieldcomponents with controlled inputs linked to form state.Variable Management UI:
Collapsible section with a button to add variables, showing a
VariableTablelisting current variables, and aVariableDialogmodal for editing/adding variables.Output Display:
Shows the output list generated from constants.
Usage Example
import InvokeForm from './index';
function MyNodeComponent({ node }) {
return <InvokeForm node={node} />;
}
Important Implementation Details
Monaco Editor Configuration:
The file configures Monaco Editor's loader path to
/vs:loader.config({ paths: { vs: '/vs' } });Internationalization:
Uses
useTranslationhook fromreact-i18nextto provide localized labels and tooltips.Form Validation:
Relies on Zod schema (
FormSchema) to enforce input correctness.Variable Management:
Variables are managed outside the form UI but integrated via a hidden form field to maintain consistency.
Memoization:
The entire
InvokeFormis wrapped in React'smemoto avoid unnecessary re-renders.Custom Hooks:
useEditVariableRecord: Handles logic for editing variable records, including modal visibility and deletion.useWatchFormChange: Reacts to changes in form values, possibly syncing with external state.
Component Composition:
Combines multiple reusable UI components like
FormContainer,FormWrapper,Collapse, and UI primitives (Input, Select, Switch, Button) for a consistent user experience.
Interaction with Other System Components
Workflow Node (
INextOperatorForm):The
nodeprop represents a workflow node whose data is edited by this form.Constants and Utilities:
initialInvokeValues: Provides default values for the form.buildOutputList: Builds a list of outputs for display.
Variable Management Components:
VariableTable: Displays the list of variables.VariableDialog: Modal dialog for editing/adding variables.
Schema and Types:
FormSchemaandFormSchemaTypedefine form validation rules.Interfaces and types ensure type safety and clarity.
Hooks:
useFormValues: Initializes form values based on node data.useEditVariableRecord: Variable editing logic.useWatchFormChange: Side effects on form changes.
UI Components:
Imported from shared component libraries under
@/components/*for consistency across the application.
Visual Diagram
componentDiagram
component "InvokeForm" {
+render()
-form : useForm<FormSchemaType>
-variables : watched form field
-showModal()
-hideModal()
-ok()
-handleDeleteRecord()
}
component "TimeoutInput" {
+render()
-value: number | undefined
-onChange: (number | null) => void
}
component "VariableTable"
component "VariableDialog"
component "FormWrapper"
component "FormContainer"
component "Collapse"
component "Output"
component "Monaco Editor"
InvokeForm --> TimeoutInput : uses
InvokeForm --> VariableTable : embeds
InvokeForm --> VariableDialog : embeds (conditional)
InvokeForm --> FormWrapper : wraps form
InvokeForm --> FormContainer : contains form fields
InvokeForm --> Collapse : toggles variable section
InvokeForm --> Output : renders output list
FormField --> Monaco Editor : for headers editing
Summary
This file implements a complex, validated, and internationalized HTTP invocation form as part of a node-based workflow editor. It integrates sophisticated UI components and hooks to manage variables, form state, and output display, providing users with a rich interface to configure HTTP requests dynamically within a larger system.