frontend: size format

This commit is contained in:
2025-10-14 23:23:26 +02:00
parent 80161fe86e
commit 60939306e7
2 changed files with 24 additions and 5 deletions
+6 -5
View File
@@ -25,6 +25,7 @@ import useApiError from './hooks/useApiError';
import SkeuomorphicWorkspace from './skeuomorphic_ws';
import { DownloadIcon, EditIcon } from './ui/icons';
import { generateRandomTagColor, getTagColorStyle, HEX_COLOR_PATTERN } from './utils/colors';
import { formatFileSize } from './utils/format';
import Sidebar from './sidebar/Sidebar';
import DocumentsTable, { FilterBar } from './documents/DocumentsTable';
@@ -481,6 +482,7 @@ const DetailPanel = ({
: null;
const isEditingTitle = titleEditDocId === singleDoc.id;
const sizeBytes = Number(singleDoc.current_version?.size_bytes) || 0;
const sizeLabel = sizeBytes > 0 ? formatFileSize(sizeBytes) : '—';
const issuedAt = singleDoc.issued_at
? new Date(singleDoc.issued_at).toLocaleString()
: '—';
@@ -557,7 +559,7 @@ const DetailPanel = ({
</div>
<div>
<strong>Size:</strong>{' '}
{sizeBytes ? `${(sizeBytes / 1024).toFixed(1)} KB` : '—'}
{sizeLabel}
</div>
<div>
<strong>Type:</strong> {singleDoc.content_type || 'Unknown'}
@@ -652,9 +654,7 @@ const DetailPanel = ({
const renderBulk = () => {
const countLabel = `${selectedCount} document${selectedCount === 1 ? '' : 's'}`;
const sizeLabel = stackTotalSizeBytes
? `${(stackTotalSizeBytes / 1024).toFixed(1)} KB`
: '—';
const sizeLabel = stackTotalSizeBytes ? formatFileSize(stackTotalSizeBytes) : '—';
return (
<>
@@ -773,6 +773,7 @@ const PreviewWorkspace = ({
? resolveApiPath(document.current_version.download_path)
: null;
const sizeBytes = Number(document.current_version?.size_bytes) || 0;
const sizeLabel = sizeBytes > 0 ? formatFileSize(sizeBytes) : null;
const metadata =
document.metadata && Object.keys(document.metadata).length > 0 ? document.metadata : null;
@@ -791,7 +792,7 @@ const PreviewWorkspace = ({
<h2>{title}</h2>
<span className="meta">
{document.content_type || mime}
{sizeBytes ? ` · ${(sizeBytes / 1024 / 1024).toFixed(2)} MB` : ''}
{sizeLabel ? ` · ${sizeLabel}` : ''}
</span>
</div>
</div>