@@ -286,6 +286,17 @@ function invalidateReferencePreviews(
286286 } )
287287}
288288
289+ function invalidateTableNames ( queryClient : ReturnType < typeof useQueryClient > ) {
290+ queryClient . invalidateQueries ( { queryKey : tableKeys . namesRoot ( ) } )
291+ }
292+
293+ function invalidateReferenceTablePreviews (
294+ queryClient : ReturnType < typeof useQueryClient > ,
295+ tableId : string
296+ ) {
297+ queryClient . invalidateQueries ( { queryKey : tableKeys . referencePreviewsForTable ( tableId ) } )
298+ }
299+
289300/**
290301 * Invalidate only the row-count surfaces — the table detail and the tables
291302 * list, both of which carry the unfiltered `rowCount`. Deliberately leaves
@@ -310,6 +321,7 @@ function invalidateTableSchema(queryClient: ReturnType<typeof useQueryClient>, t
310321 queryClient . invalidateQueries ( { queryKey : tableKeys . detail ( tableId ) } )
311322 queryClient . invalidateQueries ( { queryKey : tableKeys . rowsRoot ( tableId ) } )
312323 queryClient . invalidateQueries ( { queryKey : tableKeys . lists ( ) } )
324+ invalidateReferenceTablePreviews ( queryClient , tableId )
313325}
314326
315327/**
@@ -327,6 +339,7 @@ function invalidateTableSchemaOnly(
327339) {
328340 queryClient . invalidateQueries ( { queryKey : tableKeys . detail ( tableId ) } )
329341 queryClient . invalidateQueries ( { queryKey : tableKeys . lists ( ) } )
342+ invalidateReferenceTablePreviews ( queryClient , tableId )
330343}
331344
332345/**
@@ -736,6 +749,7 @@ export function useCreateTable(workspaceId: string) {
736749 } ,
737750 onSettled : ( ) => {
738751 queryClient . invalidateQueries ( { queryKey : tableKeys . lists ( ) } )
752+ invalidateTableNames ( queryClient )
739753 } ,
740754 } )
741755}
@@ -785,6 +799,8 @@ export function useRenameTable(workspaceId: string) {
785799 onSettled : ( _data , _error , variables ) => {
786800 queryClient . invalidateQueries ( { queryKey : tableKeys . detail ( variables . tableId ) } )
787801 queryClient . invalidateQueries ( { queryKey : tableKeys . lists ( ) } )
802+ invalidateTableNames ( queryClient )
803+ invalidateReferenceTablePreviews ( queryClient , variables . tableId )
788804 } ,
789805 } )
790806}
@@ -895,6 +911,8 @@ export function useDeleteTable(workspaceId: string) {
895911 } ,
896912 onSettled : ( _data , _error , tableId ) => {
897913 queryClient . invalidateQueries ( { queryKey : tableKeys . lists ( ) } )
914+ invalidateTableNames ( queryClient )
915+ invalidateReferenceTablePreviews ( queryClient , tableId )
898916 queryClient . removeQueries ( { queryKey : tableKeys . detail ( tableId ) } )
899917 queryClient . removeQueries ( { queryKey : tableKeys . rowsRoot ( tableId ) } )
900918 } ,
@@ -1986,8 +2004,12 @@ export function useRestoreTable() {
19862004 onSettled : ( _data , _error , tableId ) => {
19872005 return Promise . all ( [
19882006 queryClient . invalidateQueries ( { queryKey : tableKeys . lists ( ) } ) ,
2007+ queryClient . invalidateQueries ( { queryKey : tableKeys . namesRoot ( ) } ) ,
19892008 queryClient . invalidateQueries ( { queryKey : tableKeys . detail ( tableId ) } ) ,
19902009 queryClient . invalidateQueries ( { queryKey : tableKeys . rowsRoot ( tableId ) } ) ,
2010+ queryClient . invalidateQueries ( {
2011+ queryKey : tableKeys . referencePreviewsForTable ( tableId ) ,
2012+ } ) ,
19912013 ] )
19922014 } ,
19932015 } )
@@ -2105,6 +2127,7 @@ export function useImportCsv() {
21052127 } ,
21062128 onSettled : ( ) => {
21072129 queryClient . invalidateQueries ( { queryKey : tableKeys . lists ( ) } )
2130+ invalidateTableNames ( queryClient )
21082131 } ,
21092132 } )
21102133}
@@ -2149,6 +2172,7 @@ export function useImportFileAsTable() {
21492172 } ,
21502173 onSettled : ( ) => {
21512174 queryClient . invalidateQueries ( { queryKey : tableKeys . lists ( ) } )
2175+ invalidateTableNames ( queryClient )
21522176 } ,
21532177 } )
21542178}
@@ -2816,6 +2840,8 @@ export function useBulkDeleteTables(workspaceId: string) {
28162840 } ,
28172841 onSettled : ( _data , _error , { tableIds = [ ] } ) => {
28182842 queryClient . invalidateQueries ( { queryKey : tableKeys . lists ( ) } )
2843+ invalidateTableNames ( queryClient )
2844+ queryClient . invalidateQueries ( { queryKey : tableKeys . referencePreviews ( ) } )
28192845 queryClient . invalidateQueries ( { queryKey : folderKeys . resource ( 'table' ) } )
28202846 for ( const tableId of tableIds ) {
28212847 queryClient . removeQueries ( { queryKey : tableKeys . detail ( tableId ) } )
0 commit comments