ge-tool/components/FolderPathDisplay.tsx

38 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2025-12-10 06:41:43 +00:00
import React from 'react';
import { TruncatedPath } from './TruncatedPath';
interface FolderPathDisplayProps {
fullPath: string;
variant?: 'blue' | 'yellow';
maxChars?: number;
}
/**
* Hiển thị đưng dẫn đến folder (bỏ filename)
* dụ: D:\projects\dkiDownload\raw\1000_DE\003.jpg D:\projects\dkiDownload\raw\1000_DE
*/
export const FolderPathDisplay: React.FC<FolderPathDisplayProps> = ({
fullPath,
variant = 'yellow',
maxChars = 60
}) => {
// If path already ends with folder (no filename), display as-is
// If path has filename, remove it
// Check if last segment has extension (file) or not (folder)
const lastSegment = fullPath.split(/[/\\]/).pop() || '';
const hasExtension = /\.[^.]+$/.test(lastSegment);
const folderPath = hasExtension
? fullPath.replace(/[/\\][^/\\]+$/, '') // Remove filename
: fullPath; // Already a folder path
if (!folderPath) return null;
return (
<TruncatedPath
path={folderPath}
variant={variant}
maxChars={maxChars}
/>
);
};