From 3e1e8140046b765a88063ed1a9cdeb31c588f29a Mon Sep 17 00:00:00 2001 From: Asurada <43401755+ousugo@users.noreply.github.com> Date: Sat, 19 Apr 2025 02:00:11 +0800 Subject: [PATCH] fix (UI): Resolve the issue of overly long file names and path names not being displayed correctly (#5054) * feat(Messages): enhance file upload display with styled component for better UI * feat(Inputbar): add file name truncation for better display in attachment preview * feat(DataSettings): replace Typography.Text with PathText for improved path display and add text truncation styling * feat(DataSettings): refactor path display with PathRow component for better layout and styling --- .../pages/home/Inputbar/AttachmentPreview.tsx | 15 ++++++-- .../home/Messages/MessageAttachments.tsx | 15 ++++++-- .../settings/DataSettings/DataSettings.tsx | 36 ++++++++++++++----- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/renderer/src/pages/home/Inputbar/AttachmentPreview.tsx b/src/renderer/src/pages/home/Inputbar/AttachmentPreview.tsx index 343e4f6a..956403e0 100644 --- a/src/renderer/src/pages/home/Inputbar/AttachmentPreview.tsx +++ b/src/renderer/src/pages/home/Inputbar/AttachmentPreview.tsx @@ -26,12 +26,21 @@ interface Props { setFiles: (files: FileType[]) => void } +const MAX_FILENAME_DISPLAY_LENGTH = 20 +function truncateFileName(name: string, maxLength: number = MAX_FILENAME_DISPLAY_LENGTH) { + if (name.length <= maxLength) return name + return name.slice(0, maxLength - 3) + '...' +} + const FileNameRender: FC<{ file: FileType }> = ({ file }) => { const [visible, setVisible] = useState(false) const isImage = (ext: string) => { return ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp'].includes(ext) } + const fullName = FileManager.formatFileName(file) + const displayName = truncateFileName(fullName) + return ( = ({ file }) => { }} /> )} + {fullName} {formatFileSize(file.size)} }> @@ -66,8 +76,9 @@ const FileNameRender: FC<{ file: FileType }> = ({ file }) => { if (path) { window.api.file.openPath(path) } - }}> - {FileManager.formatFileName(file)} + }} + title={fullName}> + {displayName} ) diff --git a/src/renderer/src/pages/home/Messages/MessageAttachments.tsx b/src/renderer/src/pages/home/Messages/MessageAttachments.tsx index 17cef6f3..d77d6057 100644 --- a/src/renderer/src/pages/home/Messages/MessageAttachments.tsx +++ b/src/renderer/src/pages/home/Messages/MessageAttachments.tsx @@ -66,15 +66,26 @@ const MessageAttachments: FC = ({ message }) => { ) } + const StyledUpload = styled(Upload)` + .ant-upload-list-item-name { + max-width: 220px; + display: inline-block; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + vertical-align: bottom; + } + ` + return ( - ({ uid: file.id, url: 'file://' + FileManager.getSafePath(file), - status: 'done', + status: 'done' as const, name: FileManager.formatFileName(file) }))} /> diff --git a/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx b/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx index e6c8ccd2..4178ac9d 100644 --- a/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx +++ b/src/renderer/src/pages/settings/DataSettings/DataSettings.tsx @@ -204,18 +204,18 @@ const DataSettings: FC = () => { {t('settings.data.app_data')} - - {appInfo?.appDataPath} - handleOpenPath(appInfo?.appDataPath)} /> - + + {appInfo?.appDataPath} + handleOpenPath(appInfo?.appDataPath)} style={{ flexShrink: 0 }} /> + {t('settings.data.app_logs')} - - {appInfo?.logsPath} - handleOpenPath(appInfo?.logsPath)} /> - + + {appInfo?.logsPath} + handleOpenPath(appInfo?.logsPath)} style={{ flexShrink: 0 }} /> + @@ -280,4 +280,24 @@ const MenuList = styled.div` } ` +const PathText = styled(Typography.Text)` + flex: 1; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + display: inline-block; + vertical-align: middle; + text-align: right; + margin-left: 5px; +` + +const PathRow = styled(HStack)` + min-width: 0; + flex: 1; + width: 0; + align-items: center; + gap: 5px; +` + export default DataSettings