query-table.tsx


Overview

query-table.tsx is a React functional component file that implements a dynamic, interactive data table named QueryTable. This table is designed to display a list of query records (BeginQuery objects) with capabilities such as sorting, filtering, pagination, and column visibility toggling. It also includes row-level actions to edit or delete individual records.

The component leverages the powerful and flexible @tanstack/react-table library for table state management and rendering and integrates UI components such as buttons, tooltips, and table elements from a custom UI library (@/components/ui/*). Localization is supported via the react-i18next library.


Detailed Explanation

Interfaces

IProps

The QueryTable component expects props conforming to the IProps interface:

Property

Type

Description

data

BeginQuery[]

Array of query records to display in the table. Defaults to an empty array if not provided.

deleteRecord

(index: number) => void

Callback function invoked when a user clicks the delete action on a row. Receives the row index.

showModal

(index: number, record: BeginQuery) => void

Callback function invoked when a user clicks the edit action on a row. Receives the row index and the full record.


QueryTable Component

function QueryTable({ data = [], deleteRecord, showModal }: IProps)

Purpose

Renders a fully-featured table that displays query records with support for:

Parameters

Returns

Usage Example

<QueryTable 
  data={queries}
  deleteRecord={(idx) => handleDelete(idx)}
  showModal={(idx, record) => openEditModal(idx, record)}
/>

Internal State & Hooks


Columns Definition

The table columns are defined in a ColumnDef<BeginQuery>[] array:

Column Key

Header Text (localized)

Cell Rendering Details

Special Notes

key

t('flow.key')

Displays the key value truncated with a tooltip showing full value on hover.

Uses tooltip UI components.

name

t('flow.name')

Displays the name value truncated with tooltip.

Same as key.

type

t('flow.type')

Displays the type value localized and lowercased.

Shows localized type string.

optional

t('flow.optional')

Shows "Yes" if true, "No" if false.

Boolean display.

actions

t('common.action')

Displays edit (pencil icon) and delete (trash icon) buttons. Clicking triggers handlers passed in props.

Actions column is fixed visible (enableHiding: false).


Table Setup with useReactTable

The table instance is created with:


Rendering


Implementation Details / Algorithms


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    component QueryTable {
        +props: IProps
        +state: sorting, columnFilters, columnVisibility
        +columns: ColumnDef<BeginQuery>[]
        +methods: render()
    }
    component BeginQuery
    component useReactTable
    component TableUI {
        Table
        TableHeader
        TableBody
        TableRow
        TableCell
        Button
        Tooltip
    }
    QueryTable --> BeginQuery : data[]
    QueryTable --> useReactTable : manages sorting, filtering, pagination
    QueryTable --> TableUI : renders table structure & UI
    QueryTable --> "Parent Component" : deleteRecord(), showModal()

Summary

query-table.tsx defines a reusable, localized, and highly interactive data table React component named QueryTable. It leverages @tanstack/react-table for advanced table features, integrates custom UI components for a polished look and feel, and provides edit/delete functionality through callbacks. The component is designed to be a presentational and interactive layer that delegates data mutations and modal controls to parent components, supporting separation of concerns and modular design.