// AK-P4a Interim-UI (AD-28) — Files browser preview screen composed from ~/ui. // Pure presentational component: renders the server-built FileBrowserVM passed as // a prop and reports filter/view changes through injected actions. No useLoaderData, // no server imports. The final Subframe optics land as a tracked design-nachzug once // David's D-P4 delta ships; this interim screen keeps the VM/loader boundary stable. import { useTranslation } from "react-i18next"; import { FeatherDownload, FeatherFile, FeatherGrid, FeatherList, FeatherUpload } from "@subframe/core"; import type { FileBrowserRow, FileBrowserVM, FilePreviewStatus, FileScanStatus, FileViewMode } from "@hivegrid/view-models"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { Checkbox } from "~/ui/components/Checkbox"; import { Select } from "~/ui/components/Select"; import { Table } from "~/ui/components/Table"; import { Tag_Label } from "~/ui/components/Tag_Label"; import { ToggleGroup } from "~/ui/components/ToggleGroup"; export type FilesBrowserQuery = { mimeGroup: string | null; entityType: string | null; tag: string | null; assignedToUserId: string | null; includeArchived: boolean; viewMode: FileViewMode; }; export type FilesBrowserActions = { /** Navigate (GET) to the same route with the given filter/view state. */ onApply: (query: FilesBrowserQuery) => void; /** Toggle a single row in the bulk selection. */ onToggleSelect: (id: string) => void; /** Select or clear all currently-listed rows. */ onToggleSelectAll: (ids: readonly string[], selectAll: boolean) => void; }; export type FilesBrowserPageProps = { vm: FileBrowserVM; uploadHref: string; /** Href for the next cursor page, or null on the last page. */ nextHref: string | null; /** Absolute action URL the bulk-ZIP form POSTs to. */ bulkZipAction: string; /** Currently selected row ids (for the bulk-ZIP download). */ selectedIds: readonly string[]; actions: FilesBrowserActions; }; const MIME_ALL = "all"; // Shared "no filter" sentinel for the entity/tag/assignee Selects (empty string // is not a valid Select value, so a non-empty sentinel maps back to null). const FILTER_ALL = "__all__"; type StatusBadge = { farbe: "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral"; key: string }; function previewBadge(status: FilePreviewStatus): StatusBadge { switch (status) { case "ready": return { farbe: "subtle-positive", key: "files.browser.status.preview.ready" }; case "generating": return { farbe: "subtle-warning", key: "files.browser.status.preview.generating" }; case "failed": return { farbe: "subtle-negative", key: "files.browser.status.preview.failed" }; case "not_supported": return { farbe: "subtle-neutral", key: "files.browser.status.preview.notSupported" }; case "pending": default: return { farbe: "subtle-warning", key: "files.browser.status.preview.pending" }; } } function scanBadge(status: FileScanStatus): StatusBadge | null { if (status === "infected") return { farbe: "subtle-negative", key: "files.browser.status.scan.infected" }; if (status === "pending") return { farbe: "subtle-warning", key: "files.browser.status.scan.pending" }; return null; } function formatBytes(bytes: number): string { if (bytes < 1024) return `${bytes} B`; const units = ["KB", "MB", "GB"]; let value = bytes / 1024; let unitIndex = 0; while (value >= 1024 && unitIndex < units.length - 1) { value /= 1024; unitIndex += 1; } return `${value.toFixed(1)} ${units[unitIndex]}`; } export function FilesBrowserPage({ vm, uploadHref, nextHref, bulkZipAction, selectedIds, actions }: FilesBrowserPageProps) { const { t, i18n } = useTranslation(); // Loading / not-ready: keep the marker so the shell + e2e see a stable surface. if (vm.status !== "ready" || !vm.data) { return
; } const { rows, viewMode, filter, filterOptions, canWrite } = vm.data; const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" }); function applyPatch(patch: Partial) { actions.onApply({ mimeGroup: filter.mimeGroup, entityType: filter.entityType, tag: filter.tags[0] ?? null, assignedToUserId: filter.assignedToUserId, includeArchived: filter.includeArchived, viewMode, ...patch, }); } return (
{/* Header: title + subtitle (0px rhythm), view toggle + upload CTA */}
{t("files.browser.title")} {t("files.browser.subtitle")}
{ if (value === "table" || value === "grid") applyPatch({ viewMode: value }); }} > } value="table" aria-label={t("files.browser.viewMode.table")}> {t("files.browser.viewMode.table")} } value="grid" aria-label={t("files.browser.viewMode.grid")}> {t("files.browser.viewMode.grid")} {canWrite ? ( ) : null}
{/* Filter bar (server-side, navigation on change) */}
{filterOptions.entityTypes.length > 0 ? ( ) : null} {filterOptions.tags.length > 0 ? ( ) : null} {filterOptions.assignees.length > 0 ? ( ) : null} applyPatch({ includeArchived: checked })} />
{rows.length > 0 && viewMode === "table" && selectedIds.length > 0 ? (
{selectedIds.map((id) => ( ))} {t("files.browser.bulk.selected", { count: selectedIds.length })}
) : null} {rows.length === 0 ? ( ) : viewMode === "grid" ? ( ) : ( )} {nextHref ? ( ) : null}
); } function StatusBadges({ row }: { row: FileBrowserRow }) { const { t } = useTranslation(); const preview = previewBadge(row.previewStatus); const scan = scanBadge(row.scanStatus); return (
{scan ? ( {t(scan.key)} ) : null} {t(preview.key)}
); } function RowTags({ tags }: { tags: readonly string[] }) { if (tags.length === 0) return null; return (
{tags.map((tag) => ( {tag} ))}
); } function TableView({ rows, dateFormatter, selectedIds, onToggleSelect, onToggleSelectAll, }: { rows: readonly FileBrowserRow[]; dateFormatter: Intl.DateTimeFormat; selectedIds: readonly string[]; onToggleSelect: (id: string) => void; onToggleSelectAll: (ids: readonly string[], selectAll: boolean) => void; }) { const { t } = useTranslation(); const selectedSet = new Set(selectedIds); const allIds = rows.map((row) => row.id); const allSelected = allIds.length > 0 && allIds.every((id) => selectedSet.has(id)); return (
onToggleSelectAll(allIds, checked)} /> {t("files.browser.column.name")}{t("files.browser.column.type")}{t("files.browser.column.size")}{t("files.browser.column.date")}{t("files.browser.column.status")}{t("files.browser.column.tags")} } > {rows.map((row) => ( onToggleSelect(row.id)} /> {row.displayName} {row.mimeType} {formatBytes(row.sizeBytes)} {dateFormatter.format(new Date(row.createdAtIso))} ))}
); } function GridView({ rows }: { rows: readonly FileBrowserRow[] }) { return (
{rows.map((row) => (
{row.thumbnailUrl ? ( {row.displayName} ) : ( )}
{row.displayName}
))}
); } function EmptyBrowser({ canWrite, uploadHref, vm }: { canWrite: boolean; uploadHref: string; vm: Extract }) { const { t } = useTranslation(); const headlineKey = vm.data.emptyHeadlineKey; const bodyKey = vm.data.emptyBodyKey; return (
{t(headlineKey)} {t(bodyKey)}
{canWrite ? ( ) : null}
); }