refactor: enhance path rendering in mailbox context menu
This commit is contained in:
@@ -11,8 +11,10 @@ import {
|
|||||||
} from "@/components/ui/context-menu";
|
} from "@/components/ui/context-menu";
|
||||||
import {
|
import {
|
||||||
CheckCheck,
|
CheckCheck,
|
||||||
|
ChevronRight,
|
||||||
MailOpen,
|
MailOpen,
|
||||||
Mails,
|
Mails,
|
||||||
|
MoreHorizontal,
|
||||||
Trash2,
|
Trash2,
|
||||||
FolderPlus,
|
FolderPlus,
|
||||||
Pencil,
|
Pencil,
|
||||||
@@ -39,13 +41,32 @@ function truncateSegment(name: string): string {
|
|||||||
: name;
|
: name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function shortenPath(fullPath: string): string {
|
function renderPathSegments(segments: string[]): React.ReactNode {
|
||||||
if (fullPath.length <= MAX_PATH_LENGTH) return fullPath;
|
return (
|
||||||
|
<span className="inline-flex items-center gap-1 align-middle">
|
||||||
|
{segments.map((seg, i) => (
|
||||||
|
<span key={i} className="inline-flex items-center gap-1">
|
||||||
|
{i > 0 && <ChevronRight className="w-3.5 h-3.5 opacity-60" />}
|
||||||
|
{seg === "…" ? <MoreHorizontal className="w-3.5 h-3.5" /> : <span>{seg}</span>}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderShortenedPath(fullPath: string): React.ReactNode {
|
||||||
const segments = fullPath.split(PATH_SEPARATOR);
|
const segments = fullPath.split(PATH_SEPARATOR);
|
||||||
if (segments.length <= 2) return segments.map(truncateSegment).join(PATH_SEPARATOR);
|
if (fullPath.length <= MAX_PATH_LENGTH) {
|
||||||
const first = truncateSegment(segments[0]);
|
return renderPathSegments(segments);
|
||||||
const last = truncateSegment(segments[segments.length - 1]);
|
}
|
||||||
return `${first}${PATH_SEPARATOR}…${PATH_SEPARATOR}${last}`;
|
if (segments.length <= 2) {
|
||||||
|
return renderPathSegments(segments.map(truncateSegment));
|
||||||
|
}
|
||||||
|
return renderPathSegments([
|
||||||
|
truncateSegment(segments[0]),
|
||||||
|
"…",
|
||||||
|
truncateSegment(segments[segments.length - 1]),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MailboxContextMenuProps {
|
interface MailboxContextMenuProps {
|
||||||
@@ -130,12 +151,11 @@ export function MailboxContextMenu({
|
|||||||
const canRemoveItems = mailbox.myRights?.mayRemoveItems !== false;
|
const canRemoveItems = mailbox.myRights?.mayRemoveItems !== false;
|
||||||
|
|
||||||
const fullPath = getMailboxPath(mailbox, mailboxes);
|
const fullPath = getMailboxPath(mailbox, mailboxes);
|
||||||
const displayPath = shortenPath(fullPath);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContextMenu ref={menuRef} isOpen={isOpen} position={position} onClose={onClose}>
|
<ContextMenu ref={menuRef} isOpen={isOpen} position={position} onClose={onClose}>
|
||||||
<ContextMenuHeader>
|
<ContextMenuHeader>
|
||||||
<span title={fullPath}>{displayPath}</span>
|
<span title={fullPath}>{renderShortenedPath(fullPath)}</span>
|
||||||
</ContextMenuHeader>
|
</ContextMenuHeader>
|
||||||
|
|
||||||
<ContextMenuItem
|
<ContextMenuItem
|
||||||
|
|||||||
Reference in New Issue
Block a user