@@ -71,6 +71,7 @@ import {
7171 TablesListContextMenu ,
7272} from '@/app/workspace/[workspaceId]/tables/components'
7373import { TableContextMenu } from '@/app/workspace/[workspaceId]/tables/components/table-context-menu'
74+ import { useReferencedByWarning } from '@/app/workspace/[workspaceId]/tables/hooks/use-referenced-by-warning'
7475import { useWorkspaceTablesRoom } from '@/app/workspace/[workspaceId]/tables/hooks/use-workspace-tables-room'
7576import TablesLoading from '@/app/workspace/[workspaceId]/tables/loading'
7677import {
@@ -127,6 +128,21 @@ const ROOT_LABEL = FOLDERED_RESOURCE_HEADERS.table.rootLabel
127128
128129const EMPTY_TABLES : TableDefinition [ ] = [ ]
129130
131+ /** Tables inside `folderIds` or any folder nested beneath them. */
132+ function tableIdsInFolderSubtrees (
133+ tables : readonly TableDefinition [ ] ,
134+ folderIds : readonly string [ ] ,
135+ descendantFolderIds : ReadonlyMap < string , ReadonlySet < string > >
136+ ) : string [ ] {
137+ if ( folderIds . length === 0 ) return [ ]
138+ const coveredFolderIds = new Set (
139+ folderIds . flatMap ( ( folderId ) => [ folderId , ...( descendantFolderIds . get ( folderId ) ?? [ ] ) ] )
140+ )
141+ return tables . flatMap ( ( table ) =>
142+ table . folderId && coveredFolderIds . has ( table . folderId ) ? [ table . id ] : [ ]
143+ )
144+ }
145+
130146/** A list row (and the right-clicked row), resolved to the entity it refers to. */
131147type TableResourceItem =
132148 | { kind : 'table' ; table : TableDefinition }
@@ -595,6 +611,23 @@ export function Tables() {
595611 return selectionLabel ( count , firstName )
596612 } , [ selectedTableIds , selectedFolderIds , tables , folderById ] )
597613
614+ const deleteFolderIds =
615+ isDeleteFolderDialogOpen && activeFolder
616+ ? [ activeFolder . id ]
617+ : isBulkDeleteDialogOpen
618+ ? selectedFolderIds
619+ : [ ]
620+ /** Tables the open delete confirmation would archive, including every table inside a folder. */
621+ const pendingDeleteTableIds = isDeleteDialogOpen
622+ ? activeTable
623+ ? [ activeTable . id ]
624+ : [ ]
625+ : [
626+ ...( isBulkDeleteDialogOpen ? selectedTableIds : [ ] ) ,
627+ ...tableIdsInFolderSubtrees ( tables , deleteFolderIds , descendantFolderIds ) ,
628+ ]
629+ const referencedByWarning = useReferencedByWarning ( workspaceId , pendingDeleteTableIds )
630+
598631 const currentFolderActions : DropdownOption [ ] | undefined = useMemo ( ( ) => {
599632 if ( ! currentFolderId ) return undefined
600633 const folder = folderById . get ( currentFolderId )
@@ -1480,6 +1513,7 @@ export function Tables() {
14801513 { text : activeTable ?. name ?? 'this table' , bold : true } ,
14811514 '? ' ,
14821515 { text : `All ${ activeTable ?. rowCount ?? 0 } rows will be removed.` , error : true } ,
1516+ ...referencedByWarning ,
14831517 ' You can restore it from Recently Deleted in Settings.' ,
14841518 ] }
14851519 confirm = { {
@@ -1503,6 +1537,7 @@ export function Tables() {
15031537 { text : activeFolder ?. name ?? 'this folder' , bold : true } ,
15041538 '? ' ,
15051539 { text : 'Every table and subfolder inside it will be deleted too.' , error : true } ,
1540+ ...referencedByWarning ,
15061541 ' You can restore those tables from Recently Deleted in Settings.' ,
15071542 ] }
15081543 confirm = { {
@@ -1529,6 +1564,7 @@ export function Tables() {
15291564 : 'All of their rows will be removed.' ,
15301565 error : true ,
15311566 } ,
1567+ ...referencedByWarning ,
15321568 ' You can restore those tables from Recently Deleted in Settings.' ,
15331569 ] }
15341570 confirm = { {
0 commit comments