Skip to content

Commit 22473bd

Browse files
NicolappsConvex, Inc.
authored andcommitted
dash: fix height and number of rows in EmptyData (#43213)
GitOrigin-RevId: f0a71318db377585b8f55f556af3a690ea776ebb
1 parent 07e47ab commit 22473bd

File tree

1 file changed

+23
-4
lines changed
  • npm-packages/dashboard-common/src/features/data/components

1 file changed

+23
-4
lines changed

npm-packages/dashboard-common/src/features/data/components/EmptyData.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ChevronDownIcon,
66
DotsVerticalIcon,
77
} from "@radix-ui/react-icons";
8-
import { useContext } from "react";
8+
import { useContext, useEffect, useRef, useState } from "react";
99
import { CreateNewTable } from "@common/features/data/components/DataSidebar";
1010
import { EmptySection } from "@common/elements/EmptySection";
1111
import { useNents } from "@common/lib/useNents";
@@ -55,6 +55,24 @@ export function EmptyDataContent({
5555
const sizeMe = <div />;
5656
const [sized, { width }] = useSize(sizeMe);
5757

58+
const [fakeRowsCount, setFakeRowsCount] = useState(20);
59+
const tableContainerRef = useRef<HTMLDivElement>(null);
60+
useEffect(() => {
61+
if (!tableContainerRef.current) return;
62+
63+
const resizeObserver = new ResizeObserver((entries) => {
64+
for (const entry of entries) {
65+
const ROW_HEIGHT = 33;
66+
const rowsNeeded = Math.ceil(entry.contentRect.height / ROW_HEIGHT);
67+
setFakeRowsCount(rowsNeeded + 5);
68+
}
69+
});
70+
resizeObserver.observe(tableContainerRef.current);
71+
return () => {
72+
resizeObserver.disconnect();
73+
};
74+
}, []);
75+
5876
if (!tableMetadata) {
5977
return <Loading />;
6078
}
@@ -129,28 +147,29 @@ export function EmptyDataContent({
129147
<div
130148
className="flex h-full w-full flex-col overflow-hidden rounded-sm rounded-t-none border bg-background-secondary"
131149
inert
150+
ref={tableContainerRef}
132151
>
133152
<table className="h-full w-full table-fixed">
134153
<thead>
135154
<tr className="border-b bg-background-secondary">
136155
{EXAMPLE_COLUMNS.map((col) => (
137156
<th
138157
key={col}
139-
className="border-r p-3 text-left text-xs font-semibold text-content-secondary select-none last:border-r-0"
158+
className="border-r p-2.5 text-left text-xs font-semibold text-content-secondary select-none last:border-r-0"
140159
>
141160
{col}
142161
</th>
143162
))}
144163
</tr>
145164
</thead>
146165
<tbody className="divide-y">
147-
{Array.from({ length: 20 }).map((_, i) => (
166+
{Array.from({ length: fakeRowsCount }).map((_, i) => (
148167
<tr key={i} className="group">
149168
{EXAMPLE_COLUMNS.map((col) => (
150169
// eslint-disable-next-line jsx-a11y/control-has-associated-label
151170
<td
152171
key={col}
153-
className="border-r p-3 group-last:border-b-0 last:border-r-0"
172+
className="border-r p-2.5 group-last:border-b-0 last:border-r-0"
154173
>
155174
<div className="h-3 w-full max-w-64 bg-content-secondary/30" />
156175
</td>

0 commit comments

Comments
 (0)