@@ -67,13 +67,61 @@ function TablesView() {
6767 return initial ;
6868 } ,
6969 ) ;
70+ const [ recentlyEmptyTables , setRecentlyEmptyTables ] = useState < Map < string , number > > ( new Map ( ) ) ;
7071 const tables = Object . values ( state . tables ) ;
7172 const elementRefs = useRef < Map < string , HTMLElement > > ( new Map ( ) ) ;
73+ const previousTablesRef = useRef < Map < string , { loaded : boolean ; rowCount ?: number } > > ( new Map ( ) ) ;
7274
7375 // Throttled debug logging - starts after 10s, then every 10s
7476 const lastDebugLogTime = useRef < number > ( 0 ) ;
7577 const debugLogStartTime = useRef < number > ( Date . now ( ) ) ;
7678
79+ // Track when tables become empty and delay their movement to empty section
80+ useEffect ( ( ) => {
81+ const now = Date . now ( ) ;
82+ const newRecentlyEmpty = new Map ( recentlyEmptyTables ) ;
83+ let hasChanges = false ;
84+
85+ // Check for newly loaded empty tables
86+ tables . forEach ( ( table ) => {
87+ const prevState = previousTablesRef . current . get ( table . name ) ;
88+
89+ // Detect transition: table just became loaded with 0 rows
90+ if ( table . loaded && table . rowCount === 0 && ! recentlyEmptyTables . has ( table . name ) ) {
91+ // Check if this is a new state (wasn't loaded before, or rowCount just became 0)
92+ const justLoaded = ! prevState || ! prevState . loaded ;
93+ const rowCountJustBecameZero = prevState && prevState . loaded && prevState . rowCount !== 0 ;
94+
95+ if ( justLoaded || rowCountJustBecameZero ) {
96+ // This table just became empty
97+ console . log ( `Table ${ table . name } just loaded with 0 rows - delaying move to empty section` ) ;
98+ newRecentlyEmpty . set ( table . name , now ) ;
99+ hasChanges = true ;
100+
101+ // Set timeout to remove from recently empty after 3 seconds
102+ setTimeout ( ( ) => {
103+ console . log ( `Moving ${ table . name } to empty section after 3s delay` ) ;
104+ setRecentlyEmptyTables ( ( prev ) => {
105+ const next = new Map ( prev ) ;
106+ next . delete ( table . name ) ;
107+ return next ;
108+ } ) ;
109+ } , 3000 ) ;
110+ }
111+ }
112+
113+ // Update previous state
114+ previousTablesRef . current . set ( table . name , {
115+ loaded : table . loaded ,
116+ rowCount : table . rowCount ,
117+ } ) ;
118+ } ) ;
119+
120+ if ( hasChanges ) {
121+ setRecentlyEmptyTables ( newRecentlyEmpty ) ;
122+ }
123+ } , [ tables , recentlyEmptyTables ] ) ;
124+
77125 // Register element with refs
78126 const registerElement = useCallback (
79127 ( id : string , element : HTMLElement | null ) => {
@@ -199,10 +247,10 @@ function TablesView() {
199247
200248 for ( const [ clusterKey , tables ] of tablesByCluster . entries ( ) ) {
201249 const regularTables = tables . filter (
202- ( t ) => ! t . loaded || t . rowCount === undefined || t . rowCount > 0 ,
250+ ( t ) => ! t . loaded || t . rowCount === undefined || t . rowCount > 0 || recentlyEmptyTables . has ( t . name ) ,
203251 ) ;
204252 const emptyTables = tables . filter (
205- ( t ) => t . loaded && t . rowCount === 0 ,
253+ ( t ) => t . loaded && t . rowCount === 0 && ! recentlyEmptyTables . has ( t . name ) ,
206254 ) ;
207255
208256 groups . push ( {
@@ -221,7 +269,7 @@ function TablesView() {
221269 } ) ;
222270
223271 return groups ;
224- } , [ tablesByCluster ] ) ;
272+ } , [ tablesByCluster , recentlyEmptyTables ] ) ;
225273
226274 // Auto-expand sections when filtering
227275 useEffect ( ( ) => {
0 commit comments