query-table.tsx

Overview

query-table.tsx is a React functional component file that implements a highly interactive and customizable data table for displaying, sorting, filtering, and managing a collection of query records (BeginQuery objects). It leverages the @tanstack/react-table library for table state management and rendering logic, and integrates UI components from a shared design system including buttons, tooltips, and table elements.

The component supports:

This file is designed as a client-side React component ('use client' directive) and is intended to be part of a larger UI system that manages flows or queries, likely in an application where users can view and manipulate query-related data.


Detailed Explanation

Interfaces

IProps

interface IProps {
  data: BeginQuery[];
  deleteRecord(index: number): void;
  showModal(index: number, record: BeginQuery): void;
}

Component: QueryTable

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

Purpose

Renders a table showing query records with columns for key, name, type, optional flag, and action buttons. It manages sorting, filtering, and column visibility states and provides UI controls for editing and deleting each record.

Parameters

Return

JSX element rendering the complete table UI with header, body, and empty state.


Internal State

All states are managed with React's useState hooks and passed to the useReactTable hook.


Columns Definition

columns: ColumnDef<BeginQuery>[] defines the table columns:

Column Key

Header (i18n)

Cell Rendering

Notes

key

flow.key

Tooltip with truncated key value

Shows full key on hover

name

flow.name

Tooltip with truncated name value

Shows full name on hover

type

flow.type

Localized type string (lowercased)

Uses translation keys like flow.typevalue

optional

flow.optional

Displays "Yes" or "No"

Boolean representation

actions

common.action

Buttons with Pencil (edit) and Trash2 (delete) icons

Calls showModal and deleteRecord respectively

Each tooltip is implemented using Tooltip, TooltipTrigger, and TooltipContent components.


Table Instance Setup

The component uses the useReactTable hook with the following configuration:


Rendering Logic


Usage Example

import { QueryTable } from './query-table';
import { BeginQuery } from '../../interface';

const sampleData: BeginQuery[] = [
  {
    key: 'query1',
    name: 'Get Users',
    type: 'SQL',
    optional: false,
  },
  {
    key: 'query2',
    name: 'Get Orders',
    type: 'API',
    optional: true,
  },
];

function App() {
  const handleDelete = (index: number) => {
    console.log('Delete record at index:', index);
    // Implement delete logic
  };

  const handleShowModal = (index: number, record: BeginQuery) => {
    console.log('Show modal for:', record);
    // Implement modal logic
  };

  return (
    <QueryTable data={sampleData} deleteRecord={handleDelete} showModal={handleShowModal} />
  );
}

Important Implementation Details


Interaction with Other System Parts

This component acts as a reusable, self-contained table view for query entities, fitting into a larger application workflow involving query management.


Mermaid Component Diagram

componentDiagram
    QueryTable <|-- Table
    QueryTable <|-- Button
    QueryTable <|-- Tooltip
    QueryTable <|-- TableEmpty
    QueryTable *-- useReactTable
    useReactTable --> @tanstack/react-table
    QueryTable ..> BeginQuery : data type
    QueryTable ..> react-i18next : useTranslation()
    QueryTable ..> cn : utility function

Summary

query-table.tsx provides a fully featured, localized, and interactive data table component for displaying and managing query records. It combines advanced table state management via @tanstack/react-table with a modular UI component library, enabling sorting, filtering, pagination, and row-level actions. This component is designed for reuse and integration in any React-based system dealing with query or flow data entities.