@@ -72,6 +72,7 @@ import {
7272 TablesListContextMenu ,
7373} from '@/app/workspace/[workspaceId]/tables/components'
7474import { TableContextMenu } from '@/app/workspace/[workspaceId]/tables/components/table-context-menu'
75+ import { useReferencedByWarning } from '@/app/workspace/[workspaceId]/tables/hooks/use-referenced-by-warning'
7576import { useWorkspaceTablesRoom } from '@/app/workspace/[workspaceId]/tables/hooks/use-workspace-tables-room'
7677import TablesLoading from '@/app/workspace/[workspaceId]/tables/loading'
7778import {
@@ -128,6 +129,21 @@ const ROOT_LABEL = FOLDERED_RESOURCE_HEADERS.table.rootLabel
128129
129130const EMPTY_TABLES : TableDefinition [ ] = [ ]
130131
132+ /** Tables inside `folderIds` or any folder nested beneath them. */
133+ function tableIdsInFolderSubtrees (
134+ tables : readonly TableDefinition [ ] ,
135+ folderIds : readonly string [ ] ,
136+ descendantFolderIds : ReadonlyMap < string , ReadonlySet < string > >
137+ ) : string [ ] {
138+ if ( folderIds . length === 0 ) return [ ]
139+ const coveredFolderIds = new Set (
140+ folderIds . flatMap ( ( folderId ) => [ folderId , ...( descendantFolderIds . get ( folderId ) ?? [ ] ) ] )
141+ )
142+ return tables . flatMap ( ( table ) =>
143+ table . folderId && coveredFolderIds . has ( table . folderId ) ? [ table . id ] : [ ]
144+ )
145+ }
146+
131147/** A list row (and the right-clicked row), resolved to the entity it refers to. */
132148type TableResourceItem =
133149 | { kind : 'table' ; table : TableDefinition }
@@ -604,6 +620,23 @@ function TablesContent() {
604620 return selectionLabel ( count , firstName )
605621 } , [ selectedTableIds , selectedFolderIds , tables , folderById ] )
606622
623+ const deleteFolderIds =
624+ isDeleteFolderDialogOpen && activeFolder
625+ ? [ activeFolder . id ]
626+ : isBulkDeleteDialogOpen
627+ ? selectedFolderIds
628+ : [ ]
629+ /** Tables the open delete confirmation would archive, including every table inside a folder. */
630+ const pendingDeleteTableIds = isDeleteDialogOpen
631+ ? activeTable
632+ ? [ activeTable . id ]
633+ : [ ]
634+ : [
635+ ...( isBulkDeleteDialogOpen ? selectedTableIds : [ ] ) ,
636+ ...tableIdsInFolderSubtrees ( tables , deleteFolderIds , descendantFolderIds ) ,
637+ ]
638+ const referencedByWarning = useReferencedByWarning ( workspaceId , pendingDeleteTableIds )
639+
607640 const currentFolderActions : DropdownOption [ ] | undefined = useMemo ( ( ) => {
608641 if ( ! currentFolderId ) return undefined
609642 const folder = folderById . get ( currentFolderId )
@@ -1489,6 +1522,7 @@ function TablesContent() {
14891522 { text : activeTable ?. name ?? 'this table' , bold : true } ,
14901523 '? ' ,
14911524 { text : `All ${ activeTable ?. rowCount ?? 0 } rows will be removed.` , error : true } ,
1525+ ...referencedByWarning ,
14921526 ' You can restore it from Recently Deleted in Settings.' ,
14931527 ] }
14941528 confirm = { {
@@ -1512,6 +1546,7 @@ function TablesContent() {
15121546 { text : activeFolder ?. name ?? 'this folder' , bold : true } ,
15131547 '? ' ,
15141548 { text : 'Every table and subfolder inside it will be deleted too.' , error : true } ,
1549+ ...referencedByWarning ,
15151550 ' You can restore those tables from Recently Deleted in Settings.' ,
15161551 ] }
15171552 confirm = { {
@@ -1538,6 +1573,7 @@ function TablesContent() {
15381573 : 'All of their rows will be removed.' ,
15391574 error : true ,
15401575 } ,
1576+ ...referencedByWarning ,
15411577 ' You can restore those tables from Recently Deleted in Settings.' ,
15421578 ] }
15431579 confirm = { {
0 commit comments