web-crawl-modal.tsx


Overview

web-crawl-modal.tsx defines a React functional component WebCrawlModal that renders a modal dialog for inputting web crawl details, specifically a name and a URL. This component is designed to be used in a UI where users can initiate a web crawling operation by providing a document name and a target URL.

The modal includes form validation to ensure that:

Once the form is validated and submitted, the modal triggers a callback with the input data.


Detailed Explanation

Component: WebCrawlModal

Purpose

WebCrawlModal is a modal dialog component that collects two pieces of information from the user:

It ensures inputs are validated before submission and exposes hooks to manage modal visibility and handle submission.

Props

interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
  loading: boolean;
  onOk: (name: string, url: string) => void;
  showModal?(): void;
}

Internal Hooks and State

Methods

Render Output

The component renders an Ant Design <Modal> with:

Inside the modal, an Ant Design <Form> with two <Form.Item>s:

  1. Name Field

    • Label: "Name"

    • Validation: required, max length 10 (Note: message says 128, but max is 10 in rules — potential inconsistency)

    • Input placeholder: "Document name"

  2. URL Field

Usage Example

import React, { useState } from 'react';
import WebCrawlModal from './web-crawl-modal';

const Example = () => {
  const [visible, setVisible] = useState(false);

  const handleOk = (name: string, url: string) => {
    console.log('Starting web crawl:', name, url);
    setVisible(false);
    // Trigger web crawl logic here
  };

  return (
    <>
      <button onClick={() => setVisible(true)}>Start Web Crawl</button>
      <WebCrawlModal
        visible={visible}
        hideModal={() => setVisible(false)}
        loading={false}
        onOk={handleOk}
      />
    </>
  );
};

Important Implementation Details


Interactions with Other System Parts


Visual Diagram: Component Structure and Workflow

componentDiagram
    direction TB
    component WebCrawlModal {
      +visible: boolean
      +hideModal(): void
      +onOk(name: string, url: string): void
      -form: FormInstance
      -handleOk()
    }
    WebCrawlModal --> Modal
    WebCrawlModal --> Form
    Form --> FormItem_Name
    Form --> FormItem_URL
    WebCrawlModal ..> useTranslate : uses

    note right of WebCrawlModal
      1. Receives visible, hideModal, onOk props  
      2. Renders Modal containing Form  
      3. Validates input fields on OK  
      4. Calls onOk callback with validated inputs
    end note

Summary

web-crawl-modal.tsx provides a reusable, validated modal form component for collecting web crawl parameters (name and URL). It leverages Ant Design UI components and form validation, integrates with a modal management system, and supports internationalization. The component cleanly separates UI concerns from business logic by delegating the actual crawl initiation to the parent via the onOk callback.