Skip to content

Commit 57a1299

Browse files
authored
Merge pull request #1798 from visualize-admin/fix/table-height
fix: Table height
2 parents 9c36fad + 7f2cd12 commit 57a1299

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ You can also check the
1111

1212
# Unreleased
1313

14-
Nothing yet.
14+
- Fixes
15+
- Last table row is no longer cut
1516

1617
# [4.9.2] - 2024-10-04
1718

app/charts/table/table-content.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const useStyles = makeStyles((theme: Theme) => ({
6161
minHeight: SORTING_ARROW_WIDTH,
6262
alignItems: "center",
6363
justifyContent: "flex-start",
64+
whiteSpace: "nowrap",
6465
},
6566
headerGroupMeasure: {
6667
justifyContent: "flex-end",

app/charts/table/table-state.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from "@/charts/shared/chart-state";
2626
import { useSize } from "@/charts/shared/use-size";
2727
import { BAR_CELL_PADDING, TABLE_HEIGHT } from "@/charts/table/constants";
28+
import { getTableUIElementsOffset } from "@/charts/table/table";
2829
import {
2930
TableStateVariables,
3031
useTableStateData,
@@ -128,9 +129,17 @@ const useTableState = (
128129
left: 10,
129130
};
130131
const chartWidth = width - margins.left - margins.right; // We probably don't need this
131-
const chartHeight = Math.min(TABLE_HEIGHT, chartData.length * rowHeight);
132+
const chartHeight = Math.min(
133+
TABLE_HEIGHT,
134+
// + 1 for the header row
135+
(chartData.length + 1) * rowHeight
136+
);
132137

133-
const height = chartHeight + margins.top + margins.bottom;
138+
const height =
139+
chartHeight +
140+
margins.top +
141+
margins.bottom +
142+
getTableUIElementsOffset({ showSearch: settings.showSearch, width });
134143
const bounds = {
135144
width,
136145
height,

app/charts/table/table.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ const useStyles = makeStyles(() => {
6262
};
6363
});
6464

65+
const shouldShowCompactMobileView = (width: number) => {
66+
return width < MOBILE_VIEW_THRESHOLD;
67+
};
68+
69+
/** Use to make sure we don't cut the table off by having other UI elements enabled */
70+
export const getTableUIElementsOffset = ({
71+
showSearch,
72+
width,
73+
}: {
74+
showSearch: boolean;
75+
width: number;
76+
}) => {
77+
return (
78+
(showSearch ? 48 : 0) + (shouldShowCompactMobileView(width) ? 48 : 0) + 4
79+
);
80+
};
81+
6582
export const Table = () => {
6683
const {
6784
bounds,
@@ -78,8 +95,7 @@ export const Table = () => {
7895

7996
const [compactMobileViewEnabled, setCompactMobileView] = useState(false);
8097

81-
const showCompactMobileView =
82-
bounds.width < MOBILE_VIEW_THRESHOLD && compactMobileViewEnabled;
98+
const showCompactMobileView = shouldShowCompactMobileView(bounds.width);
8399

84100
// Search & filter data
85101
const [searchTerm, setSearchTerm] = useState("");
@@ -211,7 +227,7 @@ export const Table = () => {
211227
style: {
212228
...style,
213229
flexDirection: "column",
214-
width: "max-content",
230+
width: "100%",
215231
},
216232
})}
217233
>
@@ -281,6 +297,10 @@ export const Table = () => {
281297
tableColumnsMeta,
282298
]
283299
);
300+
const defaultListHeightOffset = getTableUIElementsOffset({
301+
showSearch,
302+
width: bounds.width,
303+
});
284304

285305
return (
286306
<>
@@ -311,7 +331,7 @@ export const Table = () => {
311331
/>
312332
</Box>
313333

314-
{showCompactMobileView ? (
334+
{showCompactMobileView && compactMobileViewEnabled ? (
315335
/* Compact Mobile View */
316336
<Box
317337
sx={{
@@ -327,7 +347,7 @@ export const Table = () => {
327347
{({ width, height }: { width: number; height: number }) => (
328348
<VariableSizeList
329349
key={rows.length} // Reset when groups are toggled because itemSize remains cached per index
330-
height={height}
350+
height={height - defaultListHeightOffset}
331351
itemCount={rows.length}
332352
itemSize={getMobileItemSize}
333353
width={width}
@@ -359,7 +379,8 @@ export const Table = () => {
359379
{({ height }: { height: number }) => (
360380
<FixedSizeList
361381
outerElementType={TableContentWrapper}
362-
height={height}
382+
// row height = header row height
383+
height={height - defaultListHeightOffset - rowHeight}
363384
itemCount={rows.length}
364385
itemSize={rowHeight} // depends on whether a column has bars (40px or 56px)
365386
width="100%"

0 commit comments

Comments
 (0)