query-table.tsx


Overview

query-table.tsx is a React functional component that renders a collapsible table displaying a list of query parameters or variables, typically representing input data for a flow or process. It is designed to present key details of each query item such as its key, name, type, and whether it is optional, along with providing user actions to edit or delete each record.

This component leverages Ant Design UI components (Table, Collapse, Tooltip, Space) for structured and interactive display, and uses icons from Ant Design icons library for action buttons. It also integrates internationalization support via react-i18next for multi-language text rendering.


Detailed Explanation

Component: QueryTable

Purpose

Displays a collapsible section containing a table of query items (BeginQuery[]), with columns for key, name, type, optional status, and action buttons (edit/delete).

Props

Prop

Type

Description

data

BeginQuery[]

Array of query records to be displayed in the table. Each record corresponds to a query parameter.

deleteRecord

(index: number) => void

Callback function invoked when the delete icon is clicked. Receives the index of the record to delete.

showModal

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

Callback function invoked when the edit icon is clicked. Receives the index and the record to be edited.

Return Value

Usage Example

import React, { useState } from 'react';
import QueryTable from './query-table';
import { BeginQuery } from '../../interface';

const exampleData: BeginQuery[] = [
  { key: 'userId', name: 'User ID', type: 'string', optional: false },
  { key: 'age', name: 'Age', type: 'number', optional: true },
];

const MyComponent = () => {
  const [data, setData] = useState(exampleData);

  const deleteRecord = (index: number) => {
    setData(prev => prev.filter((_, i) => i !== index));
  };

  const showModal = (index: number, record: BeginQuery) => {
    // Show modal to edit the record
    console.log('Edit record', index, record);
  };

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

Implementation Details

Columns Definition

Styling and Localization

Component Structure


Interaction with Other System Parts


Visual Diagram

componentDiagram
    component QueryTable {
        +data: BeginQuery[]
        +deleteRecord(index: number): void
        +showModal(index: number, record: BeginQuery): void
        +columns: TableColumns
        +render()
    }
    
    component Collapse {
        +items: CollapsePanel[]
    }
    
    component Table {
        +columns: TableColumns
        +dataSource: BeginQuery[]
        +pagination: boolean
    }
    
    QueryTable --> Collapse : renders inside
    Collapse --> Table : contains

Summary

query-table.tsx is a reusable, localized React component designed to display a list of query parameters in a neat, collapsible table with user-friendly tooltips and action controls for editing and deleting entries. It cleanly separates UI concerns from data management by delegating state changes to parent components via callbacks, making it adaptable in various application contexts that handle flow input variables or similar data structures.