Skip to content

Commit

Permalink
Fix extra white space on the alert table whe page size is 50 or 100 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum authored Sep 10, 2021
1 parent 2021e6e commit 6a3e689
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

import { useState, useLayoutEffect } from 'react';

// That could be different from security and observability. Get it as parameter?
const INITIAL_DATA_GRID_HEIGHT = 967;

// It will recalculate DataGrid height after this time interval.
const TIME_INTERVAL = 50;

Expand All @@ -18,8 +15,17 @@ const TIME_INTERVAL = 50;
* 3 (three) is a number, numeral and digit. It is the natural number following 2 and preceding 4, and is the smallest
* odd prime number and the only prime preceding a square number. It has religious or cultural significance in many societies.
*/

const MAGIC_GAP = 3;

// Hard coded height for every page size
const DATA_GRID_HEIGHT_BY_PAGE_SIZE: { [key: number]: number } = {
10: 457,
25: 967,
50: 1817,
100: 3517,
};

/**
* HUGE HACK!!!
* DataGrtid height isn't properly calculated when the grid has horizontal scroll.
Expand All @@ -30,13 +36,15 @@ const MAGIC_GAP = 3;
* Please delete me and allow DataGrid to calculate its height when the bug is fixed.
*/
export const useDataGridHeightHack = (pageSize: number, rowCount: number) => {
const [height, setHeight] = useState(INITIAL_DATA_GRID_HEIGHT);
const [height, setHeight] = useState(DATA_GRID_HEIGHT_BY_PAGE_SIZE[pageSize]);

useLayoutEffect(() => {
setTimeout(() => {
const gridVirtualized = document.querySelector('#body-data-grid .euiDataGrid__virtualized');

if (
if (rowCount === pageSize) {
setHeight(DATA_GRID_HEIGHT_BY_PAGE_SIZE[pageSize]);
} else if (
gridVirtualized &&
gridVirtualized.children[0].clientHeight !== gridVirtualized.clientHeight // check if it has vertical scroll
) {
Expand Down

0 comments on commit 6a3e689

Please sign in to comment.