Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

💄 style(tool-ui): use the lucide image icon for image files in tool rows (#18509)

Arvin Xuec840c607cf2
diff --git a/packages/shared-tool-ui/src/components/FilePathDisplay.tsx b/packages/shared-tool-ui/src/components/FilePathDisplay.tsx
index 1c816150d30..a09c6ef63ea 100644
--- a/packages/shared-tool-ui/src/components/FilePathDisplay.tsx
+++ b/packages/shared-tool-ui/src/components/FilePathDisplay.tsx
@@ -1,10 +1,28 @@
'use client';
-import { MaterialFileTypeIcon, Text } from '@lobehub/ui';
+import { Icon, MaterialFileTypeIcon, Text } from '@lobehub/ui';
import { createStaticStyles, cssVar } from 'antd-style';
+import { ImageIcon } from 'lucide-react';
import path from 'path-browserify-esm';
import { memo, useMemo } from 'react';
+const IMAGE_EXTENSIONS = new Set([
+ '.apng',
+ '.avif',
+ '.bmp',
+ '.gif',
+ '.heic',
+ '.heif',
+ '.ico',
+ '.jpeg',
+ '.jpg',
+ '.png',
+ '.svg',
+ '.tif',
+ '.tiff',
+ '.webp',
+]);
+
const styles = createStaticStyles(({ css }) => ({
icon: css`
flex-shrink: 0;
@@ -22,34 +40,41 @@ interface FilePathDisplayProps {
}
export const getFilePathDisplayInfo = (filePath: string) => {
- if (!filePath) return { displayPath: '', name: '' };
+ if (!filePath) return { displayPath: '', isImage: false, name: '' };
- const { base, dir } = path.parse(filePath);
+ const { base, dir, ext } = path.parse(filePath);
const parentDir = path.basename(dir);
return {
displayPath: parentDir ? `${parentDir}/${base}` : base,
+ isImage: IMAGE_EXTENSIONS.has(ext.toLowerCase()),
name: base,
};
};
export const FilePathDisplay = memo<FilePathDisplayProps>(({ filePath, isDirectory }) => {
- const { displayPath, name } = useMemo(() => getFilePathDisplayInfo(filePath), [filePath]);
+ const { displayPath, isImage, name } = useMemo(
+ () => getFilePathDisplayInfo(filePath),
+ [filePath],
+ );
if (!filePath) return null;
return (
<>
- {name && (
- <MaterialFileTypeIcon
- className={styles.icon}
- fallbackUnknownType={false}
- filename={name}
- size={16}
- type={isDirectory ? 'folder' : 'file'}
- variant={'raw'}
- />
- )}
+ {name &&
+ (isImage && !isDirectory ? (
+ <Icon className={styles.icon} icon={ImageIcon} size={16} />
+ ) : (
+ <MaterialFileTypeIcon
+ className={styles.icon}
+ fallbackUnknownType={false}
+ filename={name}
+ size={16}
+ type={isDirectory ? 'folder' : 'file'}
+ variant={'raw'}
+ />
+ ))}
{displayPath && (
<Text
className={styles.text}
diff --git a/src/features/Conversation/Messages/EditedFilesCard/index.test.ts b/src/features/Conversation/Messages/EditedFilesCard/index.test.ts
index cb897660966..03afb1519f7 100644
--- a/src/features/Conversation/Messages/EditedFilesCard/index.test.ts
+++ b/src/features/Conversation/Messages/EditedFilesCard/index.test.ts
@@ -49,9 +49,18 @@ describe('getFilePathDisplayInfo', () => {
it('keeps the parent directory and basename for long absolute paths', () => {
expect(getFilePathDisplayInfo('/very/long/workspace/Acceptance/index.tsx')).toEqual({
displayPath: 'Acceptance/index.tsx',
+ isImage: false,
name: 'index.tsx',
});
});
+
+ it('marks image files so they render a lucide image icon instead of a file-type icon', () => {
+ expect(getFilePathDisplayInfo('/workspace/tmp/r24-studio-crop.PNG')).toEqual({
+ displayPath: 'tmp/r24-studio-crop.PNG',
+ isImage: true,
+ name: 'r24-studio-crop.PNG',
+ });
+ });
});
describe('SINGLE_EDITED_FILE_ICON_SIZE', () => {