Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+90
-7
@@ -1,10 +1,10 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildFileDetailVM } from "@hivegrid/view-models";
|
||||
|
||||
import { FileDetailPage } from "./FileDetailPage";
|
||||
import { FileDetailPage, splitFileName } from "./FileDetailPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
@@ -37,6 +37,19 @@ function detailData(overrides: Record<string, unknown> = {}) {
|
||||
return vm.data;
|
||||
}
|
||||
|
||||
describe("splitFileName", () => {
|
||||
it("splits a name at its last dot", () => {
|
||||
expect(splitFileName("angebot.2026.pdf")).toEqual({ stem: "angebot.2026", extension: ".pdf" });
|
||||
});
|
||||
|
||||
it("leaves a name without a usable dot whole", () => {
|
||||
// No dot, a trailing dot, and a dotfile all have no suffix to protect.
|
||||
expect(splitFileName("scan")).toEqual({ stem: "scan", extension: "" });
|
||||
expect(splitFileName("scan.")).toEqual({ stem: "scan.", extension: "" });
|
||||
expect(splitFileName(".gitignore")).toEqual({ stem: ".gitignore", extension: "" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("FileDetailPage (interim-UI)", () => {
|
||||
it("renders the detail surface, download link and linked entities", () => {
|
||||
const { container, getAllByText } = render(
|
||||
@@ -61,15 +74,17 @@ describe("FileDetailPage (interim-UI)", () => {
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail.scanNotice"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the tag editor (updateMeta form, pre-filled) when the user can write", () => {
|
||||
it("edits the tags in a dialog, pre-filled and posting updateMeta", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileDetailPage data={detailData()} entityTypes={ENTITY_TYPES} filesHref=".." />
|
||||
</Router>,
|
||||
);
|
||||
const form = container.querySelector('[data-ui-id="ui.files.detail.tags.edit"]');
|
||||
expect(form).toBeInTheDocument();
|
||||
expect(form?.querySelector('input[type="hidden"][name="intent"][value="updateMeta"]')).toBeInTheDocument();
|
||||
fireEvent.click(container.querySelector('[data-ui-id="ui.files.detail.tags.open"]')!);
|
||||
// The dialog renders in a portal, so it is not inside `container`.
|
||||
const form = document.querySelector('[data-ui-id="ui.files.detail.tagsDialog"] form');
|
||||
expect(form).toBeTruthy();
|
||||
expect(form?.querySelector('input[type="hidden"][name="intent"][value="updateMeta"]')).toBeTruthy();
|
||||
const input = form?.querySelector('input[name="tags"]') as HTMLInputElement | null;
|
||||
expect(input?.value).toBe("wichtig");
|
||||
});
|
||||
@@ -80,6 +95,74 @@ describe("FileDetailPage (interim-UI)", () => {
|
||||
<FileDetailPage data={detailData({ canWrite: false })} entityTypes={ENTITY_TYPES} filesHref=".." />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail.tags.edit"]')).not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail.tags.open"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("offers both paging arrows and keeps the end of the library inert", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileDetailPage
|
||||
data={detailData({ previousHref: "/acme/files/f0", nextHref: null })}
|
||||
entityTypes={ENTITY_TYPES}
|
||||
filesHref=".."
|
||||
/>
|
||||
</Router>,
|
||||
);
|
||||
const previous = container.querySelector('[data-ui-id="ui.files.detail.nav.previous"]');
|
||||
const next = container.querySelector('[data-ui-id="ui.files.detail.nav.next"]');
|
||||
expect(previous?.getAttribute("href")).toBe("/acme/files/f0");
|
||||
// No neighbour: a disabled button, not a link that goes nowhere.
|
||||
expect(next?.getAttribute("href")).toBeNull();
|
||||
expect((next as HTMLButtonElement | null)?.disabled).toBe(true);
|
||||
});
|
||||
|
||||
it("edits the file name without its extension, saved by the header action", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileDetailPage data={detailData()} entityTypes={ENTITY_TYPES} filesHref=".." />
|
||||
</Router>,
|
||||
);
|
||||
const form = container.querySelector('[data-ui-id="ui.files.detail.rename"]');
|
||||
expect(form).toBeInTheDocument();
|
||||
expect(form?.querySelector('input[type="hidden"][name="intent"][value="rename"]')).toBeInTheDocument();
|
||||
// The field carries the stem only; the suffix rides along in the hidden
|
||||
// value, so a rename cannot break what the download is saved as.
|
||||
const input = container.querySelector('[data-ui-id="ui.files.detail.rename.input"]') as HTMLInputElement | null;
|
||||
expect(input?.value).toBe("vertrag");
|
||||
expect(input?.getAttribute("name")).toBeNull();
|
||||
const submitted = () => (form?.querySelector('input[type="hidden"][name="displayName"]') as HTMLInputElement).value;
|
||||
expect(submitted()).toBe("vertrag.pdf");
|
||||
|
||||
// The header's save button belongs to that form and stays inert until the
|
||||
// name actually changed.
|
||||
const save = container.querySelector('[data-ui-id="ui.files.detail.save"]') as HTMLButtonElement | null;
|
||||
expect(save?.getAttribute("form")).toBe(form?.getAttribute("id"));
|
||||
expect(save?.disabled).toBe(true);
|
||||
fireEvent.change(input!, { target: { value: "vertrag-2026" } });
|
||||
expect(submitted()).toBe("vertrag-2026.pdf");
|
||||
expect((container.querySelector('[data-ui-id="ui.files.detail.save"]') as HTMLButtonElement).disabled).toBe(false);
|
||||
});
|
||||
|
||||
it("puts save at the end of the header actions", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileDetailPage data={detailData()} entityTypes={ENTITY_TYPES} filesHref=".." />
|
||||
</Router>,
|
||||
);
|
||||
const order = ["download", "archive", "delete", "save"].map((key) =>
|
||||
[...container.querySelectorAll("[data-ui-id]")].findIndex((node) => node.getAttribute("data-ui-id") === `ui.files.detail.${key}`),
|
||||
);
|
||||
expect(order.every((index) => index >= 0)).toBe(true);
|
||||
expect([...order]).toEqual([...order].sort((left, right) => left - right));
|
||||
});
|
||||
|
||||
it("hides name editing and the save action for read-only users", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileDetailPage data={detailData({ canWrite: false })} entityTypes={ENTITY_TYPES} filesHref=".." />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail.rename"]')).not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail.save"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+479
-168
@@ -2,13 +2,33 @@
|
||||
// Presentational: renders the unwrapped FileDetailData; mutations stay server-driven
|
||||
// (<form method="post"> + 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 { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherArchive, FeatherDownload, FeatherLink, FeatherRefreshCw, FeatherTrash2, FeatherX } from "@subframe/core";
|
||||
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 { Breadcrumbs } from "~/ui/components/Breadcrumbs";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
@@ -16,6 +36,10 @@ 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;
|
||||
@@ -23,6 +47,8 @@ export type FileDetailPageProps = {
|
||||
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 {
|
||||
@@ -37,6 +63,17 @@ function formatBytes(bytes: number): string {
|
||||
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 (
|
||||
<div className="flex flex-col gap-1">
|
||||
@@ -46,189 +83,338 @@ function MetaRow({ label, value }: { label: string; value: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
export function FileDetailPage({ data, entityTypes, filesHref }: FileDetailPageProps) {
|
||||
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 dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
const [draftTags, setDraftTags] = useState(data.tags.join(", "));
|
||||
const [linkType, setLinkType] = useState<string>(entityTypes[0] ?? "contact");
|
||||
const [linkQuery, setLinkQuery] = useState("");
|
||||
const [pickedTarget, setPickedTarget] = useState<FileLinkTargetOption | null>(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 (
|
||||
<div className="flex w-full max-w-[960px] flex-col gap-6 p-6" data-ui-id="ui.files.detail">
|
||||
<Breadcrumbs>
|
||||
<a href={filesHref} className="no-underline">
|
||||
<Breadcrumbs.Item>{t("files.nav.title")}</Breadcrumbs.Item>
|
||||
</a>
|
||||
<Breadcrumbs.Divider />
|
||||
<Breadcrumbs.Item active>{data.displayName}</Breadcrumbs.Item>
|
||||
</Breadcrumbs>
|
||||
|
||||
{/* Header + action bar */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{data.displayName}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{data.mimeType} · {dateFormatter.format(new Date(data.createdAtIso))}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<a href={data.downloadUrl} className="no-underline" data-ui-id="ui.files.detail.download">
|
||||
<Button variant="tertiary" icon={<FeatherDownload />}>
|
||||
{t("files.detail.actions.download")}
|
||||
</Button>
|
||||
</a>
|
||||
{data.canWrite && data.canRegeneratePreview ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="regeneratePreview" variant="tertiary" icon={<FeatherRefreshCw />}>
|
||||
{t("files.detail.actions.regeneratePreview")}
|
||||
<PageShell uiId="ui.files.detail">
|
||||
<PageHeader
|
||||
uiId="ui.files.detail.header"
|
||||
dense
|
||||
icon={<FeatherFileText className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={data.displayName}
|
||||
subtitle={`${t(fileTypeLabelKey(data.mimeType))} · ${dateFormatter.format(new Date(data.createdAtIso))}`}
|
||||
actions={
|
||||
<>
|
||||
<a href={data.downloadUrl} className="no-underline" data-ui-id="ui.files.detail.download">
|
||||
<Button variant="tertiary" size="small" icon={<FeatherDownload />}>
|
||||
{t("files.detail.actions.download")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="archive" variant="tertiary" icon={<FeatherArchive />} data-ui-id="ui.files.detail.archive">
|
||||
{t("files.detail.actions.archive")}
|
||||
</a>
|
||||
{data.canWrite && data.canRegeneratePreview ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="regeneratePreview" variant="tertiary" size="small" icon={<FeatherRefreshCw />}>
|
||||
{t("files.detail.actions.regeneratePreview")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="archive" variant="tertiary" size="small" icon={<FeatherArchive />} data-ui-id="ui.files.detail.archive">
|
||||
{t("files.detail.actions.archive")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canDelete ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="destructive"
|
||||
size="small"
|
||||
icon={<FeatherTrash2 />}
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
data-ui-id="ui.files.detail.delete"
|
||||
>
|
||||
{t("files.detail.actions.delete")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canDelete ? (
|
||||
<Button type="button" variant="destructive" icon={<FeatherTrash2 />} onClick={() => setDeleteOpen(true)} data-ui-id="ui.files.detail.delete">
|
||||
{t("files.detail.actions.delete")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : 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 ? (
|
||||
<Button
|
||||
type="submit"
|
||||
form={renameFormId}
|
||||
size="small"
|
||||
icon={<FeatherCheck />}
|
||||
disabled={!nextName || nextName === data.displayName}
|
||||
data-ui-id="ui.files.detail.save"
|
||||
>
|
||||
{t("shared.save")}
|
||||
</Button>
|
||||
) : null}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
{data.scanNoticeKey ? (
|
||||
<div data-ui-id="ui.files.detail.scanNotice">
|
||||
<Alert variant={data.scanStatus === "infected" ? "error" : "warning"} description={t(data.scanNoticeKey)} notDismissible />
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Preview */}
|
||||
<div data-ui-id="ui.files.detail.preview">
|
||||
{data.previewUrl ? (
|
||||
<div className="flex w-full items-center justify-center overflow-hidden rounded-md border border-solid border-border-default bg-surface-neutral-tertiary p-4">
|
||||
<img src={data.previewUrl} alt={data.displayName} className="max-h-96 w-auto rounded-sm object-contain" />
|
||||
</div>
|
||||
) : data.previewFallbackKey ? (
|
||||
<Alert variant="neutral" description={t(data.previewFallbackKey)} notDismissible />
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Metadata */}
|
||||
<Card>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("files.detail.section.metadata")}</span>
|
||||
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<MetaRow label={t("files.detail.meta.type")} value={data.mimeType} />
|
||||
<MetaRow label={t("files.detail.meta.size")} value={formatBytes(data.sizeBytes)} />
|
||||
<MetaRow label={t("files.detail.meta.created")} value={dateFormatter.format(new Date(data.createdAtIso))} />
|
||||
<MetaRow label={t("files.detail.meta.source")} value={data.source} />
|
||||
</div>
|
||||
{data.notes ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("files.detail.section.notes")}</span>
|
||||
<span className="whitespace-pre-wrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{data.notes}</span>
|
||||
<PageBody>
|
||||
{data.scanNoticeKey ? (
|
||||
<div data-ui-id="ui.files.detail.scanNotice">
|
||||
<Alert variant={data.scanStatus === "infected" ? "error" : "warning"} description={t(data.scanNoticeKey)} notDismissible />
|
||||
</div>
|
||||
) : null}
|
||||
</Card>
|
||||
|
||||
{/* Tags */}
|
||||
{data.tags.length > 0 || data.canWrite ? (
|
||||
<div className="flex flex-col gap-2" data-ui-id="ui.files.detail.tags">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("files.detail.section.tags")}</span>
|
||||
{data.tags.length > 0 ? (
|
||||
<div className="flex flex-wrap items-center gap-1">
|
||||
{data.tags.map((tag) => (
|
||||
<Tag_Label key={tag} tone="neutral-subtle" size="small" noAction>
|
||||
{tag}
|
||||
</Tag_Label>
|
||||
))}
|
||||
{/* 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. */}
|
||||
<div className="flex w-full flex-col items-start gap-4 lg:flex-row">
|
||||
{/* 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". */}
|
||||
<div className="flex w-full min-w-0 grow items-center gap-3" data-ui-id="ui.files.detail.preview">
|
||||
<NeighbourButton
|
||||
href={data.previousHref}
|
||||
icon={<FeatherChevronLeft />}
|
||||
label={t("files.detail.nav.previous")}
|
||||
uiId="ui.files.detail.nav.previous"
|
||||
/>
|
||||
<div className="flex min-w-0 grow flex-col items-center gap-3">
|
||||
{data.previewUrl ? (
|
||||
<div className="flex w-full items-center justify-center overflow-hidden rounded-md border border-solid border-border-default bg-surface-neutral-tertiary p-4">
|
||||
<img src={data.previewUrl} alt={data.displayName} className="max-h-[520px] w-auto rounded-sm object-contain" />
|
||||
</div>
|
||||
) : data.previewFallbackKey ? (
|
||||
<Alert className="w-full" variant="neutral" description={t(data.previewFallbackKey)} notDismissible />
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{data.canWrite ? (
|
||||
<form method="post" className="flex flex-wrap items-end gap-2" data-ui-id="ui.files.detail.tags.edit">
|
||||
<input type="hidden" name="intent" value="updateMeta" />
|
||||
<TextInput label={t("files.detail.tags.editLabel")} showLabel className="min-w-[240px] flex-1">
|
||||
<TextInput.Input name="tags" defaultValue={data.tags.join(", ")} placeholder={t("files.detail.tags.placeholder")} />
|
||||
</TextInput>
|
||||
<Button type="submit" variant="secondary">
|
||||
<NeighbourButton href={data.nextHref} icon={<FeatherChevronRight />} label={t("files.detail.nav.next")} uiId="ui.files.detail.nav.next" />
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-col gap-4 lg:w-[360px] lg:flex-none">
|
||||
{/* Card 1: Stammdaten — type, size, date, source, plus the tags and
|
||||
notes that describe the same file. */}
|
||||
<Card data-ui-id="ui.files.detail.metadata">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("files.detail.section.metadata")}</span>
|
||||
{data.canWrite ? (
|
||||
<form method="post" id={renameFormId} className="w-full" data-ui-id="ui.files.detail.rename">
|
||||
<input type="hidden" name="intent" value="rename" />
|
||||
{/* The suffix travels with the submitted value but never
|
||||
through the field, so renaming cannot change it. */}
|
||||
<input type="hidden" name="displayName" value={nextName} />
|
||||
<TextInput className="w-full max-w-none" label={t("files.detail.rename.label")} showLabel>
|
||||
<TextInput.Input
|
||||
variant="small"
|
||||
value={draftStem}
|
||||
onChange={(event) => setDraftStem(event.target.value)}
|
||||
data-ui-id="ui.files.detail.rename.input"
|
||||
/>
|
||||
</TextInput>
|
||||
{extension ? (
|
||||
<span
|
||||
className="mt-1 block text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary"
|
||||
data-ui-id="ui.files.detail.rename.extension"
|
||||
>
|
||||
{t("files.detail.rename.extensionHint", { extension })}
|
||||
</span>
|
||||
) : null}
|
||||
</form>
|
||||
) : null}
|
||||
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-1">
|
||||
<MetaRow label={t("files.detail.meta.type")} value={t(fileTypeLabelKey(data.mimeType))} />
|
||||
<MetaRow label={t("files.detail.meta.size")} value={formatBytes(data.sizeBytes)} />
|
||||
<MetaRow label={t("files.detail.meta.created")} value={dateFormatter.format(new Date(data.createdAtIso))} />
|
||||
<MetaRow label={t("files.detail.meta.source")} value={data.source} />
|
||||
</div>
|
||||
{data.notes ? (
|
||||
<div className="flex w-full flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("files.detail.section.notes")}</span>
|
||||
<span className="whitespace-pre-wrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{data.notes}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</Card>
|
||||
|
||||
{/* Card 2: Schlagworte — the file's own labels, edited in a dialog
|
||||
so the card stays a list and not half a form. */}
|
||||
<Card data-ui-id="ui.files.detail.tags">
|
||||
<div className="flex w-full items-center justify-between gap-3">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("files.detail.section.tags")}</span>
|
||||
{data.canWrite ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
icon={<FeatherTags />}
|
||||
onClick={() => {
|
||||
setDraftTags(data.tags.join(", "));
|
||||
setTagsOpen(true);
|
||||
}}
|
||||
data-ui-id="ui.files.detail.tags.open"
|
||||
>
|
||||
{t("shared.edit")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{data.tags.length > 0 ? (
|
||||
<div className="flex w-full flex-wrap items-center gap-1">
|
||||
{data.tags.map((tag) => (
|
||||
<Tag_Label key={tag} tone="neutral-subtle" size="small" noAction>
|
||||
{tag}
|
||||
</Tag_Label>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("files.detail.tags.empty")}</span>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{/* Card 3: Verknuepfungen — what this file is attached to. */}
|
||||
<Card data-ui-id="ui.files.detail.links">
|
||||
<div className="flex w-full items-center justify-between gap-3">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("files.detail.section.links")}</span>
|
||||
{data.canWrite ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
icon={<FeatherLink />}
|
||||
onClick={() => setAddLinkOpen(true)}
|
||||
data-ui-id="ui.files.detail.links.add"
|
||||
>
|
||||
{t("files.detail.actions.link")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{data.linkedEntities.length > 0 ? (
|
||||
<ul className="flex w-full flex-col gap-2">
|
||||
{data.linkedEntities.map((link) => (
|
||||
<li
|
||||
key={`${link.entityType}-${link.entityId}`}
|
||||
className="flex items-center justify-between gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-3 py-2"
|
||||
data-link-id={`${link.entityType}-${link.entityId}`}
|
||||
>
|
||||
<span className="flex min-w-0 flex-col">
|
||||
<span className="truncate text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{link.label ?? t(`files.entityType.${link.entityType}`, { defaultValue: t("files.entityType.unknown") })}
|
||||
</span>
|
||||
<span className="truncate text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(`files.entityType.${link.entityType}`, { defaultValue: t("files.entityType.unknown") })}
|
||||
{link.linkRole ? ` · ${link.linkRole}` : ""}
|
||||
</span>
|
||||
</span>
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<input type="hidden" name="intent" value="unlink" />
|
||||
<input type="hidden" name="entityType" value={link.entityType} />
|
||||
<input type="hidden" name="entityId" value={link.entityId} />
|
||||
<IconButton type="submit" variant="ghost" size="small" icon={<FeatherX />} aria-label={t("files.detail.actions.unlink")} />
|
||||
</form>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("files.detail.links.empty")}</span>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
|
||||
{/* Tags dialog — same chrome as the other quick actions. The field takes a
|
||||
comma-separated list, which is what the route's updateMeta expects. */}
|
||||
<Dialog open={tagsOpen} onOpenChange={setTagsOpen}>
|
||||
<Dialog.Content className="w-112 max-w-[92vw] p-4" data-ui-id="ui.files.detail.tagsDialog">
|
||||
<form method="post" className="flex w-full flex-col items-start gap-5">
|
||||
<input type="hidden" name="intent" value="updateMeta" />
|
||||
<div className="flex w-full flex-col items-start gap-1">
|
||||
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("files.detail.section.tags")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("files.detail.tags.placeholder")}</span>
|
||||
</div>
|
||||
<TextInput className="w-full max-w-none" label={t("files.detail.tags.editLabel")} showLabel>
|
||||
<TextInput.Input
|
||||
autoFocus
|
||||
name="tags"
|
||||
value={draftTags}
|
||||
onChange={(event) => setDraftTags(event.target.value)}
|
||||
placeholder={t("files.detail.tags.placeholder")}
|
||||
data-ui-id="ui.files.detail.tagsDialog.input"
|
||||
/>
|
||||
</TextInput>
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button type="button" variant="tertiary" onClick={() => setTagsOpen(false)}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" icon={<FeatherTags />} data-ui-id="ui.files.detail.tagsDialog.submit">
|
||||
{t("files.detail.tags.save")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Linked entities */}
|
||||
<div className="flex flex-col gap-3" data-ui-id="ui.files.detail.links">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("files.detail.section.links")}</span>
|
||||
{data.canWrite ? (
|
||||
<Button type="button" variant="tertiary" size="small" icon={<FeatherLink />} onClick={() => setAddLinkOpen(true)}>
|
||||
{t("files.detail.actions.link")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{data.linkedEntities.length > 0 ? (
|
||||
<ul className="flex flex-col gap-2">
|
||||
{data.linkedEntities.map((link) => (
|
||||
<li
|
||||
key={`${link.entityType}-${link.entityId}`}
|
||||
className="flex items-center justify-between gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-3 py-2"
|
||||
data-link-id={`${link.entityType}-${link.entityId}`}
|
||||
>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{link.entityType}
|
||||
{link.linkRole ? ` · ${link.linkRole}` : ""}
|
||||
</span>
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<input type="hidden" name="intent" value="unlink" />
|
||||
<input type="hidden" name="entityType" value={link.entityType} />
|
||||
<input type="hidden" name="entityId" value={link.entityId} />
|
||||
<IconButton type="submit" variant="ghost" size="small" icon={<FeatherX />} aria-label={t("files.detail.actions.unlink")} />
|
||||
</form>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("files.detail.links.empty")}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Add-link dialog (real ~/ui Dialog, size S) */}
|
||||
<Dialog open={addLinkOpen} onOpenChange={setAddLinkOpen}>
|
||||
<Dialog.Content className="w-[560px] max-w-[90vw] p-8">
|
||||
<form method="post" className="flex w-full flex-col gap-6" data-ui-id="ui.files.detail.linkForm">
|
||||
<input type="hidden" name="intent" value="link" />
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("files.detail.addLink.title")}</span>
|
||||
<div className="flex flex-col gap-4">
|
||||
<Select name="entityType" label={t("files.detail.link.entityType")} showLabel defaultValue={entityTypes[0]}>
|
||||
{entityTypes.map((type) => (
|
||||
<Select.Item key={type} value={type}>
|
||||
{type}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<TextInput label={t("files.detail.link.entityId")} showLabel>
|
||||
<TextInput.Input name="entityId" required />
|
||||
</TextInput>
|
||||
<TextInput label={t("files.detail.link.role")} showLabel>
|
||||
<TextInput.Input name="linkRole" />
|
||||
</TextInput>
|
||||
</div>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button type="button" variant="tertiary" onClick={() => setAddLinkOpen(false)}>
|
||||
{t("files.detail.dialog.cancel")}
|
||||
</Button>
|
||||
<Button type="submit">{t("files.detail.actions.link")}</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* Delete confirmation dialog (real ~/ui Dialog, size XS) */}
|
||||
{/* Add-link dialog */}
|
||||
<Dialog open={addLinkOpen} onOpenChange={setAddLinkOpen}>
|
||||
<Dialog.Content className="w-112 max-w-[92vw] p-4" data-ui-id="ui.files.detail.linkDialog">
|
||||
<form method="post" className="flex w-full flex-col items-start gap-5" data-ui-id="ui.files.detail.linkForm">
|
||||
<input type="hidden" name="intent" value="link" />
|
||||
<div className="flex w-full flex-col items-start gap-1">
|
||||
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("files.detail.addLink.title")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("files.detail.addLink.subtitle")}</span>
|
||||
</div>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<Select
|
||||
className="w-full max-w-none"
|
||||
name="entityType"
|
||||
label={t("files.detail.link.entityType")}
|
||||
showLabel
|
||||
value={linkType}
|
||||
onValueChange={(value: string) => {
|
||||
setLinkType(value);
|
||||
// A record of the old type says nothing about the new one.
|
||||
setLinkQuery("");
|
||||
setPickedTarget(null);
|
||||
}}
|
||||
data-ui-id="ui.files.detail.linkDialog.type"
|
||||
>
|
||||
{entityTypes.map((type) => (
|
||||
<Select.Item key={type} value={type}>
|
||||
{t(`files.entityType.${type}`, { defaultValue: t("files.entityType.unknown") })}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
<LinkTargetPicker
|
||||
searchHref={linkSearchHref}
|
||||
entityType={linkType}
|
||||
query={linkQuery}
|
||||
onQueryChange={setLinkQuery}
|
||||
picked={pickedTarget}
|
||||
onPick={setPickedTarget}
|
||||
/>
|
||||
{/* 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. */}
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button type="button" variant="tertiary" onClick={() => setAddLinkOpen(false)}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" icon={<FeatherLink />}>
|
||||
{t("files.detail.actions.link")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* Delete confirmation dialog */}
|
||||
<Dialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-8">
|
||||
<div className="flex w-full flex-col gap-6">
|
||||
@@ -238,7 +424,7 @@ export function FileDetailPage({ data, entityTypes, filesHref }: FileDetailPageP
|
||||
</div>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button type="button" variant="tertiary" onClick={() => setDeleteOpen(false)}>
|
||||
{t("files.detail.dialog.cancel")}
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="delete" variant="destructive" icon={<FeatherTrash2 />}>
|
||||
@@ -249,6 +435,131 @@ export function FileDetailPage({ data, entityTypes, filesHref }: FileDetailPageP
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<FileLinkTargetOption[]>([]);
|
||||
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 (
|
||||
<TextInput className="w-full max-w-none" label={t("files.detail.link.entityId")} showLabel helpText={t("files.detail.link.noSearch")}>
|
||||
<TextInput.Input name="entityId" required data-ui-id="ui.files.detail.linkDialog.entityId" />
|
||||
</TextInput>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-2" data-ui-id="ui.files.detail.linkDialog.picker">
|
||||
{/* 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. */}
|
||||
<input type="hidden" name="entityId" value={picked?.id ?? ""} required />
|
||||
<TextInput className="w-full max-w-none" label={t("files.detail.link.search")} showLabel icon={<FeatherSearch />}>
|
||||
<TextInput.Input
|
||||
value={picked ? picked.label : query}
|
||||
placeholder={t("files.detail.link.searchPlaceholder")}
|
||||
onChange={(event) => {
|
||||
// Typing again means picking again.
|
||||
if (picked) onPick(null);
|
||||
onQueryChange(event.target.value);
|
||||
}}
|
||||
data-ui-id="ui.files.detail.linkDialog.search"
|
||||
/>
|
||||
</TextInput>
|
||||
|
||||
{picked ? (
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-positive" data-ui-id="ui.files.detail.linkDialog.picked">
|
||||
{t("files.detail.link.picked", { label: picked.label })}
|
||||
</span>
|
||||
) : (
|
||||
<div className="flex max-h-56 w-full flex-col overflow-y-auto rounded-md border border-solid border-border-default">
|
||||
{state === "failed" ? (
|
||||
<span className="px-3 py-2 text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-negative">{t("shared.unexpectedError")}</span>
|
||||
) : rows.length === 0 ? (
|
||||
<span className="px-3 py-2 text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(state === "loading" ? "shared.loading" : "files.detail.link.noResults")}
|
||||
</span>
|
||||
) : (
|
||||
rows.map((row) => (
|
||||
<button
|
||||
key={row.id}
|
||||
type="button"
|
||||
className="flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left hover:bg-surface-neutral-tertiary"
|
||||
onClick={() => onPick(row)}
|
||||
data-ui-id={`ui.files.detail.linkDialog.option.${row.id}`}
|
||||
>
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary">{row.label}</span>
|
||||
{row.hint ? (
|
||||
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">{row.hint}</span>
|
||||
) : null}
|
||||
</button>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<IconButton variant="tertiary" size="medium" icon={icon} aria-label={label} title={label} disabled data-ui-id={uiId} />
|
||||
);
|
||||
}
|
||||
return (
|
||||
<AppLink href={href} className="no-underline" aria-label={label} title={label} data-ui-id={uiId}>
|
||||
<IconButton variant="tertiary" size="medium" icon={icon} aria-label={label} />
|
||||
</AppLink>
|
||||
);
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
// Upload dialog of the files browser. Same chrome as the project quick-action
|
||||
// upload (shared QuickActionDialog + the same dashed dropzone), so uploading a
|
||||
// file looks the same wherever it is started. Unlike the project dialog it takes
|
||||
// several files at once and shows the chunked pipeline's progress per file,
|
||||
// which is what the standalone upload view offered before.
|
||||
//
|
||||
// Deliberate delta from the project dialog: no category/description fields.
|
||||
// Those describe a file's role *on a project* and have nowhere to go on a file
|
||||
// that is uploaded into the tenant's library.
|
||||
//
|
||||
// Pure/presentational: the queue and the upload pipeline live in the route and
|
||||
// arrive as props. No useLoaderData/useFetcher, no server imports.
|
||||
|
||||
import { useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherUpload, FeatherUploadCloud } from "@subframe/core";
|
||||
import type { FileUploadDisplayItem } from "./FileUploadPage";
|
||||
import { QuickActionDialog } from "../shared/QuickActionDialog";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Progress } from "~/ui/components/Progress";
|
||||
|
||||
export type FileUploadDialogProps = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
/** Queue of the current dialog session, newest selection last. */
|
||||
items: readonly FileUploadDisplayItem[];
|
||||
/** Hand the picked/dropped files to the route's chunked upload pipeline. */
|
||||
onFiles: (files: FileList | null) => void;
|
||||
/** True while at least one file is still on its way. */
|
||||
uploading: boolean;
|
||||
};
|
||||
|
||||
function progressState(status: FileUploadDisplayItem["status"]): "uploading" | "success" | "error" {
|
||||
if (status === "done") return "success";
|
||||
if (status === "error") return "error";
|
||||
return "uploading";
|
||||
}
|
||||
|
||||
export function FileUploadDialog(props: FileUploadDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
function statusText(item: FileUploadDisplayItem): string {
|
||||
if (item.status === "error") return t(item.errorKey ?? "files.error.uploadIncomplete");
|
||||
if (item.status === "done") return t("files.upload.status.done");
|
||||
if (item.status === "processing") return t("files.upload.status.processing");
|
||||
if (item.status === "queued") return t("files.upload.status.queued");
|
||||
return `${item.progressPercent}%`;
|
||||
}
|
||||
|
||||
return (
|
||||
<QuickActionDialog
|
||||
open={props.open}
|
||||
onOpenChange={props.onOpenChange}
|
||||
icon={<FeatherUpload />}
|
||||
iconVariant="neutral"
|
||||
title={t("files.upload.title")}
|
||||
subtitle={t("files.upload.dialogSubtitle")}
|
||||
submitLabel={t("files.upload.actions.done")}
|
||||
submitIcon={<FeatherUpload />}
|
||||
submitting={props.uploading}
|
||||
// Closing is the only way out while nothing has been picked yet; the
|
||||
// primary button confirms that the finished uploads are accepted.
|
||||
submitDisabled={props.items.length === 0}
|
||||
onSubmit={() => props.onOpenChange(false)}
|
||||
uiId="ui.files.browser.uploadDialog"
|
||||
>
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
multiple
|
||||
className="sr-only"
|
||||
aria-label={t("files.upload.actions.select")}
|
||||
onChange={(event) => {
|
||||
props.onFiles(event.target.files);
|
||||
// The same file twice in a row must fire again.
|
||||
event.target.value = "";
|
||||
}}
|
||||
data-ui-id="ui.files.browser.uploadDialog.input"
|
||||
/>
|
||||
<div
|
||||
onDragOver={(event) => event.preventDefault()}
|
||||
onDrop={(event) => {
|
||||
event.preventDefault();
|
||||
props.onFiles(event.dataTransfer.files);
|
||||
}}
|
||||
className="flex w-full flex-col items-center justify-center gap-5 rounded-lg border border-dashed border-border-strong bg-surface-neutral-primary px-6 py-8"
|
||||
data-ui-id="ui.files.browser.uploadDialog.dropzone"
|
||||
>
|
||||
<FeatherUploadCloud className="text-subtitle font-subtitle text-icon-neutral-secondary" />
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t("files.upload.dropzone.headline")}
|
||||
</span>
|
||||
<Button variant="tertiary" onClick={() => inputRef.current?.click()} data-ui-id="ui.files.browser.uploadDialog.select">
|
||||
{t("files.upload.actions.select")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{props.items.length > 0 ? (
|
||||
<ul className="flex w-full flex-col gap-3" data-ui-id="ui.files.browser.uploadDialog.queue">
|
||||
{props.items.map((item) => (
|
||||
<li key={item.clientId} className="flex w-full flex-col gap-1" data-row-id={item.clientId} data-status={item.status}>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="line-clamp-1 text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-primary">{item.filename}</span>
|
||||
<span
|
||||
className={
|
||||
item.status === "error"
|
||||
? "text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-negative"
|
||||
: "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary"
|
||||
}
|
||||
>
|
||||
{statusText(item)}
|
||||
</span>
|
||||
</div>
|
||||
<Progress className="w-full" value={item.progressPercent} state={progressState(item.status)} hideLabel />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
</QuickActionDialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default FileUploadDialog;
|
||||
+3
-2
@@ -16,12 +16,13 @@ describe("FileUploadPage (interim-UI)", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileUploadPage vm={vm} items={[]} actions={{ onFiles: vi.fn() }} />
|
||||
</Router>,
|
||||
</Router>
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.upload"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.upload.dropzone"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.upload.input"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.upload.queue"]')).toBeInTheDocument();
|
||||
expect(container.querySelector("button button")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders per-file queue items with status markers", () => {
|
||||
@@ -33,7 +34,7 @@ describe("FileUploadPage (interim-UI)", () => {
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<FileUploadPage vm={vm} items={items} actions={{ onFiles: vi.fn() }} />
|
||||
</Router>,
|
||||
</Router>
|
||||
);
|
||||
expect(container.querySelector('[data-row-id="a-1-2"][data-status="uploading"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-row-id="b-3-4"][data-status="error"]')).toBeInTheDocument();
|
||||
|
||||
+13
-8
@@ -62,15 +62,13 @@ export function FileUploadPage({ vm, items, actions }: FileUploadPageProps) {
|
||||
</div>
|
||||
|
||||
{/* Dropzone (custom interactive target; i18n copy from the VM) */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => inputRef.current?.click()}
|
||||
<div
|
||||
onDragOver={(event) => event.preventDefault()}
|
||||
onDrop={(event) => {
|
||||
event.preventDefault();
|
||||
actions.onFiles(event.dataTransfer.files);
|
||||
}}
|
||||
className="flex w-full flex-col items-center gap-4 rounded-lg border-2 border-dashed border-border-strong bg-surface-neutral-primary px-6 py-16 hover:border-brand-brand-border-solid-hover hover:bg-surface-neutral-secondary"
|
||||
className="border-border-strong bg-surface-neutral-primary hover:border-brand-brand-border-solid-hover hover:bg-surface-neutral-secondary flex w-full flex-col items-center gap-4 rounded-lg border-2 border-dashed px-6 py-16"
|
||||
data-ui-id="ui.files.upload.dropzone"
|
||||
>
|
||||
<FeatherUpload className="text-heading-1 font-heading-1 text-icon-neutral-secondary" />
|
||||
@@ -78,11 +76,18 @@ export function FileUploadPage({ vm, items, actions }: FileUploadPageProps) {
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(dropzoneHeadlineKey)}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">{t(dropzoneBodyKey)}</span>
|
||||
</div>
|
||||
<Button icon={<FeatherUpload />} variant="tertiary">
|
||||
<Button icon={<FeatherUpload />} variant="tertiary" onClick={() => inputRef.current?.click()}>
|
||||
{t("files.upload.actions.select")}
|
||||
</Button>
|
||||
</button>
|
||||
<input ref={inputRef} type="file" multiple className="hidden" onChange={(event) => actions.onFiles(event.target.files)} data-ui-id="ui.files.upload.input" />
|
||||
</div>
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
multiple
|
||||
className="hidden"
|
||||
onChange={(event) => actions.onFiles(event.target.files)}
|
||||
data-ui-id="ui.files.upload.input"
|
||||
/>
|
||||
|
||||
<Alert variant="information" textSize="small" description={t(heicNoticeKey)} notDismissible />
|
||||
|
||||
@@ -93,7 +98,7 @@ export function FileUploadPage({ vm, items, actions }: FileUploadPageProps) {
|
||||
items.map((item) => (
|
||||
<li key={item.clientId} className="flex flex-col gap-2" data-row-id={item.clientId} data-status={item.status}>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="line-clamp-1 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{item.filename}</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary line-clamp-1">{item.filename}</span>
|
||||
<span
|
||||
className={
|
||||
item.status === "error"
|
||||
|
||||
+321
-176
@@ -4,17 +4,26 @@
|
||||
// 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 { type FormEvent, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherDownload, FeatherFile, FeatherGrid, FeatherList, FeatherUpload } from "@subframe/core";
|
||||
import { fileTypeLabelKey } from "~/utils/files/fileTypeLabel";
|
||||
import { FeatherDownload, FeatherFile, FeatherFileText, FeatherGrid, FeatherLink, FeatherList, FeatherTag, FeatherUpload, FeatherUser } from "@subframe/core";
|
||||
import type { FileBrowserRow, FileBrowserVM, FilePreviewStatus, FileScanStatus, FileViewMode } from "@hivegrid/view-models";
|
||||
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
|
||||
import { FacetFilterBar, type ClientFacet } from "../shared/FacetFilterBar";
|
||||
import { FileUploadDialog } from "./FileUploadDialog";
|
||||
import type { FileUploadDisplayItem } from "./FileUploadPage";
|
||||
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";
|
||||
import { APP_TIME_ZONE } from "~/locale/format";
|
||||
import { useLiveFilter } from "~/hooks/use-live-filter";
|
||||
import { useSaveToast, type SaveActionResult } from "~/hooks/use-save-toast";
|
||||
import { AppLink } from "~/components/app/AppLink";
|
||||
|
||||
export type FilesBrowserQuery = {
|
||||
mimeGroup: string | null;
|
||||
@@ -22,23 +31,40 @@ export type FilesBrowserQuery = {
|
||||
tag: string | null;
|
||||
assignedToUserId: string | null;
|
||||
includeArchived: boolean;
|
||||
/** Free-text search over the file name. */
|
||||
q: string;
|
||||
viewMode: FileViewMode;
|
||||
};
|
||||
|
||||
export type FilesBrowserActions = {
|
||||
/** Navigate (GET) to the same route with the given filter/view state. */
|
||||
onApply: (query: FilesBrowserQuery) => void;
|
||||
/** Navigate (GET) to another page of the current result set. */
|
||||
onGoToPage: (query: FilesBrowserQuery, page: number) => 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 FilesBrowserUpload = {
|
||||
/** Queue of the open dialog session. */
|
||||
items: readonly FileUploadDisplayItem[];
|
||||
/** Hand picked/dropped files to the route's chunked upload pipeline. */
|
||||
onFiles: (files: FileList | null) => void;
|
||||
/** True while at least one file is still on its way. */
|
||||
uploading: boolean;
|
||||
/** Clear the queue when the dialog closes. */
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export type FilesBrowserPageProps = {
|
||||
vm: FileBrowserVM;
|
||||
uploadHref: string;
|
||||
/** Href for the next cursor page, or null on the last page. */
|
||||
nextHref: string | null;
|
||||
/**
|
||||
* Upload pipeline of the route. Absent for a reader — without it the header
|
||||
* shows no upload button, because there would be nothing behind it.
|
||||
*/
|
||||
upload?: FilesBrowserUpload;
|
||||
/** Absolute action URL the bulk-ZIP form POSTs to. */
|
||||
bulkZipAction: string;
|
||||
/** Currently selected row ids (for the bulk-ZIP download). */
|
||||
@@ -46,10 +72,8 @@ export type FilesBrowserPageProps = {
|
||||
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__";
|
||||
/** Mime groups the server knows how to filter on. */
|
||||
const MIME_GROUPS = ["image", "pdf", "text"] as const;
|
||||
|
||||
type StatusBadge = { farbe: "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral"; key: string };
|
||||
|
||||
@@ -87,171 +111,293 @@ function formatBytes(bytes: number): string {
|
||||
return `${value.toFixed(1)} ${units[unitIndex]}`;
|
||||
}
|
||||
|
||||
export function FilesBrowserPage({ vm, uploadHref, nextHref, bulkZipAction, selectedIds, actions }: FilesBrowserPageProps) {
|
||||
export function FilesBrowserPage({ vm, upload, bulkZipAction, selectedIds, actions }: FilesBrowserPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [uploadOpen, setUploadOpen] = useState(false);
|
||||
const [downloadingZip, setDownloadingZip] = useState(false);
|
||||
const [downloadError, setDownloadError] = useState<SaveActionResult>();
|
||||
useSaveToast(downloadError);
|
||||
// Local search buffer, live-committed to the route (GET) debounced — the same
|
||||
// behaviour the board filter bar has.
|
||||
const data = vm.status === "ready" ? vm.data : null;
|
||||
const searchFromVm = data?.filter.q ?? "";
|
||||
const [search, setSearch] = useState(searchFromVm);
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.files.browser" />;
|
||||
/** Current query with one part replaced — the shape every control reports. */
|
||||
function currentQuery(patch: Partial<FilesBrowserQuery> = {}): FilesBrowserQuery {
|
||||
return {
|
||||
mimeGroup: data?.filter.mimeGroup ?? null,
|
||||
entityType: data?.filter.entityType ?? null,
|
||||
tag: data?.filter.tags[0] ?? null,
|
||||
assignedToUserId: data?.filter.assignedToUserId ?? null,
|
||||
includeArchived: data?.filter.includeArchived ?? false,
|
||||
q: searchFromVm,
|
||||
viewMode: data?.viewMode ?? "table",
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
const { rows, viewMode, filter, filterOptions, canWrite } = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
|
||||
function applyPatch(patch: Partial<FilesBrowserQuery>) {
|
||||
actions.onApply(currentQuery(patch));
|
||||
}
|
||||
|
||||
useLiveFilter(search.trim(), searchFromVm.trim(), () => applyPatch({ q: search.trim() }));
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (!data) {
|
||||
return (
|
||||
<PageShell uiId="ui.files.browser">
|
||||
<PageHeader icon={<FeatherFileText className={PAGE_HEADER_ICON_CLASS} />} title={t("files.browser.title")} subtitle={t("files.browser.subtitle")} />
|
||||
<PageBody>{null}</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
const { rows, viewMode, filter, filterOptions, canWrite, pagination } = data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "medium" });
|
||||
|
||||
// Single-select facets on a multi-select control: picking the active option
|
||||
// again clears it, which is what the chip's X does too.
|
||||
function toggleFacet(facetKey: string, value: string) {
|
||||
switch (facetKey) {
|
||||
case "mime":
|
||||
return applyPatch({ mimeGroup: filter.mimeGroup === value ? null : value });
|
||||
case "entity":
|
||||
return applyPatch({ entityType: filter.entityType === value ? null : value });
|
||||
case "tag":
|
||||
return applyPatch({ tag: filter.tags[0] === value ? null : value });
|
||||
case "assignee":
|
||||
return applyPatch({ assignedToUserId: filter.assignedToUserId === value ? null : value });
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
setSearch("");
|
||||
actions.onApply({
|
||||
mimeGroup: filter.mimeGroup,
|
||||
entityType: filter.entityType,
|
||||
tag: filter.tags[0] ?? null,
|
||||
assignedToUserId: filter.assignedToUserId,
|
||||
includeArchived: filter.includeArchived,
|
||||
mimeGroup: null,
|
||||
entityType: null,
|
||||
tag: null,
|
||||
assignedToUserId: null,
|
||||
includeArchived: false,
|
||||
q: "",
|
||||
viewMode,
|
||||
...patch,
|
||||
});
|
||||
}
|
||||
|
||||
async function downloadZip(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
setDownloadingZip(true);
|
||||
try {
|
||||
const response = await fetch(bulkZipAction, {
|
||||
method: "POST",
|
||||
body: new FormData(event.currentTarget),
|
||||
});
|
||||
if (!response.ok) throw new Error("bulk zip failed");
|
||||
|
||||
const href = URL.createObjectURL(await response.blob());
|
||||
const link = document.createElement("a");
|
||||
link.href = href;
|
||||
link.download = "dateien.zip";
|
||||
link.click();
|
||||
window.setTimeout(() => URL.revokeObjectURL(href), 0);
|
||||
} catch {
|
||||
setDownloadError({
|
||||
intent: "bulk-zip",
|
||||
error: "files.browser.bulk.downloadError",
|
||||
});
|
||||
} finally {
|
||||
setDownloadingZip(false);
|
||||
}
|
||||
}
|
||||
|
||||
const allFacets: ClientFacet[] = [
|
||||
{
|
||||
key: "mime",
|
||||
label: t("files.browser.filter.mime.label"),
|
||||
icon: <FeatherFile />,
|
||||
tone: "blue-subtle",
|
||||
options: MIME_GROUPS.map((group) => ({ value: group, label: t(`files.browser.filter.mime.${group}`) })),
|
||||
selected: new Set(filter.mimeGroup ? [filter.mimeGroup] : []),
|
||||
},
|
||||
{
|
||||
key: "entity",
|
||||
label: t("files.browser.filter.entity.label"),
|
||||
icon: <FeatherLink />,
|
||||
tone: "violet-subtle",
|
||||
options: filterOptions.entityTypes.map((type) => ({
|
||||
value: type,
|
||||
label: t(`files.entityType.${type}`, { defaultValue: t("files.entityType.unknown") }),
|
||||
})),
|
||||
selected: new Set(filter.entityType ? [filter.entityType] : []),
|
||||
},
|
||||
{
|
||||
key: "tag",
|
||||
label: t("files.browser.filter.tag.label"),
|
||||
icon: <FeatherTag />,
|
||||
tone: "neutral-subtle",
|
||||
options: filterOptions.tags.map((tag) => ({ value: tag, label: tag })),
|
||||
selected: new Set(filter.tags),
|
||||
},
|
||||
{
|
||||
key: "assignee",
|
||||
label: t("files.browser.filter.assignee.label"),
|
||||
icon: <FeatherUser />,
|
||||
tone: "sky-subtle",
|
||||
options: filterOptions.assignees.map((assignee) => ({ value: assignee.id, label: assignee.name })),
|
||||
selected: new Set(filter.assignedToUserId ? [filter.assignedToUserId] : []),
|
||||
},
|
||||
];
|
||||
// A facet with nothing to pick is a dead button; the tenant may simply have
|
||||
// no tags or no linked entities yet.
|
||||
const facets = allFacets.filter((facet) => facet.options.length > 0);
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.files.browser">
|
||||
{/* Header: title + subtitle (0px rhythm), view toggle + upload CTA */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("files.browser.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("files.browser.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<ToggleGroup
|
||||
value={viewMode}
|
||||
onValueChange={(value: string) => {
|
||||
if (value === "table" || value === "grid") applyPatch({ viewMode: value });
|
||||
}}
|
||||
<PageShell uiId="ui.files.browser">
|
||||
<PageHeader
|
||||
icon={<FeatherFileText className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={t("files.browser.title")}
|
||||
subtitle={t("files.browser.subtitle")}
|
||||
actions={
|
||||
<>
|
||||
<ToggleGroup
|
||||
value={viewMode}
|
||||
onValueChange={(value: string) => {
|
||||
if (value === "table" || value === "grid") applyPatch({ viewMode: value });
|
||||
}}
|
||||
>
|
||||
<ToggleGroup.Item icon={<FeatherList />} value="table" aria-label={t("files.browser.viewMode.table")}>
|
||||
{t("files.browser.viewMode.table")}
|
||||
</ToggleGroup.Item>
|
||||
<ToggleGroup.Item icon={<FeatherGrid />} value="grid" aria-label={t("files.browser.viewMode.grid")}>
|
||||
{t("files.browser.viewMode.grid")}
|
||||
</ToggleGroup.Item>
|
||||
</ToggleGroup>
|
||||
{canWrite && upload ? (
|
||||
<Button icon={<FeatherUpload />} onClick={() => setUploadOpen(true)} data-ui-id="ui.files.browser.upload">
|
||||
{t("files.browser.actions.upload")}
|
||||
</Button>
|
||||
) : null}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
{/* --- Filter bar: search box + facet dropdowns, the same strip the
|
||||
boards use, so a filter looks and behaves the same on both screens. --- */}
|
||||
<FacetFilterBar
|
||||
facets={facets}
|
||||
onToggle={toggleFacet}
|
||||
search={search}
|
||||
onSearchChange={setSearch}
|
||||
searchPlaceholder={t("files.browser.filter.searchPlaceholder")}
|
||||
onReset={resetFilters}
|
||||
labels={{ reset: t("files.browser.filter.reset"), removeChip: t("files.browser.filter.removeChip") }}
|
||||
uiId="ui.files.browser.filter"
|
||||
trailing={
|
||||
<Checkbox
|
||||
label={t("files.browser.filter.archived")}
|
||||
checked={filter.includeArchived}
|
||||
onCheckedChange={(checked: boolean) => applyPatch({ includeArchived: checked })}
|
||||
data-ui-id="ui.files.browser.filter.archived"
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<PageBody>
|
||||
{/* Filter bar (server-side, navigation on change) */}
|
||||
|
||||
{rows.length > 0 && viewMode === "table" && selectedIds.length > 0 ? (
|
||||
<form
|
||||
method="post"
|
||||
action={bulkZipAction}
|
||||
onSubmit={downloadZip}
|
||||
className="border-border-default bg-surface-neutral-secondary flex flex-wrap items-center gap-3 rounded-md border border-solid px-4 py-3"
|
||||
data-ui-id="ui.files.browser.bulkbar"
|
||||
>
|
||||
<ToggleGroup.Item icon={<FeatherList />} value="table" aria-label={t("files.browser.viewMode.table")}>
|
||||
{t("files.browser.viewMode.table")}
|
||||
</ToggleGroup.Item>
|
||||
<ToggleGroup.Item icon={<FeatherGrid />} value="grid" aria-label={t("files.browser.viewMode.grid")}>
|
||||
{t("files.browser.viewMode.grid")}
|
||||
</ToggleGroup.Item>
|
||||
</ToggleGroup>
|
||||
{canWrite ? (
|
||||
<a href={uploadHref} className="no-underline" data-ui-id="ui.files.browser.upload">
|
||||
<Button icon={<FeatherUpload />}>{t("files.browser.actions.upload")}</Button>
|
||||
</a>
|
||||
{selectedIds.map((id) => (
|
||||
<input key={id} type="hidden" name="fileIds" value={id} />
|
||||
))}
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("files.browser.bulk.selected", { count: selectedIds.length })}
|
||||
</span>
|
||||
<Button type="submit" variant="secondary" icon={<FeatherDownload />} disabled={downloadingZip}>
|
||||
{t("files.browser.bulk.downloadZip")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<EmptyBrowser
|
||||
canWrite={canWrite && Boolean(upload)}
|
||||
onUpload={() => setUploadOpen(true)}
|
||||
headlineKey={data.emptyHeadlineKey}
|
||||
bodyKey={data.emptyBodyKey}
|
||||
/>
|
||||
) : viewMode === "grid" ? (
|
||||
<GridView rows={rows} />
|
||||
) : (
|
||||
<TableView
|
||||
rows={rows}
|
||||
dateFormatter={dateFormatter}
|
||||
selectedIds={selectedIds}
|
||||
onToggleSelect={actions.onToggleSelect}
|
||||
onToggleSelectAll={actions.onToggleSelectAll}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Page footer: how many files there are, which page of how many, and
|
||||
the way in both directions — in both views, since paging is a
|
||||
property of the result set, not of how it is drawn. */}
|
||||
<div className="flex w-full items-center justify-between gap-2" data-ui-id="ui.files.browser.pagination">
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{t("files.browser.pagination.total", { count: pagination.total })}
|
||||
</span>
|
||||
{rows.length > 0 ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="neutral"
|
||||
size="small"
|
||||
disabled={!pagination.hasPrevious}
|
||||
onClick={() => actions.onGoToPage(currentQuery(), pagination.page - 1)}
|
||||
data-ui-id="ui.files.browser.pagination.prev"
|
||||
>
|
||||
{t("files.browser.pagination.previous")}
|
||||
</Button>
|
||||
<span
|
||||
className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary"
|
||||
data-ui-id="ui.files.browser.pagination.position"
|
||||
>
|
||||
{t("files.browser.pagination.position", { page: pagination.page, pageCount: pagination.pageCount })}
|
||||
</span>
|
||||
<Button
|
||||
variant="neutral"
|
||||
size="small"
|
||||
disabled={!pagination.hasNext}
|
||||
onClick={() => actions.onGoToPage(currentQuery(), pagination.page + 1)}
|
||||
data-ui-id="ui.files.browser.pagination.next"
|
||||
>
|
||||
{t("files.browser.pagination.next")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
|
||||
{/* Filter bar (server-side, navigation on change) */}
|
||||
<div className="flex flex-wrap items-center gap-4" data-ui-id="ui.files.browser.filter">
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.mime.label")}
|
||||
showLabel
|
||||
value={filter.mimeGroup ?? MIME_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ mimeGroup: value === MIME_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={MIME_ALL}>{t("files.browser.filter.mime.all")}</Select.Item>
|
||||
<Select.Item value="image">{t("files.browser.filter.mime.image")}</Select.Item>
|
||||
<Select.Item value="pdf">{t("files.browser.filter.mime.pdf")}</Select.Item>
|
||||
<Select.Item value="text">{t("files.browser.filter.mime.text")}</Select.Item>
|
||||
</Select>
|
||||
{filterOptions.entityTypes.length > 0 ? (
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.entity.label")}
|
||||
showLabel
|
||||
value={filter.entityType ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ entityType: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("files.browser.filter.entity.all")}</Select.Item>
|
||||
{filterOptions.entityTypes.map((type) => (
|
||||
<Select.Item key={type} value={type}>
|
||||
{t(`files.entityType.${type}`, { defaultValue: type })}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
{filterOptions.tags.length > 0 ? (
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.tag.label")}
|
||||
showLabel
|
||||
value={filter.tags[0] ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ tag: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("files.browser.filter.tag.all")}</Select.Item>
|
||||
{filterOptions.tags.map((tag) => (
|
||||
<Select.Item key={tag} value={tag}>
|
||||
{tag}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
{filterOptions.assignees.length > 0 ? (
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.assignee.label")}
|
||||
showLabel
|
||||
value={filter.assignedToUserId ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ assignedToUserId: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("files.browser.filter.assignee.all")}</Select.Item>
|
||||
{filterOptions.assignees.map((assignee) => (
|
||||
<Select.Item key={assignee.id} value={assignee.id}>
|
||||
{assignee.name}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
<Checkbox
|
||||
label={t("files.browser.filter.archived")}
|
||||
checked={filter.includeArchived}
|
||||
onCheckedChange={(checked: boolean) => applyPatch({ includeArchived: checked })}
|
||||
{/* Uploading stays on this page: the browser is where the new file is
|
||||
expected to appear, and a separate upload route took the reader away
|
||||
from it. */}
|
||||
{upload ? (
|
||||
<FileUploadDialog
|
||||
open={uploadOpen}
|
||||
onOpenChange={(open) => {
|
||||
setUploadOpen(open);
|
||||
if (!open) upload.onClose();
|
||||
}}
|
||||
items={upload.items}
|
||||
onFiles={upload.onFiles}
|
||||
uploading={upload.uploading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{rows.length > 0 && viewMode === "table" && selectedIds.length > 0 ? (
|
||||
<form
|
||||
method="post"
|
||||
action={bulkZipAction}
|
||||
className="flex flex-wrap items-center gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-3"
|
||||
data-ui-id="ui.files.browser.bulkbar"
|
||||
>
|
||||
{selectedIds.map((id) => (
|
||||
<input key={id} type="hidden" name="fileIds" value={id} />
|
||||
))}
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("files.browser.bulk.selected", { count: selectedIds.length })}
|
||||
</span>
|
||||
<Button type="submit" variant="secondary" icon={<FeatherDownload />}>
|
||||
{t("files.browser.bulk.downloadZip")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<EmptyBrowser canWrite={canWrite} uploadHref={uploadHref} vm={vm} />
|
||||
) : viewMode === "grid" ? (
|
||||
<GridView rows={rows} />
|
||||
) : (
|
||||
<TableView
|
||||
rows={rows}
|
||||
dateFormatter={dateFormatter}
|
||||
selectedIds={selectedIds}
|
||||
onToggleSelect={actions.onToggleSelect}
|
||||
onToggleSelectAll={actions.onToggleSelectAll}
|
||||
/>
|
||||
)}
|
||||
|
||||
{nextHref ? (
|
||||
<div className="flex justify-center pt-2" data-ui-id="ui.files.browser.pagination">
|
||||
<a href={nextHref} className="no-underline">
|
||||
<Button variant="tertiary">{t("files.browser.pagination.next")}</Button>
|
||||
</a>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -327,19 +473,17 @@ function TableView({
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id}>
|
||||
<Table.Cell>
|
||||
<Checkbox
|
||||
aria-label={t("files.browser.select.row")}
|
||||
checked={selectedSet.has(row.id)}
|
||||
onCheckedChange={() => onToggleSelect(row.id)}
|
||||
/>
|
||||
<Checkbox aria-label={t("files.browser.select.row")} checked={selectedSet.has(row.id)} onCheckedChange={() => onToggleSelect(row.id)} />
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<a href={row.detailHref} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
||||
<AppLink href={row.detailHref} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
||||
{row.displayName}
|
||||
</a>
|
||||
</AppLink>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{row.mimeType}</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary" title={row.mimeType}>
|
||||
{t(fileTypeLabelKey(row.mimeType))}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{formatBytes(row.sizeBytes)}</span>
|
||||
@@ -366,9 +510,9 @@ function GridView({ rows }: { rows: readonly FileBrowserRow[] }) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4" data-ui-id="ui.files.browser.grid">
|
||||
{rows.map((row) => (
|
||||
<a key={row.id} href={row.detailHref} className="no-underline" data-row-id={row.id}>
|
||||
<AppLink key={row.id} href={row.detailHref} className="no-underline" data-row-id={row.id}>
|
||||
<Card>
|
||||
<div className="flex h-32 w-full items-center justify-center overflow-hidden rounded-md bg-surface-neutral-tertiary">
|
||||
<div className="bg-surface-neutral-tertiary flex h-32 w-full items-center justify-center overflow-hidden rounded-md">
|
||||
{row.thumbnailUrl ? (
|
||||
<img src={row.thumbnailUrl} alt={row.displayName} className="h-full w-full object-cover" />
|
||||
) : (
|
||||
@@ -376,32 +520,33 @@ function GridView({ rows }: { rows: readonly FileBrowserRow[] }) {
|
||||
)}
|
||||
</div>
|
||||
<div className="flex w-full flex-col gap-2">
|
||||
<span className="line-clamp-1 text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.displayName}</span>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary line-clamp-1">{row.displayName}</span>
|
||||
<StatusBadges row={row} />
|
||||
<RowTags tags={row.tags} />
|
||||
</div>
|
||||
</Card>
|
||||
</a>
|
||||
</AppLink>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EmptyBrowser({ canWrite, uploadHref, vm }: { canWrite: boolean; uploadHref: string; vm: Extract<FileBrowserVM, { status: "ready" }> }) {
|
||||
function EmptyBrowser({ canWrite, onUpload, headlineKey, bodyKey }: { canWrite: boolean; onUpload: () => void; headlineKey: string; bodyKey: string }) {
|
||||
const { t } = useTranslation();
|
||||
const headlineKey = vm.data.emptyHeadlineKey;
|
||||
const bodyKey = vm.data.emptyBodyKey;
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-6 py-16 text-center" data-ui-id="ui.files.browser.empty">
|
||||
<div
|
||||
className="border-border-default bg-surface-neutral-primary flex flex-col items-center gap-4 rounded-md border border-solid px-6 py-16 text-center"
|
||||
data-ui-id="ui.files.browser.empty"
|
||||
>
|
||||
<FeatherFile className="text-heading-1 font-heading-1 text-icon-neutral-tertiary" />
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary">{t(headlineKey)}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t(bodyKey)}</span>
|
||||
</div>
|
||||
{canWrite ? (
|
||||
<a href={uploadHref} className="no-underline">
|
||||
<Button icon={<FeatherUpload />}>{t("files.browser.actions.upload")}</Button>
|
||||
</a>
|
||||
<Button icon={<FeatherUpload />} onClick={onUpload} data-ui-id="ui.files.browser.empty.upload">
|
||||
{t("files.browser.actions.upload")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
function readComponent(name: string): string {
|
||||
return readFileSync(resolve(process.cwd(), `apps/web/app/components/screens/files/${name}`), "utf8");
|
||||
}
|
||||
|
||||
describe("file entity type i18n fallbacks", () => {
|
||||
it("never exposes an unknown persisted entity type as UI copy", () => {
|
||||
for (const name of ["FilesBrowserPage.tsx", "FileDetailPage.tsx"]) {
|
||||
const source = readComponent(name);
|
||||
expect(source).toContain('defaultValue: t("files.entityType.unknown")');
|
||||
expect(source).not.toMatch(/defaultValue:\s*(?:type|link\.entityType)/);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user