|
5 | 5 | ChevronDownIcon, |
6 | 6 | DotsVerticalIcon, |
7 | 7 | } from "@radix-ui/react-icons"; |
8 | | -import { useContext } from "react"; |
| 8 | +import { useContext, useEffect, useRef, useState } from "react"; |
9 | 9 | import { CreateNewTable } from "@common/features/data/components/DataSidebar"; |
10 | 10 | import { EmptySection } from "@common/elements/EmptySection"; |
11 | 11 | import { useNents } from "@common/lib/useNents"; |
@@ -55,6 +55,24 @@ export function EmptyDataContent({ |
55 | 55 | const sizeMe = <div />; |
56 | 56 | const [sized, { width }] = useSize(sizeMe); |
57 | 57 |
|
| 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 | + |
58 | 76 | if (!tableMetadata) { |
59 | 77 | return <Loading />; |
60 | 78 | } |
@@ -129,28 +147,29 @@ export function EmptyDataContent({ |
129 | 147 | <div |
130 | 148 | className="flex h-full w-full flex-col overflow-hidden rounded-sm rounded-t-none border bg-background-secondary" |
131 | 149 | inert |
| 150 | + ref={tableContainerRef} |
132 | 151 | > |
133 | 152 | <table className="h-full w-full table-fixed"> |
134 | 153 | <thead> |
135 | 154 | <tr className="border-b bg-background-secondary"> |
136 | 155 | {EXAMPLE_COLUMNS.map((col) => ( |
137 | 156 | <th |
138 | 157 | 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" |
140 | 159 | > |
141 | 160 | {col} |
142 | 161 | </th> |
143 | 162 | ))} |
144 | 163 | </tr> |
145 | 164 | </thead> |
146 | 165 | <tbody className="divide-y"> |
147 | | - {Array.from({ length: 20 }).map((_, i) => ( |
| 166 | + {Array.from({ length: fakeRowsCount }).map((_, i) => ( |
148 | 167 | <tr key={i} className="group"> |
149 | 168 | {EXAMPLE_COLUMNS.map((col) => ( |
150 | 169 | // eslint-disable-next-line jsx-a11y/control-has-associated-label |
151 | 170 | <td |
152 | 171 | 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" |
154 | 173 | > |
155 | 174 | <div className="h-3 w-full max-w-64 bg-content-secondary/30" /> |
156 | 175 | </td> |
|
0 commit comments