1+ import { filterOutEmpty } from '../../../helper' ;
2+ import { useTanMutation } from '../../../helper/reactQueryAlias' ;
13import { BAITrashBinIcon } from '../../../icons' ;
2- import { BAIButtonProps } from '../../BAIButton' ;
4+ import BAIButton , { BAIButtonProps } from '../../BAIButton' ;
35import BAIFlex from '../../BAIFlex' ;
46import useConnectedBAIClient from '../../provider/BAIClientProvider/hooks/useConnectedBAIClient' ;
57import { VFolderFile } from '../../provider/BAIClientProvider/types' ;
68import { FolderInfoContext } from './BAIFileExplorer' ;
7- import { useMutation } from '@tanstack/react-query' ;
8- import { App , Button , theme } from 'antd' ;
9- import { DownloadIcon } from 'lucide-react' ;
9+ import { MoreOutlined } from '@ant-design/icons' ;
10+ import { App , theme , Dropdown , Tooltip } from 'antd' ;
11+ import type { MenuProps } from 'antd' ;
12+ import { DownloadIcon , EditIcon } from 'lucide-react' ;
1013import { use } from 'react' ;
1114import { useTranslation } from 'react-i18next' ;
1215
1316interface FileItemControlsProps {
1417 selectedItem : VFolderFile ;
1518 onClickDelete : ( ) => void ;
19+ onClickEdit ?: ( ) => void ;
1620 enableDownload ?: boolean ;
1721 enableDelete ?: boolean ;
22+ enableEdit ?: boolean ;
1823 downloadButtonProps ?: BAIButtonProps ;
1924 deleteButtonProps ?: BAIButtonProps ;
2025}
2126
2227const FileItemControls : React . FC < FileItemControlsProps > = ( {
2328 selectedItem,
2429 onClickDelete,
30+ onClickEdit,
2531 enableDownload = false ,
2632 enableDelete = false ,
33+ enableEdit = false ,
2734 downloadButtonProps,
2835 deleteButtonProps,
2936} ) => {
37+ 'use memo' ;
38+
3039 const { t } = useTranslation ( ) ;
3140 const { token } = theme . useToken ( ) ;
3241 const { message } = App . useApp ( ) ;
3342 const { targetVFolderId, currentPath } = use ( FolderInfoContext ) ;
3443 const baiClient = useConnectedBAIClient ( ) ;
3544
36- const downloadFileMutation = useMutation ( {
45+ const downloadFileMutation = useTanMutation ( {
3746 mutationFn : async ( {
3847 fileName,
3948 currentFolder,
@@ -73,31 +82,46 @@ const FileItemControls: React.FC<FileItemControlsProps> = ({
7382 } ,
7483 } ) ;
7584
76- const handleDownload = ( ) => {
77- if ( ! selectedItem || downloadFileMutation . isPending ) return ;
85+ const isDirectory = selectedItem . type === 'DIRECTORY' ;
7886
79- downloadFileMutation . mutate ( {
80- fileName : `${ currentPath } /${ selectedItem . name } ` ,
81- currentFolder : targetVFolderId ,
82- archive : selectedItem . type === 'DIRECTORY' ,
83- } ) ;
84- } ;
87+ const dropdownMenuItems : MenuProps [ 'items' ] = filterOutEmpty ( [
88+ {
89+ key : 'fileEdit' ,
90+ icon : < EditIcon /> ,
91+ label : isDirectory ? (
92+ < Tooltip title = { t ( 'comp:FileExplorer.UnsupportedFileFormat' ) } >
93+ < span > { t ( 'comp:FileExplorer.EditFile' ) } </ span >
94+ </ Tooltip >
95+ ) : (
96+ t ( 'comp:FileExplorer.EditFile' )
97+ ) ,
98+ disabled : ! enableEdit || isDirectory ,
99+ onClick : ( e ) => {
100+ e . domEvent . stopPropagation ( ) ;
101+ onClickEdit ?.( ) ;
102+ } ,
103+ } ,
104+ ] ) ;
85105
86106 return (
87107 < BAIFlex gap = "xs" >
88- < Button
108+ < BAIButton
89109 type = "text"
90110 size = "small"
91111 icon = { < DownloadIcon color = { token . colorInfo } /> }
92- disabled = { ! enableDownload || downloadFileMutation . isPending }
93- loading = { downloadFileMutation . isPending }
94- onClick = { ( e ) => {
95- e . stopPropagation ( ) ;
96- handleDownload ( ) ;
112+ disabled = { ! enableDownload }
113+ onClick = { ( e ) => e . stopPropagation ( ) }
114+ action = { async ( ) => {
115+ if ( ! selectedItem ) return ;
116+ await downloadFileMutation . mutateAsync ( {
117+ fileName : `${ currentPath } /${ selectedItem . name } ` ,
118+ currentFolder : targetVFolderId ,
119+ archive : isDirectory ,
120+ } ) ;
97121 } }
98122 { ...downloadButtonProps }
99123 />
100- < Button
124+ < BAIButton
101125 type = "text"
102126 size = "small"
103127 icon = { < BAITrashBinIcon style = { { color : token . colorError } } /> }
@@ -108,6 +132,23 @@ const FileItemControls: React.FC<FileItemControlsProps> = ({
108132 } }
109133 { ...deleteButtonProps }
110134 />
135+ < Dropdown
136+ menu = { {
137+ items : dropdownMenuItems ,
138+ } }
139+ trigger = { [ 'click' ] }
140+ >
141+ < BAIButton
142+ type = "text"
143+ size = "small"
144+ onClick = { ( e ) => {
145+ e . stopPropagation ( ) ;
146+ } }
147+ icon = { < MoreOutlined /> }
148+ aria-label = { t ( 'comp:FileExplorer.MoreOptions' ) }
149+ style = { { color : token . colorTextSecondary } }
150+ />
151+ </ Dropdown >
111152 </ BAIFlex >
112153 ) ;
113154} ;
0 commit comments