// AK-P4a Interim-UI (AD-28) — File detail preview screen composed from ~/ui. // Presentational: renders the unwrapped FileDetailData; mutations stay server-driven // (
+ intent, exactly like the baseline route action). Modals are // real ~/ui Dialogs (David standard), not Card fakes. No useLoaderData / server imports. // // The page wears the same dense header band as the board screens: the file name // is the title and is edited in place there, the file's actions sit in the // header's action slot, and paging to the neighbouring file happens next to the // preview instead of via the browser's back button. import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { AppLink } from "~/components/app/AppLink"; import { fileTypeLabelKey } from "~/utils/files/fileTypeLabel"; import { FeatherArchive, FeatherChevronLeft, FeatherChevronRight, FeatherCheck, FeatherDownload, FeatherFileText, FeatherLink, FeatherRefreshCw, FeatherSearch, FeatherTags, FeatherTrash2, FeatherX, } from "@subframe/core"; import type { FileDetailData } from "@hivegrid/view-models"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { Alert } from "~/ui/components/Alert"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { Dialog } from "~/ui/components/Dialog"; import { IconButton } from "~/ui/components/IconButton"; import { Select } from "~/ui/components/Select"; import { Tag_Label } from "~/ui/components/Tag_Label"; import { TextInput } from "~/ui/components/TextInput"; import { APP_TIME_ZONE } from "~/locale/format"; /** One pickable link target, as the link-targets resource returns it. */ export type FileLinkTargetOption = { id: string; label: string; hint: string | null }; export type FileDetailPageProps = { data: FileDetailData; /** Allowed polymorphic entity types for the add-link form. */ entityTypes: readonly string[]; /** Href back to the files browser (breadcrumb). */ filesHref: string; /** Loader-only JSON resource the link dialog searches for records. */ linkSearchHref: string; }; 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]}`; } /** * Split "angebot.2026.pdf" into "angebot.2026" + ".pdf". A leading dot is part * of the name (".gitignore" has no suffix), and a name without a dot keeps an * empty suffix rather than inventing one. */ export function splitFileName(displayName: string): { stem: string; extension: string } { const dot = displayName.lastIndexOf("."); if (dot <= 0 || dot === displayName.length - 1) return { stem: displayName, extension: "" }; return { stem: displayName.slice(0, dot), extension: displayName.slice(dot) }; } function MetaRow({ label, value }: { label: string; value: string }) { return (
{label} {value}
); } export function FileDetailPage({ data, entityTypes, linkSearchHref }: FileDetailPageProps) { const { t, i18n } = useTranslation(); const [addLinkOpen, setAddLinkOpen] = useState(false); const [tagsOpen, setTagsOpen] = useState(false); const [deleteOpen, setDeleteOpen] = useState(false); const [draftTags, setDraftTags] = useState(data.tags.join(", ")); const [linkType, setLinkType] = useState(entityTypes[0] ?? "contact"); const [linkQuery, setLinkQuery] = useState(""); const [pickedTarget, setPickedTarget] = useState(null); const dateFormatter = new Intl.DateTimeFormat(i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "medium" }); // The file name is edited where the project name is edited: as a normal field // in the first card, saved by the one save action in the header. No separate // edit mode — the field is the field. const renameFormId = "file-rename-form"; // Only the stem is editable. The suffix is what a download is saved as and // what the reader's system picks an application by, so it is shown next to // the field and put back on save instead of being left to a typo. const { stem, extension } = splitFileName(data.displayName); const [draftStem, setDraftStem] = useState(stem); const nextName = `${draftStem.trim()}${extension}`; return ( } title={data.displayName} subtitle={`${t(fileTypeLabelKey(data.mimeType))} · ${dateFormatter.format(new Date(data.createdAtIso))}`} actions={ <> {data.canWrite && data.canRegeneratePreview ? ( ) : null} {data.canWrite ? (
) : null} {data.canDelete ? ( ) : null} {/* Save closes the row: it belongs to the field in the card below, not to the file-wide actions in front of it. */} {data.canWrite ? ( ) : null} } /> {data.scanNoticeKey ? (
) : null} {/* The file itself on the left, everything the app knows about it in its own card on the right. They stack below lg, where a 340px column next to a preview would leave neither of them a usable width. */}
{/* Preview, with the neighbouring files one click away on either side. Both buttons stay on screen and grey out at the ends, so the reader can tell "no more files" from "this control is missing". */}
} label={t("files.detail.nav.previous")} uiId="ui.files.detail.nav.previous" />
{data.previewUrl ? (
{data.displayName}
) : data.previewFallbackKey ? ( ) : null}
} label={t("files.detail.nav.next")} uiId="ui.files.detail.nav.next" />
{/* Card 1: Stammdaten — type, size, date, source, plus the tags and notes that describe the same file. */} {t("files.detail.section.metadata")} {data.canWrite ? (
{/* The suffix travels with the submitted value but never through the field, so renaming cannot change it. */} setDraftStem(event.target.value)} data-ui-id="ui.files.detail.rename.input" /> {extension ? ( {t("files.detail.rename.extensionHint", { extension })} ) : null}
) : null}
{data.notes ? (
{t("files.detail.section.notes")} {data.notes}
) : null}
{/* Card 2: Schlagworte — the file's own labels, edited in a dialog so the card stays a list and not half a form. */}
{t("files.detail.section.tags")} {data.canWrite ? ( ) : null}
{data.tags.length > 0 ? (
{data.tags.map((tag) => ( {tag} ))}
) : ( {t("files.detail.tags.empty")} )}
{/* Card 3: Verknuepfungen — what this file is attached to. */}
{t("files.detail.section.links")} {data.canWrite ? ( ) : null}
{data.linkedEntities.length > 0 ? (
    {data.linkedEntities.map((link) => (
  • {link.label ?? t(`files.entityType.${link.entityType}`, { defaultValue: t("files.entityType.unknown") })} {t(`files.entityType.${link.entityType}`, { defaultValue: t("files.entityType.unknown") })} {link.linkRole ? ` · ${link.linkRole}` : ""} {data.canWrite ? (
    } aria-label={t("files.detail.actions.unlink")} /> ) : null}
  • ))}
) : ( {t("files.detail.links.empty")} )}
{/* Tags dialog — same chrome as the other quick actions. The field takes a comma-separated list, which is what the route's updateMeta expects. */}
{t("files.detail.section.tags")} {t("files.detail.tags.placeholder")}
setDraftTags(event.target.value)} placeholder={t("files.detail.tags.placeholder")} data-ui-id="ui.files.detail.tagsDialog.input" />
{/* Add-link dialog */}
{t("files.detail.addLink.title")} {t("files.detail.addLink.subtitle")}
{/* No role field: the action treats it as optional, and a free text role nobody fills in only made the dialog longer. Existing roles (set by other paths) still show on the link itself. */}
{/* Delete confirmation dialog */}
{t("files.detail.delete.title")} {t("files.detail.delete.body")}
); } /** * Picks the record a link points at. The dialog used to ask for a raw id, which * nobody carries in their head; this searches the chosen type instead and * submits the id of what was picked. A type the server cannot search (no name * to search by) keeps the plain id field, which is honest about what it needs. */ function LinkTargetPicker({ searchHref, entityType, query, onQueryChange, picked, onPick, }: { searchHref: string; entityType: string; query: string; onQueryChange: (value: string) => void; picked: FileLinkTargetOption | null; onPick: (target: FileLinkTargetOption | null) => void; }) { const { t } = useTranslation(); const [rows, setRows] = useState([]); const [searchable, setSearchable] = useState(true); const [state, setState] = useState<"idle" | "loading" | "failed">("idle"); // Debounced, and aborted on the next keystroke: without the abort a slow // early response can overwrite the results of a later, narrower query. useEffect(() => { const controller = new AbortController(); const timer = setTimeout(() => { setState("loading"); fetch(`${searchHref}?type=${encodeURIComponent(entityType)}&q=${encodeURIComponent(query)}`, { signal: controller.signal }) .then((response) => (response.ok ? response.json() : Promise.reject(new Error(String(response.status))))) .then((data: { rows: FileLinkTargetOption[]; searchable: boolean }) => { setRows(data.rows); setSearchable(data.searchable); setState("idle"); }) .catch((error: unknown) => { if (error instanceof DOMException && error.name === "AbortError") return; setState("failed"); }); }, 250); return () => { controller.abort(); clearTimeout(timer); }; }, [entityType, query, searchHref]); if (!searchable) { // No name to search by for this type — ask for the id and say so. return ( ); } return (
{/* The picked id is what gets submitted; the search box itself is not a form field, so a half-typed name can never be sent as an id. */} }> { // Typing again means picking again. if (picked) onPick(null); onQueryChange(event.target.value); }} data-ui-id="ui.files.detail.linkDialog.search" /> {picked ? ( {t("files.detail.link.picked", { label: picked.label })} ) : (
{state === "failed" ? ( {t("shared.unexpectedError")} ) : rows.length === 0 ? ( {t(state === "loading" ? "shared.loading" : "files.detail.link.noResults")} ) : ( rows.map((row) => ( )) )}
)}
); } /** One paging arrow; disabled-looking and inert at either end of the library. */ function NeighbourButton({ href, icon, label, uiId }: { href: string | null; icon: React.ReactNode; label: string; uiId: string }) { if (!href) { return ( ); } return ( ); }