import React from 'react'; import {useTable} from '@gravity-ui/table'; import type {CellContext, ColumnDef, ExpandedState} from '@tanstack/react-table'; import {ColumnHeader, Table} from '../../../../../../components/Table/Table'; import type {SimplifiedPlanItem} from '../../../../../../store/reducers/query/types'; import {configuredNumeral} from '../../../../../../utils/numeral'; import {formatToMs} from '../../../../../../utils/timeParsers'; import {toExponential} from '../../../../../../utils/utils'; import {MetricsCell} from './MetricsCell'; import {OperationCell} from './OperationCell'; import type {ExtendedSimplifiesPlanItem} from './types'; import {block, getExtendedTreeNodes} from './utils'; import './SimplifiedPlan.scss'; function nameAccessorFn(row: ExtendedSimplifiesPlanItem) { return {name: row.name, operationParams: row.operationParams, lines: row.lines}; } function metricsCell(info: CellContext) { const formatter = (value: number) => value < 1e8 ? configuredNumeral(value).format() : toExponential(value, 1); return ; } function cpuCell(info: CellContext) { const formatter = (value: number) => formatToMs(Math.round(value)); return ; } const columns: ColumnDef[] = [ { accessorKey: 'name', accessorFn: nameAccessorFn, header: () => Operation, size: 600, cell: (info) => ( >()} /> ), }, { accessorKey: 'aCpu', header: () => A-Cpu, size: 90, minSize: 90, cell: cpuCell, meta: {align: 'right', verticalAlign: 'top'}, }, { accessorKey: 'aRows', header: () => A-Rows, size: 90, minSize: 90, cell: metricsCell, meta: {align: 'right', verticalAlign: 'top'}, }, { accessorKey: 'eCost', header: () => E-Cost, size: 90, minSize: 90, cell: metricsCell, meta: {align: 'right', verticalAlign: 'top'}, }, { accessorKey: 'eRows', header: () => E-Rows, size: 90, minSize: 90, cell: metricsCell, meta: {align: 'right', verticalAlign: 'top'}, }, { accessorKey: 'eSize', header: () => E-Size, size: 90, minSize: 90, cell: metricsCell, meta: {align: 'right', verticalAlign: 'top'}, }, ]; interface SimplifiedPlanProps { plan: SimplifiedPlanItem[]; } export function SimplifiedPlan({plan}: SimplifiedPlanProps) { const planWithLinesInfo = React.useMemo(() => getExtendedTreeNodes(plan), [plan]); const [expanded, setExpanded] = React.useState(true); const table = useTable({ columns, data: planWithLinesInfo, getSubRows: (item) => item.children, enableExpanding: true, onExpandedChange: setExpanded, state: { expanded, }, enableColumnResizing: true, columnResizeMode: 'onChange', }); return ; }