From dda498784837d1c4634d66debadda807399a9093 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 19 Jun 2023 17:54:06 +0100 Subject: [PATCH] Improve grid row inversion index calculation --- .../src/components/grid/stores/viewport.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/viewport.js b/packages/frontend-core/src/components/grid/stores/viewport.js index a363ffca00..b03f10f8fa 100644 --- a/packages/frontend-core/src/components/grid/stores/viewport.js +++ b/packages/frontend-core/src/components/grid/stores/viewport.js @@ -111,14 +111,19 @@ export const deriveStores = context => { [height, rowHeight, scrollTop], ([$height, $rowHeight, $scrollTop]) => { const offset = $scrollTop % $rowHeight + + // Compute the last row index with space to render popovers below it const minBottom = $height - ScrollBarSize * 3 - MaxCellRenderHeight + offset - return Math.floor(minBottom / $rowHeight) + const lastIdx = Math.floor(minBottom / $rowHeight) - // const maxCellRenderRows = Math.ceil(MaxCellRenderHeight / $rowHeight) - // const topIdx = $visualRowCapacity - maxCellRenderRows - 2 - // const bottomIdx = maxCellRenderRows + 1 - // return Math.max(topIdx, bottomIdx) + // Compute the first row index with space to render popovers above it + const minTop = MaxCellRenderHeight + offset + const firstIdx = Math.ceil(minTop / $rowHeight) + + // Use the greater of the two indices so that we prefer content below, + // unless there is room to render the entire popover above + return Math.max(lastIdx, firstIdx) } )