variable-dialog.tsx


Overview

variable-dialog.tsx is a React component file defining a modal dialog interface for creating or editing "variables" within a flow or query system. It leverages a form with validation to collect variable properties such as a unique key, a reference, and a value. The dialog encapsulates user input with immediate validation feedback and integrates with the broader UI through reusable components.

The main export is VariableDialog, a modal dialog component that wraps a VariableForm form component. VariableForm handles form state management, validation, and submission using react-hook-form and zod schema validation.

This file is intended to be used anywhere in the application where users need to configure or modify variables that are part of a flow, query, or similar construct.


Exports

VariableDialog (Function Component)

Description

The VariableDialog component provides a modal dialog UI to create or edit a variable. It displays a form (VariableForm) inside a dialog box with header, content, and footer sections. The footer contains a submit button that triggers form submission.

Props

VariableDialog accepts the following combined props:

Prop

Type

Description

initialValue

VariableFormSchemaType

Initial form values to populate the form (for editing).

hideModal

(open: boolean) => void

Callback to close/hide the modal dialog.

otherThanCurrentQuery

VariableFormSchemaType[]

Array of other variables (except current) to validate uniqueness of keys.

submit

(values: any) => void

Callback invoked on form submission with form values.

Usage Example

<VariableDialog
  initialValue={{ key: 'var1', ref: 'ref1', value: 'val1' }}
  otherThanCurrentQuery={[{ key: 'var2', ref: 'ref2', value: 'val2' }]}
  hideModal={() => setShowModal(false)}
  submit={(values) => console.log('Submitted:', values)}
/>

Internal Components and Functions

VariableForm (Function Component)

Description

VariableForm renders the form inside the dialog. It manages form state, validation, and submission using react-hook-form integrated with zod for schema validation. It provides fields for key, ref, and value with respective validations and UI controls.

Props

Prop

Type

Description

initialValue

VariableFormSchemaType

Initial values used to reset the form on mount/update.

otherThanCurrentQuery

VariableFormSchemaType[]

List of other variables to check for key uniqueness.

submit

(values: any) => void

Callback invoked when form is successfully submitted.

Form Fields & Validation

Field

Type

Validation

key

string

Required, trimmed, must be unique among otherThanCurrentQuery keys (no duplicates allowed).

ref

string

No explicit validation beyond string type.

value

string

No explicit validation beyond string type.

Implementation Details

Usage Example

<VariableForm
  initialValue={{ key: '', ref: '', value: '' }}
  otherThanCurrentQuery={[{ key: 'existingKey', ref: '', value: '' }]}
  submit={(values) => console.log('Form submitted:', values)}
/>

Important Implementation Details


Interaction with Other System Parts


Visual Diagram

componentDiagram
    VariableDialog <|-- VariableForm
    VariableDialog --> Dialog
    Dialog --> DialogContent
    DialogContent --> DialogHeader
    DialogContent --> DialogFooter
    DialogHeader --> DialogTitle
    DialogFooter --> Button
    VariableForm --> Form
    Form --> FormField_key
    Form --> QueryVariable_ref
    Form --> FormField_value
    FormField_key --> Input_key
    FormField_value --> Input_value

Summary

This file enables users to safely and intuitively manage variables within the app, ensuring data integrity and a consistent user experience.