query-variable.tsx


Overview

The query-variable.tsx file defines a React functional component named QueryVariable. This component provides a form field that allows users to select a query variable from a searchable dropdown list. The dropdown options are dynamically generated and optionally filtered by a specified variable type. It integrates tightly with react-hook-form for form state management and uses internationalization support via react-i18next.

This component is intended for use within forms that require selecting or specifying query variables, likely in a broader application context related to building or configuring queries (e.g., for data filtering or API requests).


Detailed Explanation

QueryVariable Component

function QueryVariable({
  name = 'query',
  type,
  label,
}: QueryVariableProps): JSX.Element

Description

QueryVariable renders a form field with a label and a searchable select dropdown for choosing query variables. It leverages the useFormContext hook to integrate with react-hook-form's form control, ensuring that the selected value is managed within the form's state.

Props

Return Value

Returns a React JSX element rendering the form field with the filtered variable options.

Usage Example

<QueryVariable 
  name="userQuery" 
  type="string" 
  label={<span>User Query</span>} 
/>

This example renders the QueryVariable form field with a custom label "User Query", filters options to only those of type including "string", and uses "userQuery" as the form field name.


Implementation Details and Algorithms


Interaction with Other Parts of the System


Component Structure Diagram

classDiagram
    class QueryVariable {
      +name: string
      +type: VariableType | undefined
      +label: ReactNode | undefined
      +render(): JSX.Element
    }

    QueryVariable ..> SelectWithSearch : uses
    QueryVariable ..> FormField : uses
    QueryVariable ..> useBuildQueryVariableOptions : calls
    QueryVariable ..> useFormContext : calls
    QueryVariable ..> useTranslation : calls

Summary

The query-variable.tsx file provides a reusable, localized, and form-integrated React component to select query variables from dynamically generated and optionally filtered options. It abstracts away the complexity of fetching and filtering options, localization, and form integration, making it easy to embed query variable selection in forms throughout the application.

This component depends on several shared modules including UI form components, a custom select-with-search component, translation hooks, and a custom hook for fetching query variable options. It is designed for use within a react-hook-form managed form environment.


End of Documentation for query-variable.tsx