Skip to content

Commit

Permalink
replace useRef by prop
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Oct 7, 2022
1 parent 15d0314 commit fcefb26
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions superset-frontend/src/components/FilterableTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ const FilterableTable = ({
.map(key => widthsForColumnsByKey[key])
.reduce((curr, next) => curr + next),
);
const totalTableHeight = useRef(height);
const container = useRef<HTMLDivElement>(null);

const fitTableToWidthIfNeeded = () => {
Expand All @@ -348,10 +347,6 @@ const FilterableTable = ({
fitTableToWidthIfNeeded();
}, []);

useEffect(() => {
totalTableHeight.current = height;
}, [height]);

const hasMatch = (text: string, row: Datum) => {
const values: string[] = [];
Object.keys(row).forEach(key => {
Expand Down Expand Up @@ -567,15 +562,13 @@ const FilterableTable = ({
};

const renderGrid = () => {
totalTableHeight.current = height;
if (
// exclude the height of the horizontal scroll bar from the height of the table
// and the height of the table container if the content overflows
const totalTableHeight =
container.current &&
totalTableWidth.current > container.current.clientWidth
) {
// exclude the height of the horizontal scroll bar from the height of the table
// and the height of the table container if the content overflows
totalTableHeight.current -= SCROLL_BAR_HEIGHT;
}
? height - SCROLL_BAR_HEIGHT
: height;

const getColumnWidth = ({ index }: { index: number }) =>
widthsForColumnsByKey[orderedColumnKeys[index]];
Expand Down Expand Up @@ -604,7 +597,7 @@ const FilterableTable = ({
cellRenderer={renderGridCell}
columnCount={orderedColumnKeys.length}
columnWidth={getColumnWidth}
height={totalTableHeight.current - rowHeight}
height={totalTableHeight - rowHeight}
onScroll={onScroll}
overscanColumnCount={overscanColumnCount}
overscanRowCount={overscanRowCount}
Expand Down Expand Up @@ -648,15 +641,13 @@ const FilterableTable = ({
);
}

totalTableHeight.current = height;
if (
// exclude the height of the horizontal scroll bar from the height of the table
// and the height of the table container if the content overflows
const totalTableHeight =
container.current &&
totalTableWidth.current > container.current.clientWidth
) {
// exclude the height of the horizontal scroll bar from the height of the table
// and the height of the table container if the content overflows
totalTableHeight.current -= SCROLL_BAR_HEIGHT;
}
? height - SCROLL_BAR_HEIGHT
: height;

const rowGetter = ({ index }: { index: number }) =>
getDatum(sortedAndFilteredList, index);
Expand All @@ -669,7 +660,7 @@ const FilterableTable = ({
{fitted && (
<Table
headerHeight={headerHeight}
height={totalTableHeight.current}
height={totalTableHeight}
overscanRowCount={overscanRowCount}
rowClassName={rowClassName}
rowHeight={rowHeight}
Expand Down

0 comments on commit fcefb26

Please sign in to comment.