// 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