Skip to content

Commit

Permalink
fix: count correctly the number of table headers that are rendered (#821
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TCL735 authored Oct 6, 2022
1 parent 909ac2c commit a88b2fb
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 17 deletions.
2 changes: 1 addition & 1 deletion giraffe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@influxdata/giraffe",
"version": "2.37.0",
"version": "2.37.1",
"main": "dist/index.js",
"module": "dist/index.js",
"license": "MIT",
Expand Down
29 changes: 14 additions & 15 deletions giraffe/src/components/SimpleTable/PagedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface ExtendedColumn {
data: any[]
}

const TABLE_MARGIN = 10

/*
* @param result - the result of the query
* @param paginationOffset - the start index of the first row of the current page
Expand Down Expand Up @@ -54,31 +56,28 @@ const getNumberOfRowsOnCurrentPage = (
let lastSignature
let signature

// rowHeight is now guaranteed to be greater than zero
const lastVisibleRowMinimumHeight = 0.2 * rowHeight

while (rowIdx < result.table.length) {
if (result.table.columns?.table?.data?.[rowIdx] !== currentTable) {
signature = Object.values(result.table.columns)
.map(
c =>
`${c.name}::${c.fluxDataType}::${result.fluxGroupKeyUnion.includes(
c.name
)}`
)
.map(column => {
if (column.data[rowIdx] !== undefined) {
return `${column.name}::${
column.fluxDataType
}::${result.fluxGroupKeyUnion.includes(column.name)}`
}
return 'undefined'
})
.join('|')

if (signature !== lastSignature) {
runningHeight += headerHeight

if (currentTable !== undefined) {
runningHeight += 10
runningHeight += TABLE_MARGIN
}

if (
runningHeight + lastVisibleRowMinimumHeight >=
totalAvailableHeight
) {
// Stop counting if the new table cannot fit even 1 row
if (runningHeight + rowHeight >= totalAvailableHeight) {
break
}

Expand All @@ -92,7 +91,7 @@ const getNumberOfRowsOnCurrentPage = (

runningHeight += rowHeight

if (runningHeight + lastVisibleRowMinimumHeight >= totalAvailableHeight) {
if (runningHeight >= totalAvailableHeight) {
break
}

Expand Down
2 changes: 1 addition & 1 deletion stories/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@influxdata/giraffe-stories",
"version": "2.37.0",
"version": "2.37.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit a88b2fb

Please sign in to comment.