index.tsx
Overview
index.tsx defines a React functional component named InvokeForm that provides a user interface form for configuring HTTP request parameters. The form includes fields such as URL, HTTP method, timeout, headers, proxy, and other request-related settings. It leverages the Ant Design (antd) library for UI components and the Monaco Editor for JSON header editing. The form also supports internationalization via react-i18next.
This component is designed to be embedded within a larger application workflow, likely as part of an operator or node configuration interface, where users specify details for invoking HTTP requests or API calls.
Detailed Explanation
External Dependencies
@monaco-editor/react: Provides a code editor component (
Editor) supporting syntax highlighting and themes.antd: UI component library offering form controls such as
Form,Input,Select,Space,Switch, andInputNumber.react-i18next: For translating UI text based on user locale.
DynamicVariablesForm: A custom form component imported locally, likely for managing dynamic or runtime variables associated with the node/operator.
IOperatorForm: TypeScript interface describing the props for
InvokeForm.
Enum: Method
Defines supported HTTP methods for the form.
enum Method {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
}
Used to populate the HTTP method dropdown.
Ensures type safety and consistency across the form.
Constant: MethodOptions
An array of objects mapping Method enum values to { label, value } pairs, suitable for feeding into the Ant Design Select component.
const MethodOptions = [Method.GET, Method.POST, Method.PUT].map((x) => ({
label: x,
value: x,
}));
Interface: TimeoutInputProps
Props for the TimeoutInput component.
Property | Type | Description |
|---|---|---|
| `number \ | undefined` |
| `(value: number \ | null) => void` \ |
Component: TimeoutInput
A custom input component wrapping Ant Design's InputNumber to accept a numeric timeout value, displaying the unit "seconds" after the input.
const TimeoutInput = ({ value, onChange }: TimeoutInputProps) => {
const { t } = useTranslation();
return (
<Space>
<InputNumber value={value} onChange={onChange} /> {t('common.s')}
</Space>
);
};
Usage Example:
<TimeoutInput value={30} onChange={(val) => console.log(val)} />
Displays an input for a number and the localized letter "s" (seconds).
Calls
onChangewhenever the number changes.
Component: InvokeForm
The main exported component that renders the form for HTTP invocation settings.
const InvokeForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const { t } = useTranslation();
return (
<Form
name="basic"
autoComplete="off"
form={form}
onValuesChange={onValuesChange}
layout={'vertical'}
>
{/* URL Input */}
<Form.Item name={'url'} label={t('flow.url')}>
<Input />
</Form.Item>
{/* HTTP Method Select */}
<Form.Item name={'method'} label={t('flow.method')} initialValue={Method.GET}>
<Select options={MethodOptions} />
</Form.Item>
{/* Timeout Input */}
<Form.Item name={'timeout'} label={t('flow.timeout')}>
<TimeoutInput />
</Form.Item>
{/* Headers Editor */}
<Form.Item name={'headers'} label={t('flow.headers')}>
<Editor height={200} defaultLanguage="json" theme="vs-dark" />
</Form.Item>
{/* Proxy Input */}
<Form.Item name={'proxy'} label={t('flow.proxy')}>
<Input />
</Form.Item>
{/* Clean HTML Switch */}
<Form.Item
name={'clean_html'}
label={t('flow.cleanHtml')}
tooltip={t('flow.cleanHtmlTip')}
>
<Switch />
</Form.Item>
{/* Data Type Select */}
<Form.Item name={'datatype'} label={t('flow.datatype')}>
<Select
options={[
{ value: 'json', label: 'application/json' },
{ value: 'formdata', label: 'multipart/form-data' },
]}
allowClear={true}
/>
</Form.Item>
{/* Dynamic Variables Subform */}
<DynamicVariablesForm node={node} />
</Form>
);
};
Props
InvokeForm receives props typed as IOperatorForm. Although the interface is imported and not defined in this file, based on usage:
Prop | Type | Description |
|---|---|---|
|
| The form instance object for controlling form state. |
|
| Callback triggered whenever form values change. |
|
| Represents the node or operator context, passed to |
Return Value
Returns a React fragment rendering a vertical Ant Design
Form.The form fields map to typical HTTP invocation parameters.
Usage Example
<InvokeForm
form={formInstance}
node={currentNode}
onValuesChange={(changed, all) => console.log(all)}
/>
Important Implementation Details
Monaco Editor Loader Configuration
loader.config({ paths: { vs: '/vs' } });This configures the Monaco Editor loader to use the path
/vsfor loading editor resources, typically required for proper Webpack or static resource serving.Internationalization
The component uses
useTranslationhook fromreact-i18nextto translate all UI labels and tooltips dynamically, supporting localization.Dynamic Variables
The form integrates a
DynamicVariablesFormcomponent, suggesting that the HTTP invocation supports dynamic or runtime variables. This subcomponent receives thenodeprop to customize variable handling according to the node context.Form Control
The form is fully controlled via props:
forminstance andonValuesChangecallback, allowing parent components to manage state and validation.Input Controls
URL, proxy: simple text inputs.
Method, datatype: dropdown selects with predefined options.
Timeout: numeric input with seconds label.
Headers: JSON editor using Monaco Editor.
Clean HTML: toggle switch with tooltip.
Interaction with Other Parts of the System
DynamicVariablesFormThis component is embedded within
InvokeFormand likely manages dynamic variables related to the current node/operator. Changes in dynamic variables probably influence the behavior or parameters of the HTTP invocation.IOperatorFormInterfaceThe props interface indicates that
InvokeFormis part of a system that manages operators or workflow nodes, likely in a visual or programmatic flow designer.Parent Components
Since the form is controlled, it relies on parent components to provide form state and handle changes, integrating with workflow or pipeline configuration management.
Resource Loading
The Monaco Editor configuration indicates that static resources are served from
/vs, which must be configured in the hosting environment.
Visual Diagram
componentDiagram
component InvokeForm {
+form: FormInstance
+onValuesChange(changedValues, allValues): void
+node: object
+renders Form with fields:
- url (Input)
- method (Select)
- timeout (TimeoutInput)
- headers (Monaco Editor)
- proxy (Input)
- clean_html (Switch)
- datatype (Select)
- DynamicVariablesForm (child component)
}
component TimeoutInput {
+value?: number
+onChange(value: number | null): void
+renders InputNumber + "s" label
}
component DynamicVariablesForm {
+node: object
+renders dynamic variables configuration UI
}
InvokeForm --> TimeoutInput : uses
InvokeForm --> DynamicVariablesForm : embeds
Summary
index.tsx exports
InvokeForm, a React component for configuring HTTP requests in a form.Uses Ant Design UI components and Monaco Editor for JSON editing.
Supports internationalization and dynamic variables.
Designed for embedding in workflow/operator configuration interfaces.
Provides a user-friendly interface for setting URL, method, timeout, headers, proxy, and related settings for HTTP invocation nodes.
This file is a key part of the UI that allows users to specify how HTTP requests are constructed and executed within a larger workflow or automation system.