variable-table.tsx

Overview

variable-table.tsx defines a React functional component named VariableTable that renders a fully-featured, interactive data table displaying a list of variables. Each variable record contains a key, a reference, and a value. The table supports sorting, filtering, pagination, and dynamic column visibility using the powerful @tanstack/react-table library.

The component also provides inline actions for editing and deleting records, with UI elements enhanced by tooltips and icons to improve user experience. It integrates with translation utilities for internationalization and uses custom hooks and UI components consistent with the surrounding application.


Detailed Documentation

Component: VariableTable

Purpose

Displays a table of variables with columns for key, reference label, and value. Supports sorting, filtering, pagination, and visibility toggling for columns. Includes edit and delete actions per row.

Props

Prop Name

Type

Required

Description

data

VariableFormSchemaType[]

Yes

Array of variable records to display in the table.

deleteRecord

(index: number) => void

Yes

Callback function invoked when a delete action is triggered on a row. Receives row index.

showModal

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

Yes

Callback function to show an edit modal. Receives row index and the record data.

nodeId

string

No

Optional node identifier used to retrieve variable labels via a custom hook.

Internal State

Libraries and Hooks Used

Columns Definition

The table defines these columns:

Column Key

Header (Translated)

Cell Renderer

Notes

key

flow.key

Displays the variable key with a tooltip showing the full key on hover.

Text truncated with tooltip

ref

flow.ref

Displays a label for the reference value obtained via getLabel(ref). Tooltip shows full label.

Uses custom hook for label

value

flow.value

Displays the raw value of the variable.

Simple text display

actions

common.action

Renders edit and delete buttons with icons. Clicking triggers respective callbacks with row info.

Buttons styled transparently

Table Configuration

Rendered Output


Usage Example

import { VariableTable } from './variable-table';
import { useState } from 'react';

function Example() {
  const [variables, setVariables] = useState<VariableFormSchemaType[]>([
    { key: 'var1', ref: 'ref1', value: 'Value 1' },
    { key: 'var2', ref: 'ref2', value: 'Value 2' },
  ]);

  function handleDelete(index: number) {
    setVariables((prev) => prev.filter((_, i) => i !== index));
  }

  function handleShowModal(index: number, record: VariableFormSchemaType) {
    console.log('Edit variable', index, record);
    // Show modal logic here...
  }

  return (
    <VariableTable
      data={variables}
      deleteRecord={handleDelete}
      showModal={handleShowModal}
      nodeId="node-123"
    />
  );
}

Important Implementation Details


Interactions with Other System Parts


Visual Diagram

classDiagram
    class VariableTable {
        +props: IProps
        +state: sorting, columnFilters, columnVisibility
        +columns: ColumnDef[]
        +render()
    }

    VariableTable --> useReactTable
    VariableTable --> useGetVariableLabelByValue
    VariableTable --> useTranslation
    VariableTable ..> Table : uses
    VariableTable ..> Button : uses
    VariableTable ..> Tooltip : uses
    VariableTable ..> Pencil : uses (icon)
    VariableTable ..> Trash2 : uses (icon)

Summary

The variable-table.tsx file provides a reusable, customizable React component for displaying and managing a table of variables. It leverages modern React table utilities for rich features and integrates seamlessly with translation and UI libraries. Its design cleanly separates presentation from data handling by relying on props for actions, making it a flexible building block in the overall system.