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


Enum: Method

Defines supported HTTP methods for the form.

enum Method {
  GET = 'GET',
  POST = 'POST',
  PUT = 'PUT',
}

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

value

`number \

undefined`

onChange

`(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)} />

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

form

FormInstance (AntD)

The form instance object for controlling form state.

onValuesChange

(changedValues, allValues) => void

Callback triggered whenever form values change.

node

any (likely an object)

Represents the node or operator context, passed to DynamicVariablesForm.

Return Value

Usage Example

<InvokeForm
  form={formInstance}
  node={currentNode}
  onValuesChange={(changed, all) => console.log(all)}
/>

Important Implementation Details


Interaction with Other Parts of the System


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

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.