import React, { useState } from 'react'; import { Button } from '../../components/Button/Button'; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, } from '../../components/DropdownMenu'; import { Icons } from '../../components/Icons/Icons'; import { Tooltip, TooltipTrigger, TooltipContent } from '../../components/Tooltip/Tooltip'; /** * DataRow is a complex UI component that displays a selectable, interactive row with hierarchical data. * It's designed to show a numbered item with a title, optional color indicator, and expandable details. * The row supports various interactive features like visibility toggling, locking, and contextual actions. * * @component * @example * ```tsx * {}} * onToggleLocked={() => {}} * onRename={() => {}} * onDelete={() => {}} * onColor={() => {}} * /> * ``` */ /** * Props for the DataRow component * @interface DataRowProps * @property {number} number - The display number/index of the row * @property {string} title - The main text label for the row * @property {boolean} disableEditing - When true, prevents rename and delete operations * @property {string} [colorHex] - Optional hex color code to display a color indicator * @property {Object} [details] - Optional hierarchical details to display below the row * @property {string[]} details.primary - Primary details shown immediately below the row * @property {string[]} details.secondary - Secondary details (currently unused) * @property {boolean} [isSelected] - Whether the row is currently selected * @property {() => void} [onSelect] - Callback when the row is clicked/selected * @property {boolean} isVisible - Controls the row's visibility state * @property {() => void} onToggleVisibility - Callback to toggle visibility * @property {boolean} isLocked - Controls the row's locked state * @property {() => void} onToggleLocked - Callback to toggle locked state * @property {() => void} onRename - Callback when rename is requested * @property {() => void} onDelete - Callback when delete is requested * @property {() => void} onColor - Callback when color change is requested */ interface DataRowProps { number: number; disableEditing: boolean; description: string; details?: { primary: string[]; secondary: string[] }; // isSelected?: boolean; onSelect?: () => void; // isVisible: boolean; onToggleVisibility: () => void; // isLocked: boolean; onToggleLocked: () => void; // title: string; onRename: () => void; // onDelete: () => void; // colorHex?: string; onColor: () => void; } const DataRow: React.FC = ({ number, title, colorHex, details, onSelect, isLocked, onToggleVisibility, onToggleLocked, onRename, onDelete, onColor, isSelected = false, isVisible = true, disableEditing = false, }) => { const [isDropdownOpen, setIsDropdownOpen] = useState(false); const isTitleLong = title?.length > 25; const handleAction = (action: string, e: React.MouseEvent) => { e.stopPropagation(); switch (action) { case 'Rename': onRename(); break; case 'Lock': onToggleLocked(); break; case 'Delete': onDelete(); break; case 'Color': onColor(); break; } }; const decodeHTML = (html: string) => { const txt = document.createElement('textarea'); txt.innerHTML = html; return txt.value; }; const renderDetailText = (text: string, indent: number = 0) => { const indentation = ' '.repeat(indent); if (text === '') { return (
); } const cleanText = decodeHTML(text); return (
{indentation} {cleanText}
); }; const renderDetails = (details: string[]) => { const visibleLines = details.slice(0, 4); const hiddenLines = details.slice(4); return (
{visibleLines.map((line, lineIndex) => renderDetailText(line, line.startsWith(' ') ? 1 : 0) )}
{hiddenLines.length > 0 && (
...
)}
{details.map((line, lineIndex) => renderDetailText(line, line.startsWith(' ') ? 1 : 0) )}
); }; return (
{/* Hover Overlay */}
{/* Number Box */}
{number}
{/* Color Circle (Optional) */} {colorHex && (
)} {/* Label with Conditional Tooltip */}
{isTitleLong ? ( {title} {title} ) : ( {title} )}
{/* Actions and Visibility Toggle */}
{/* Visibility Toggle Icon */} {/* Lock Icon (if needed) */} {isLocked && } {/* Actions Dropdown Menu */} setIsDropdownOpen(open)}> {!disableEditing && ( <> handleAction('Rename', e)}> Rename handleAction('Delete', e)}> Delete {onColor && ( handleAction('Color', e)}> Change Color )} )} handleAction('Lock', e)}> {isLocked ? 'Unlock' : 'Lock'}
{/* Details Section */} {details && (details.primary?.length > 0 || details.secondary?.length > 0) && (
{details.primary?.length > 0 && renderDetails(details.primary)} {details.secondary?.length > 0 && (
{renderDetails(details.secondary)}
)}
)}
); }; export default DataRow;