-
Notifications
You must be signed in to change notification settings - Fork 78
feat(FR-1014): implement text file editor for NEO File Explorer #4943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a92461d
ca135a0
a5bca85
de85aa6
55c6036
a15141a
ca57b90
75a47b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,26 +4,66 @@ import BAIFlex from '../../BAIFlex'; | |||||||
| import useConnectedBAIClient from '../../provider/BAIClientProvider/hooks/useConnectedBAIClient'; | ||||||||
| import { VFolderFile } from '../../provider/BAIClientProvider/types'; | ||||||||
| import { FolderInfoContext } from './BAIFileExplorer'; | ||||||||
| import { MoreOutlined } from '@ant-design/icons'; | ||||||||
| import { useMutation } from '@tanstack/react-query'; | ||||||||
| import { App, Button, theme } from 'antd'; | ||||||||
| import { DownloadIcon } from 'lucide-react'; | ||||||||
| import { App, Button, theme, Dropdown } from 'antd'; | ||||||||
| import { DownloadIcon, EditIcon } from 'lucide-react'; | ||||||||
| import { use } from 'react'; | ||||||||
| import { useTranslation } from 'react-i18next'; | ||||||||
|
|
||||||||
| interface FileItemControlsProps { | ||||||||
| selectedItem: VFolderFile; | ||||||||
| onClickDelete: () => void; | ||||||||
| onClickEdit?: () => void; | ||||||||
| enableDownload?: boolean; | ||||||||
| enableDelete?: boolean; | ||||||||
| enableEdit?: boolean; | ||||||||
| downloadButtonProps?: BAIButtonProps; | ||||||||
| deleteButtonProps?: BAIButtonProps; | ||||||||
| } | ||||||||
|
|
||||||||
| const TEXT_FILE_EXTENSIONS = [ | ||||||||
| '.txt', | ||||||||
| '.md', | ||||||||
| '.json', | ||||||||
| '.yaml', | ||||||||
| '.yml', | ||||||||
| '.xml', | ||||||||
| '.csv', | ||||||||
| '.js', | ||||||||
| '.ts', | ||||||||
| '.jsx', | ||||||||
| '.tsx', | ||||||||
| '.py', | ||||||||
| '.sh', | ||||||||
| '.bash', | ||||||||
| '.html', | ||||||||
| '.css', | ||||||||
| '.scss', | ||||||||
| '.less', | ||||||||
| '.sql', | ||||||||
| '.log', | ||||||||
| '.env', | ||||||||
| '.conf', | ||||||||
| '.config', | ||||||||
| '.ini', | ||||||||
| '.toml', | ||||||||
| ]; | ||||||||
|
|
||||||||
| const isTextFile = (fileName: string): boolean => { | ||||||||
| const lastDotIndex = fileName.lastIndexOf('.'); | ||||||||
| if (lastDotIndex === -1) return false; | ||||||||
| const ext = fileName.toLowerCase().slice(lastDotIndex); | ||||||||
| return TEXT_FILE_EXTENSIONS.includes(ext); | ||||||||
| }; | ||||||||
|
|
||||||||
| const FileItemControls: React.FC<FileItemControlsProps> = ({ | ||||||||
| selectedItem, | ||||||||
| onClickDelete, | ||||||||
| onClickEdit, | ||||||||
| enableDownload = false, | ||||||||
| enableDelete = false, | ||||||||
| enableEdit = false, | ||||||||
| downloadButtonProps, | ||||||||
| deleteButtonProps, | ||||||||
| }) => { | ||||||||
|
|
@@ -108,6 +148,37 @@ const FileItemControls: React.FC<FileItemControlsProps> = ({ | |||||||
| }} | ||||||||
| {...deleteButtonProps} | ||||||||
| /> | ||||||||
| <Dropdown | ||||||||
| menu={{ | ||||||||
| items: [ | ||||||||
| { | ||||||||
| key: 'fileEdit', | ||||||||
| icon: <EditIcon size={14} />, | ||||||||
| label: t('comp:FileExplorer.EditFile'), | ||||||||
| disabled: | ||||||||
| !enableEdit || | ||||||||
| selectedItem.type === 'DIRECTORY' || | ||||||||
| !isTextFile(selectedItem.name), | ||||||||
| onClick: (e) => { | ||||||||
| e.domEvent.stopPropagation(); | ||||||||
| onClickEdit?.(); | ||||||||
| }, | ||||||||
| }, | ||||||||
| ], | ||||||||
| }} | ||||||||
| trigger={['click']} | ||||||||
| > | ||||||||
| <Button | ||||||||
| type="text" | ||||||||
| size="small" | ||||||||
| onClick={(e) => { | ||||||||
| e.preventDefault(); | ||||||||
| e.stopPropagation(); | ||||||||
| }} | ||||||||
| icon={<MoreOutlined />} | ||||||||
|
||||||||
| icon={<MoreOutlined />} | |
| icon={<MoreOutlined />} | |
| aria-label={t('comp:FileExplorer.MoreOptions')} |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The More menu dropdown currently only has one item (Edit). Consider whether a dropdown is necessary for a single action, or if this is preparation for future menu items. If it's just for the Edit action, a simpler icon button might be more appropriate. If more actions are planned, this is acceptable.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| export { default as BAIClientProvider } from './BAIClientProvider'; | ||
| export type { BAIClientProviderProps } from './BAIClientProvider'; | ||
| export { BAIClientContext, BAIAnonymousClientContext } from './context'; | ||
| export type { BAIClient } from './types'; | ||
| export type { BAIClient, VFolderFile } from './types'; | ||
| export { default as useConnectedBAIClient } from './hooks/useConnectedBAIClient'; | ||
| export { default as useAnonymousBAIClient } from './hooks/useAnonymousBAIClient'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TEXT_FILE_EXTENSIONS array is defined within the component file but could be shared across the codebase. Consider extracting this to a constants file or utility module, especially since the file type detection logic might be useful elsewhere in the application.