Skip to content

Commit

Permalink
Merge branch 'main' into CHARTS-9840-mass-actions-datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
stpavlenko authored Sep 20, 2024
2 parents 9ae238e + 4a75b98 commit ac4eb0e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const TableBody = React.memo<Props>((props: Props) => {
gridColumn: cell.colSpan
? `span ${cell.colSpan}`
: undefined,
maxHeight: cell.maxHeight,
}}
onClick={(event) => {
if (onCellClick) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export type BodyCellViewData = {
index: number;
/* Original cell data */
data: unknown;
maxHeight?: number;
};

export type BodyRowViewData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, number>>({});
React.useEffect(() => {
rowMeasures.current = {};
Expand All @@ -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];
Expand All @@ -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
Expand Down Expand Up @@ -333,6 +346,10 @@ export const usePreparedTableData = (props: {
)
) {
prevCell.rowSpan += 1;
if (prevCell.maxHeight && virtualRow.size) {
prevCell.maxHeight += virtualRow.size;
}

return acc;
}
}
Expand Down Expand Up @@ -378,6 +395,7 @@ export const usePreparedTableData = (props: {
: originalCellData?.className,
rowSpan: 1,
data: originalCellData,
maxHeight: enableRowGrouping ? virtualRow.size : undefined,
};

prevCells[index] = rowsAcc.length;
Expand Down

0 comments on commit ac4eb0e

Please sign in to comment.