38 lines
1.1 KiB
TypeScript
Executable File
38 lines
1.1 KiB
TypeScript
Executable File
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)
|
|
* Ví 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}
|
|
/>
|
|
);
|
|
}; |