dataset-creating-dialog.tsx
Overview
dataset-creating-dialog.tsx defines React components that provide a user interface for creating a new dataset (or "knowledge base") by entering a name into a form within a modal dialog. It leverages form validation with zod and react-hook-form, internationalization via react-i18next, and custom UI components for dialogs, inputs, and buttons.
The primary functionality includes:
Displaying a modal dialog with a form for dataset creation.
Validating user input (dataset name) with instant feedback.
Submitting the form data to a parent component through a callback.
Displaying loading state during submission.
Components and Functions
Constants
FormId: string
Value:
'dataset-creating-form'Purpose: Used as the HTML form's
idattribute and referenced by the submit button to trigger form submission.
InputForm
function InputForm({ onOk }: IModalProps<any>): JSX.Element
Description
Renders a form with a single input field for entering the dataset name. It uses react-hook-form integrated with a zod schema for validation. When the form is submitted successfully, it calls the onOk callback with the dataset name.
Parameters
onOk: (data: any) => void
Callback function invoked when the form is submitted successfully. Receives the dataset name string as an argument.
Internal Details
Validation Schema:
Useszodto enforce:name: required string, minimum length 1, trimmed.parseType: optional number (defaulted to 1 but not exposed in form UI).
Localization:
UsesuseTranslation()for UI strings such as labels and placeholders.UI Elements:
Composed of custom form components (Form,FormField,FormItem, etc.) wrapping anInputcomponent.
Return Value
A JSX element representing a form ready for rendering.
Usage Example
<InputForm onOk={(datasetName) => console.log('Dataset created:', datasetName)} />
DatasetCreatingDialog
function DatasetCreatingDialog({
hideModal,
onOk,
loading,
}: IModalProps<any>): JSX.Element
Description
Renders a modal dialog containing the InputForm component and a submit button. It controls the dialog visibility and handles form submission and loading state display.
Parameters
hideModal: () => void
Callback to close or hide the modal dialog.onOk: (data: any) => void
Callback function passed down toInputFormto receive the submitted dataset name.loading: boolean
Boolean flag indicating whether the form submission is in progress; disables the submit button and shows a loading spinner.
Implementation Details
Uses custom
Dialog,DialogContent,DialogHeader,DialogTitle, andDialogFootercomponents to structure the modal.The submit button (
ButtonLoading) is linked to the form via theformattribute withFormId.The dialog is always open (
openprop) and visibility is controlled externally viahideModal.
Return Value
A JSX element representing the modal dialog for dataset creation.
Usage Example
<DatasetCreatingDialog
hideModal={() => setDialogOpen(false)}
onOk={(datasetName) => saveDataset(datasetName)}
loading={isSaving}
/>
Important Implementation Details
Form Validation:
Validation is performed usingzodschemas integrated withreact-hook-formthroughzodResolver. This provides type-safe validation and error feedback.Internationalization (i18n):
All static text strings such as labels, placeholders, and button text are retrieved via theuseTranslationhook, allowing easy localization.Form Submission:
The form submission is handled internally inInputFormand triggers theonOkprop callback with the entered dataset name, decoupling UI from business logic.Modal Behavior:
The dialog does not manage its own open state internally; it relies on props to control visibility (hideModalcallback).
Interaction with Other System Parts
UI Components:
Depends on shared UI components from the application’s UI library (@/components/ui/*), ensuring consistent styling and behavior.Form Management:
Integrates withreact-hook-formandzodfor form state and validation.Localization:
Uses thereact-i18nextlibrary for translation, implying integration with the app’s internationalization setup.Parent Components:
This dialog component is designed to be controlled by parent components that manage modal visibility and handle the dataset creation logic after form submission.
Visual Diagram
classDiagram
class InputForm {
+onOk: function
+onSubmit(data)
-form: react-hook-form instance
+render(): JSX.Element
}
class DatasetCreatingDialog {
+hideModal: function
+onOk: function
+loading: boolean
+render(): JSX.Element
}
DatasetCreatingDialog "1" --> "1" InputForm : renders >
Summary
dataset-creating-dialog.tsx provides a modal dialog UI for creating datasets.
It features robust form validation and internationalized UI text.
The file exports two main React functional components:
InputForm(form UI and logic) andDatasetCreatingDialog(modal container).Designed to integrate seamlessly with the app’s UI components, form handling, and i18n system.
Parent components control modal visibility and handle creation logic via callbacks.