popover-form.tsx


Overview

popover-form.tsx defines the PopoverForm React component, a reusable UI element that combines an interactive popover with an embedded form designed to accept a URL input, validate it, parse the linked document, and then submit the parsed result. This component leverages Ant Design UI components and custom hooks to provide asynchronous data fetching and form state management within a popover interface.

The main functionality centers around allowing users to input a URL into a popover form. Upon submission, the URL is validated against a regex pattern, then processed asynchronously by the parseDocument function, which presumably fetches and extracts information from the document at the URL. The parsed data is then set into the form and submitted. The popover visibility and reset logic are controlled externally and internally to maintain UI consistency.


Component and Function Details

PopoverForm Component

export const PopoverForm = ({
  children,
  visible,
  switchVisible,
}: PropsWithChildren<IModalProps<any>>)

Description

PopoverForm is a functional React component that renders a clickable popover containing a form for URL input and submission. It validates the URL, processes the document via a hook, and submits the parsed result.

Parameters

These props extend IModalProps<any>, indicating the component is designed to be compatible with modal-like visibility control patterns.

Return Value

Usage Example

<PopoverForm visible={isPopoverVisible} switchVisible={setPopoverVisible}>
  <Button>Open URL Form</Button>
</PopoverForm>

Internal Logic and Hooks


Core Method: onOk

const onOk = async () => { ... }

Purpose

Handles submission when the user clicks the submit button:

  1. Validates the URL field.

  2. Checks the URL against a regex pattern (reg) ensuring proper URL format.

  3. Calls parseDocument asynchronously.

  4. If the parse is successful (code === 0), sets the parsed data into the hidden 'result' form field.

  5. Submits the form.

Parameters

Returns

Behavior Notes


Regex URL Validation: reg

const reg =
  /^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/;

JSX Structure


Implementation Details and Algorithms


Interaction with Other Parts of the System

This component is designed to be a modular building block for any UI requiring URL input and document parsing within a popover context, fitting into larger workflows involving document management or data extraction.


Visual Diagram

componentDiagram
    PopoverForm --|> React.Component
    PopoverForm o-- "Antd Popover" : renders
    PopoverForm o-- "Antd Form" : contains
    PopoverForm o-- "Antd Input" : url input field
    PopoverForm o-- "Antd Button" : submit button
    PopoverForm ..> useParseDocument : calls parseDocument()
    PopoverForm ..> useResetFormOnCloseModal : resets form on close
    PopoverForm ..> useTranslation : provides t()

Summary

popover-form.tsx exports a PopoverForm React component that encapsulates a URL input form inside a clickable popover. It validates URLs, asynchronously parses documents at those URLs, and submits the results while managing form state and visibility in an idiomatic React + Ant Design pattern. The component is internationalized and designed to integrate seamlessly with the system's document parsing logic and modal visibility controls.