From 70d0ae42bc86e102ecdd932d02f8e83e57847385 Mon Sep 17 00:00:00 2001 From: Irina Kuzmina Date: Fri, 20 Sep 2024 13:36:12 +0300 Subject: [PATCH 1/2] fix scroll in the pivot table (#1583) --- .../renderer/components/Table/TableBody.tsx | 1 + .../Table/renderer/components/Table/types.ts | 1 + .../components/Table/usePreparedTableData.ts | 26 ++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/TableBody.tsx b/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/TableBody.tsx index 987d8cb68e..432fe32eb5 100644 --- a/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/TableBody.tsx +++ b/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/TableBody.tsx @@ -39,6 +39,7 @@ export const TableBody = React.memo((props: Props) => { gridColumn: cell.colSpan ? `span ${cell.colSpan}` : undefined, + maxHeight: cell.maxHeight, }} onClick={(event) => { if (onCellClick) { diff --git a/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/types.ts b/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/types.ts index 3a4892006d..01c055d392 100644 --- a/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/types.ts +++ b/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/types.ts @@ -106,6 +106,7 @@ export type BodyCellViewData = { index: number; /* Original cell data */ data: unknown; + maxHeight?: number; }; export type BodyRowViewData = { diff --git a/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/usePreparedTableData.ts b/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/usePreparedTableData.ts index 2678582678..1829c339b9 100644 --- a/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/usePreparedTableData.ts +++ b/src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/usePreparedTableData.ts @@ -208,6 +208,11 @@ export const usePreparedTableData = (props: { const headers = table.getHeaderGroups(); const tableRows = table.getRowModel().rows; + const enableRowGrouping = React.useMemo( + () => data.head?.some((cell) => get(cell, 'group', false)), + [data.head], + ); + const rowMeasures = React.useRef>({}); React.useEffect(() => { rowMeasures.current = {}; @@ -218,14 +223,22 @@ export const usePreparedTableData = (props: { estimateSize: () => 30, getScrollElement: () => tableContainerRef.current, measureElement: (el) => { - const rowIndex = el.getAttribute('data-index') ?? ''; - if (rowIndex && typeof rowMeasures.current[rowIndex] === 'undefined') { + const getRowHeight = () => { const cells = Array.from(el?.getElementsByTagName('td') || []); const simpleCell = cells.find((c) => { const rowSpan = Number(c.getAttribute('rowspan')) || 0; return rowSpan <= 1; }); - rowMeasures.current[rowIndex] = simpleCell?.getBoundingClientRect()?.height ?? 0; + return simpleCell?.getBoundingClientRect()?.height ?? 0; + }; + + if (!enableRowGrouping) { + return getRowHeight(); + } + + const rowIndex = el.getAttribute('data-index') ?? ''; + if (rowIndex && typeof rowMeasures.current[rowIndex] === 'undefined') { + rowMeasures.current[rowIndex] = getRowHeight(); } return rowMeasures.current[rowIndex]; @@ -236,7 +249,7 @@ export const usePreparedTableData = (props: { const virtualItems = prerender ? new Array(Math.min(tableRows.length, PRERENDER_ROW_COUNT)) .fill(null) - .map((_, index) => ({index, start: 0})) + .map((_, index) => ({index, start: 0, size: undefined})) : rowVirtualizer.getVirtualItems(); const headerRows = headers @@ -333,6 +346,10 @@ export const usePreparedTableData = (props: { ) ) { prevCell.rowSpan += 1; + if (prevCell.maxHeight && virtualRow.size) { + prevCell.maxHeight += virtualRow.size; + } + return acc; } } @@ -378,6 +395,7 @@ export const usePreparedTableData = (props: { : originalCellData?.className, rowSpan: 1, data: originalCellData, + maxHeight: enableRowGrouping ? virtualRow.size : undefined, }; prevCells[index] = rowsAcc.length; From 4a75b98a5d4c038090a5e11f032bff8129951a6a Mon Sep 17 00:00:00 2001 From: Andrey Melikhov Date: Fri, 20 Sep 2024 16:31:18 +0300 Subject: [PATCH 2/2] Add Math.E (#1584) --- .../isolated-sandbox/isolated-sandbox-chart-builder.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server/components/charts-engine/components/processor/isolated-sandbox/isolated-sandbox-chart-builder.ts b/src/server/components/charts-engine/components/processor/isolated-sandbox/isolated-sandbox-chart-builder.ts index 86ee0ec579..d5f261d315 100644 --- a/src/server/components/charts-engine/components/processor/isolated-sandbox/isolated-sandbox-chart-builder.ts +++ b/src/server/components/charts-engine/components/processor/isolated-sandbox/isolated-sandbox-chart-builder.ts @@ -58,7 +58,10 @@ export const getIsolatedSandboxChartBuilder = async ( const context = isolate.createContextSync(); const getQLConnectionTypeMap = registry.getQLConnectionTypeMap(); context.evalSync( - `const __modules = {}; + ` + // I do not know why, but this is not exists in V8 Isolate. + Math.E = ${Math.E}; + const __modules = {}; let __params; let __usedParams; let __runtimeMetadata = {userParamsOverride: undefined};