index.tsx


Overview

index.tsx defines a React functional component named ChunkCreatingModal that provides a modal dialog interface for creating or editing a "chunk" entity within a document parsing or knowledge management system. This modal form allows users to input or modify various chunk-related data such as content, keywords, questions, tags, and feature tags, with appropriate UI controls including text areas, tag editors, switches, and tooltips.

The component supports both creation and editing modes, distinguished by the presence of a chunkId prop. It integrates with custom hooks to fetch existing chunk data for editing and to delete chunks. It also uses internationalization for multi-language support and React Hook Form for form state management and validation.


Component: ChunkCreatingModal

Purpose

To present a modal dialog that enables users to create a new chunk or edit an existing one, managing chunk attributes and providing controls for enabling/disabling and deleting the chunk.

Props

The component accepts the following props:

Prop Name

Type

Description

doc_id

string

The ID of the document to which the chunk belongs.

chunkId

[string \

undefined](/projects/311/74002)

parserId

string

Identifier for the parser type, used to conditionally render form fields (e.g., 'tag').

hideModal

() => void

Callback to hide/close the modal.

onOk

(values: any) => void

Callback invoked when the form is submitted successfully with the chunk data.

loading

boolean

Loading state to show a loading indicator on the modal's confirmation button.

Internal State

State

Type

Description

checked

boolean

Controls the enabled/disabled state of the chunk.

Hooks Used


Form Fields and Behavior


Methods and Callbacks

onSubmit(values: FieldValues) => void

handleOk() => void

handleRemove() => Promise<void | undefined>

handleCheck() => void


Side Effects


Rendering Structure


Usage Example

<ChunkCreatingModal
  doc_id="document123"
  chunkId="chunk456"
  parserId="tag"
  hideModal={() => setShowModal(false)}
  onOk={(chunkData) => console.log('Chunk saved:', chunkData)}
  loading={false}
/>

Important Implementation Details


Interaction with Other Parts of the System


Mermaid Component Diagram

componentDiagram
    ChunkCreatingModal --|> Modal
    ChunkCreatingModal --> Form
    ChunkCreatingModal --> EditTag
    ChunkCreatingModal --> TagFeatureItem
    ChunkCreatingModal --> Switch
    ChunkCreatingModal --> Textarea
    ChunkCreatingModal --> HoverCard
    ChunkCreatingModal ..> useFetchChunk : data fetching
    ChunkCreatingModal ..> useDeleteChunkByIds : chunk deletion
    ChunkCreatingModal ..> useTranslation : i18n
    ChunkCreatingModal ..> react-hook-form : form management

Summary

index.tsx exports a single React component ChunkCreatingModal that is a sophisticated modal form for creating or editing document chunks with rich keyword and tag metadata. It leverages multiple custom and shared hooks/components, manages complex form state and data transformations, and supports internationalization and user-friendly UI interactions such as tooltips and toggles. This component is a key UI element for chunk management workflows in the broader application.