import React from 'react'; import {ActionTooltip, ArrowToggle, Button, Flex} from '@gravity-ui/uikit'; import type {Row} from '@tanstack/react-table'; import type {SimlifiedPlanOperatorOtherParams} from '../../../../../../types/api/query'; import i18n from '../../../i18n'; import {OperationParams} from './OperationParams'; import {block} from './utils'; const LEVEL_PADDING = 25; const FIRST_PADDING = 9; interface OperationCellProps { row: Row; depth?: number; params: {name: string; operationParams?: SimlifiedPlanOperatorOtherParams; lines?: string}; } interface DividerProps { modifiers?: Record; left: number; } function Divider({modifiers, left}: DividerProps) { return (
); } function getDividers(lines: string, hasVisibleSubNodes: boolean) { const linesArray = lines.split('.').map(Number); const dividers = []; for (let i = 0; i < linesArray.length; i++) { //logic for calculating left coordinate: FIRST_PADDING - is a padding from start of a level to the middle of toggle button // LEVEL_PADDING is a difference between levels // (i-1): in `lines` we have digits that point, should we paint a line for previous levels or not if (i === linesArray.length - 1 && i !== 0) { if (linesArray[i]) { //horizontal pointer to the node (├) dividers.push( , ); } else { //pointer to the last child in the branch (└) dividers.push( , ); } } if (i === linesArray.length - 1 && hasVisibleSubNodes) { //starting vertical line if node has leafs dividers.push( , ); } if (linesArray[i]) { //vertical line indicating level dividers.push(); } } return dividers; } export function OperationCell({row, depth = 0, params}: OperationCellProps) { const {name, operationParams, lines = ''} = params; const hasVisibleSubNodes = row.getLeafRows().length > 0 && row.getIsExpanded(); const dividers = React.useMemo( () => getDividers(lines, hasVisibleSubNodes), [lines, hasVisibleSubNodes], ); const isExpandable = row.getCanExpand(); const isExpanded = row.getIsExpanded(); return (
{dividers} {isExpandable && ( )}
{/* wrapper to inline elements */}
{name}  
); }