@@ -16,7 +16,7 @@ import {
1616 MagicAi ,
1717} from '@teable/icons' ;
1818import type { IDuplicateFieldRo } from '@teable/openapi' ;
19- import { deleteFields , duplicateField } from '@teable/openapi' ;
19+ import { duplicateField } from '@teable/openapi' ;
2020import type { GridView } from '@teable/sdk' ;
2121import {
2222 useFieldPermission ,
@@ -44,8 +44,9 @@ import {
4444 SheetHeader ,
4545} from '@teable/ui-lib/shadcn' ;
4646import { useTranslation } from 'next-i18next' ;
47- import { Fragment , useRef } from 'react' ;
47+ import { Fragment , useEffect , useRef , useState } from 'react' ;
4848import { useClickAway } from 'react-use' ;
49+ import { FieldDeleteConfirmDialog } from '@/features/app/components/field-setting/field-delete-confirm-dialog/FieldDeleteConfirmDialog' ;
4950import { FieldOperator } from '@/features/app/components/field-setting/type' ;
5051import { tableConfig } from '@/features/i18n/table.config' ;
5152import { useFieldSettingStore } from '../../field/useFieldSettingStore' ;
@@ -82,6 +83,14 @@ export const FieldMenu = () => {
8283 const fieldSettingRef = useRef < HTMLDivElement > ( null ) ;
8384 const { fields, aiEnable, onSelectionClear, onAutoFill } = headerMenu ?? { } ;
8485 const { filterRef, sortRef, groupRef } = useToolBarStore ( ) ;
86+ const emptyFieldMenu = ! view || ! fields ?. length || ! allFields . length ;
87+ const [ deleteFieldDialog , setDeleteFieldDialog ] = useState < {
88+ open : boolean ;
89+ tableId ?: string ;
90+ fieldIds ?: string [ ] ;
91+ } > ( {
92+ open : false ,
93+ } ) ;
8594
8695 const { mutateAsync : duplicateFieldFn } = useMutation ( {
8796 mutationFn : ( {
@@ -99,7 +108,15 @@ export const FieldMenu = () => {
99108 closeHeaderMenu ( ) ;
100109 } ) ;
101110
102- if ( ! view || ! fields ?. length || ! allFields . length ) return null ;
111+ useEffect ( ( ) => {
112+ if ( emptyFieldMenu ) {
113+ setDeleteFieldDialog ( { open : false } ) ;
114+ }
115+ } , [ emptyFieldMenu ] ) ;
116+
117+ if ( emptyFieldMenu ) {
118+ return null ;
119+ }
103120
104121 const fieldIds = fields . map ( ( f ) => f . id ) ;
105122
@@ -350,10 +367,12 @@ export const FieldMenu = () => {
350367 const fieldIdsSet = new Set ( fieldIds ) ;
351368 const filteredFields = allFields . filter ( ( f ) => fieldIdsSet . has ( f . id ) ) . filter ( Boolean ) ;
352369 if ( filteredFields . length === 0 ) return ;
353- await deleteFields (
370+
371+ setDeleteFieldDialog ( {
372+ open : true ,
354373 tableId,
355- filteredFields . map ( ( f ) => f . id )
356- ) ;
374+ fieldIds : filteredFields . map ( ( f ) => f . id ) ,
375+ } ) ;
357376 } ,
358377 } ,
359378 ] ,
@@ -381,8 +400,11 @@ export const FieldMenu = () => {
381400 if ( disabled ) return ;
382401
383402 await onClick ( ) ;
384- onSelectionClear ?.( ) ;
385- closeHeaderMenu ( ) ;
403+ // Don't auto-close menu for delete action
404+ if ( type !== MenuItemType . Delete ) {
405+ onSelectionClear ?.( ) ;
406+ closeHeaderMenu ( ) ;
407+ }
386408 } }
387409 >
388410 { icon }
@@ -424,8 +446,11 @@ export const FieldMenu = () => {
424446 return ;
425447 }
426448 await onClick ( ) ;
427- onSelectionClear ?.( ) ;
428- closeHeaderMenu ( ) ;
449+ // Don't auto-close menu for delete action
450+ if ( type !== MenuItemType . Delete ) {
451+ onSelectionClear ?.( ) ;
452+ closeHeaderMenu ( ) ;
453+ }
429454 } }
430455 >
431456 { icon }
@@ -442,6 +467,17 @@ export const FieldMenu = () => {
442467 </ PopoverContent >
443468 </ Popover >
444469 ) }
470+
471+ < FieldDeleteConfirmDialog
472+ tableId = { deleteFieldDialog . tableId ?? '' }
473+ fieldIds = { deleteFieldDialog . fieldIds ?? [ ] }
474+ open = { deleteFieldDialog . open }
475+ onClose = { ( ) => {
476+ setDeleteFieldDialog ( { open : false } ) ;
477+ onSelectionClear ?.( ) ;
478+ closeHeaderMenu ( ) ;
479+ } }
480+ />
445481 </ >
446482 ) ;
447483} ;
0 commit comments