dataset-dataflow-creating-dialog.tsx
Overview
dataset-dataflow-creating-dialog.tsx is a React component file that provides a user interface for creating a new dataset or knowledge base entry via a modal dialog. It leverages form validation, localization, and conditional rendering to capture user input in a structured way. The primary components are:
InputForm: A form component that handles user input, validation, and conditional sub-component rendering based on the selected parse type.DatasetCreatingDialog: A modal dialog component that wraps theInputFormand manages dialog visibility, loading state, and submission.
This file is part of a larger system managing datasets, knowledge extraction, and embedding models, integrating with reusable UI components and data configuration items.
Detailed Components and Functions
Constants
FormId: string
Value:
'dataset-creating-form'Purpose: Used as the
idattribute on the form, enabling the submit button outside the form element to trigger form submission.
InputForm Component
function InputForm({ onOk }: IModalProps<any>): JSX.Element
Purpose
Renders a form to input the dataset or knowledge base name and select parsing options. It validates user input using zod schema and conditionally renders additional configuration items based on the selected parse type.
Props
onOk: (data: any) => void— Callback function triggered upon successful form submission. Receives the dataset name string.
Internal Logic
Uses
react-hook-formto manage form state and validation.Validation schema defined with
zod:name: Required string, trimmed, with a localized error message.parseType: Optional number (default 1).
Watches the
parseTypefield to conditionally render additional UI sections.On submit, only the
nameis passed to theonOkcallback.
Rendered Form Fields
Name (
name):Input text field, required.
Label and placeholder localized via
react-i18next.
Embedding Model (
EmbeddingModelItem):Custom component, presumably to select an embedding model.
Parse Type (
ParseTypeItem):Custom component for selecting the parse type.
Conditional Fields (only if
parseType === 2):DataFlowItemDataExtractKnowledgeItemTeamItem
Usage Example
<InputForm onOk={(datasetName) => console.log('Dataset created:', datasetName)} />
DatasetCreatingDialog Component
function DatasetCreatingDialog({
hideModal,
onOk,
loading,
}: IModalProps<any>): JSX.Element
Purpose
Encapsulates the InputForm within a modal dialog. It controls the dialog's open state, submission loading state, and triggers callbacks when the dialog is closed or the form is submitted.
Props
hideModal: () => void— Function to close the modal dialog.onOk: (data: any) => void— Callback to handle form submission data.loading: boolean— Flag to indicate submission/loading state; disables the submit button and shows a loading spinner.
Structure and Behavior
Uses the
Dialog,DialogContent,DialogHeader,DialogFooter, andDialogTitleUI components to build the modal.Renders the localized title "Create Knowledge Base".
Includes the
InputFormcomponent.Renders a submit button (
ButtonLoading) outside the form but linked via theformattribute usingFormId. The button shows a loading indicator whenloadingis true.The dialog is always open (
openprop set), but closing triggershideModal.
Usage Example
<DatasetCreatingDialog
hideModal={() => setShowDialog(false)}
onOk={(name) => saveDataset(name)}
loading={isSaving}
/>
Important Implementation Details
Form Validation: Uses
zodschema validation integrated withreact-hook-formviazodResolver, ensuring consistent and typed validation logic.Dynamic Form Fields: Watches the
parseTypeform field to conditionally render additional configuration components (DataFlowItem,DataExtractKnowledgeItem,TeamItem). This allows the form to adapt based on user selections.Localization: All user-facing strings use the
useTranslationhook fromreact-i18nextfor internationalization.Form Submission: The submit button is outside the form element but connected via the
formattribute referencingFormId. This enables proper form submission from the dialog footer.Component Composition: The dialog and form components compose smaller UI pieces (
Input,FormItem, etc.) and domain-specific items (EmbeddingModelItem,ParseTypeItem, etc.) to maintain modularity and reusability.
Interaction with Other Parts of the System
Imports reusable UI components from a shared UI library (e.g.,
ButtonLoading,Dialog,Form,Input).Uses domain-specific configuration components imported from
../dataset/dataset-setting/configuration/common-item:EmbeddingModelItemParseTypeItemDataFlowItemDataExtractKnowledgeItemTeamItem
These likely encapsulate further configuration logic related to datasets and knowledge extraction.
The dialog component fits into a larger flow of dataset/knowledge base management, triggered by user actions in the application UI to create new dataset entries.
onOkcallbacks allow parent components or state managers to handle creation results (e.g., API calls, state updates).
Mermaid Component Diagram
componentDiagram
component DatasetCreatingDialog {
+hideModal()
+onOk(data)
+loading: boolean
--
uses InputForm
uses Dialog
uses ButtonLoading
}
component InputForm {
+onOk(data)
--
uses useForm (react-hook-form)
uses Form
uses Input
uses EmbeddingModelItem
uses ParseTypeItem
uses DataFlowItem (conditional)
uses DataExtractKnowledgeItem (conditional)
uses TeamItem (conditional)
}
Summary
dataset-dataflow-creating-dialog.tsx provides a modal dialog containing a validated, localized form for creating datasets or knowledge bases with conditional configuration options. It is designed for extensibility, localization, and integration with domain-specific components, supporting a clean UX flow for dataset creation within a larger application context.