index.tsx
Overview
This file defines the InvokeForm React component, which is a form interface for configuring an HTTP invocation step within a workflow or flow-based system. The form allows users to specify HTTP request details such as URL, method, timeout, headers, proxy, and HTML cleaning options. It also supports managing request variables through a nested parameter editor with modal dialogs.
The form uses React Hook Form for state management and validation, with schema validation powered by Zod. It integrates several UI components (inputs, switches, selects, code editor) to build a rich and interactive user experience.
This component is memoized for performance optimization and relies on external hooks and utilities to handle form values, watch changes, and manage variable editing.
Components, Functions, and Types
Enum: Method
enum Method {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
}
Defines supported HTTP methods for the invocation.
Used for populating the method select input.
Constant: MethodOptions
const MethodOptions = [Method.GET, Method.POST, Method.PUT].map((x) => ({
label: x,
value: x,
}));
Array of objects for select options corresponding to HTTP methods.
Each option has a
labelandvalueequal to the method string.
Interface: TimeoutInputProps
interface TimeoutInputProps {
value?: number;
onChange?: (value: number | null) => void;
}
Props for the
TimeoutInputcomponent.valueis the current timeout value in seconds.onChangeis a callback when the timeout value changes, accepting a number or null.
Component: TimeoutInput
const TimeoutInput = ({ value, onChange }: TimeoutInputProps) => {
const { t } = useTranslation();
return (
<div className="flex gap-2 items-center">
<NumberInput value={value} onChange={onChange} /> {t('flow.seconds')}
</div>
);
};
A simple input for entering timeout values in seconds.
Uses a
NumberInputcomponent and displays a localized "seconds" label.Props:
value: current numeric timeout.onChange: handler to update timeout.
Usage:
<TimeoutInput value={30} onChange={(val) => console.log(val)} />
Constant: outputList
const outputList = buildOutputList(initialInvokeValues.outputs);
Builds a list of output definitions for display using a utility function.
Uses
initialInvokeValues.outputsas the base data.This list is passed to the
Outputcomponent to show expected outputs of the invocation.
Main Component: InvokeForm
function InvokeForm({ node }: INextOperatorForm) { ... }
The primary exported component that renders the entire invocation form.
Props:
node: The current node in the workflow graph, typed asINextOperatorForm.
Features:
Uses
useFormfrom React Hook Form with a Zod schema resolver for validation.Initializes form values based on the
nodeandinitialInvokeValues.Uses a custom hook
useEditVariableRecordto manage variable editing modals and state.Watches
variablesfield for dynamic variable list updates.Contains form fields:
url: HTTP URL input.method: HTTP method select.timeout: Timeout input in seconds.headers: JSON code editor for HTTP headers.proxy: Proxy input string.clean_html: Switch to enable/disable cleaning of HTML responses.variables: Hidden field to register variables with the form.
Includes a collapsible section to display and manage variables.
Renders a modal dialog (
VariableDialog) when editing variables.Displays output information below the form.
Returns:
JSX element representing the form UI.
Usage example:
<InvokeForm node={someNode} />
Important Implementation Details
Form Validation: Uses
zodResolverwith aFormSchemaimported from./schema. This ensures form data correctness before submission.Form State Management: React Hook Form manages input states, form validation, and change detection.
Variables Management: Variables are handled with a combination of watched form state and custom hooks (
useEditVariableRecord) that open modals for adding/editing/deleting parameters.Code Editor Integration: The
@monaco-editor/reactpackage is used to provide a JSON editor for HTTP headers, configured for dark theme and JSON syntax.Localization: All labels and text strings are internationalized with
react-i18next.Memoization: The component is wrapped with
memoto prevent unnecessary re-renders.UI Components: Uses a consistent UI component library (
@/components/ui) and custom components for inputs, switches, buttons, etc.Collapse Component: Used to toggle visibility of the parameters section.
Output Display: The
Outputcomponent at the bottom shows metadata about the outputs of this invocation.
Interaction with Other Parts of the System
Hooks:
useFormValuesprepares initial form values based on the current node.useWatchFormChangetracks form changes to synchronize or trigger side effects.useEditVariableRecordencapsulates logic for managing the variable editing modal and state.
Components:
VariableTabledisplays the list of variables with controls to edit/delete.VariableDialogmodal allows editing or adding variables.FormWrapperandFormContainerprovide layout and styling for the form.
Utilities:
buildOutputListgenerates the output metadata for display.
Schema & Types:
FormSchemaandFormSchemaTypedefine the shape and validation of form data.
Constants:
initialInvokeValuesprovides default values and structure for the form.
Localization:
Integrates with the i18n system for localized UI.
This file acts as the user interface boundary for configuring HTTP invoke nodes within a larger flow-based application, likely part of a no-code/low-code or workflow automation platform.
Visual Diagram
componentDiagram
component InvokeForm {
+render()
}
component TimeoutInput {
+render()
}
component VariableTable {
+render()
}
component VariableDialog {
+render()
}
component Output {
+render()
}
component FormWrapper
component FormContainer
component useEditVariableRecord
component useFormValues
component useWatchFormChange
InvokeForm --> TimeoutInput : uses
InvokeForm --> VariableTable : uses
InvokeForm --> VariableDialog : uses (conditional)
InvokeForm --> Output : uses
InvokeForm --> FormWrapper : wraps form
InvokeForm --> FormContainer : wraps inputs
InvokeForm --> useEditVariableRecord : manages variables
InvokeForm --> useFormValues : initializes form
InvokeForm --> useWatchFormChange : watches form changes
Summary
The index.tsx file defines a sophisticated React component InvokeForm that enables users to configure HTTP invocation steps within a workflow system. It features comprehensive form fields, validation, variable management with modals, and output preview. The file leverages React Hook Form, Monaco Editor, i18n, and various custom UI components and hooks to create a user-friendly and robust form interface. It integrates closely with other parts of the system through hooks, schemas, and shared components to provide a seamless experience in editing invocation nodes.