Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+70
-77
@@ -2,24 +2,30 @@
|
||||
// once (server-side); the component only renders (DoD A). Module off -> locked
|
||||
// empty state (like walking-skeleton). Missing files.read_own -> 404.
|
||||
//
|
||||
// Baseline functional UI (data-ui-id markers for e2e); the Subframe visual polish
|
||||
// follows Davids D-P4 delta (Dev-Nachzug).
|
||||
// Interim-UI (AD-28): renders the ~/ui preview screen FilesBrowserPage; the loader
|
||||
// owns navigation for filter/view changes (server-side). Final Subframe optics land
|
||||
// as a tracked design-nachzug once David's D-P4 delta ships.
|
||||
|
||||
import { type LoaderFunctionArgs, useLoaderData } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { buildFileBrowserVM, type FileBrowserRow, type FileBrowserVM } from "@toolctrl/view-models";
|
||||
import { useState } from "react";
|
||||
import { type LoaderFunctionArgs, useLoaderData, useNavigate } from "react-router";
|
||||
import { buildFileBrowserVM, type FileBrowserRow, type FileBrowserVM, type FileViewMode } from "@hivegrid/view-models";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { loadFilesContext, notFoundResponse, requireFilesPermission } from "~/utils/integrations/fileAccess.server";
|
||||
import { listFilesForBrowser } from "~/utils/integrations/fileService.server";
|
||||
import { listFilesForBrowser, listFileFilterOptions } from "~/utils/integrations/fileService.server";
|
||||
import { mediaVariantPath, filesDetailPath } from "~/utils/integrations/fileRoutePaths";
|
||||
import { FilesBrowserPage, type FilesBrowserQuery } from "~/components/screens/files/FilesBrowserPage";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
|
||||
type LoaderData = { title: string; vm: FileBrowserVM };
|
||||
type LoaderData = { title: string; vm: FileBrowserVM; nextHref: string | null; uploadHref: string; bulkZipAction: string };
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const { t } = await getTranslations(request);
|
||||
const ctx = await loadFilesContext({ request, params });
|
||||
const tenantSlug = params.tenant ?? "";
|
||||
// Absolute (host-aware) URLs — a relative "upload" would resolve against the
|
||||
// /<tenant>/files base and drop the "files" segment (→ 404).
|
||||
const uploadHref = `/${tenantSlug}/files/upload`;
|
||||
const bulkZipAction = `/${tenantSlug}/files/bulk-zip`;
|
||||
|
||||
if (!ctx.hasModule) {
|
||||
// Locked connector state: render an empty VM (no rows, no write).
|
||||
@@ -29,7 +35,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
canWrite: false,
|
||||
canDelete: false,
|
||||
});
|
||||
return Response.json({ title: `${t("files.browser.title")} | ${process.env.APP_NAME}`, vm } satisfies LoaderData);
|
||||
return Response.json({ title: `${t("files.browser.title")} | ${process.env.APP_NAME}`, vm, nextHref: null, uploadHref, bulkZipAction } satisfies LoaderData);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -41,14 +47,21 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const url = new URL(request.url);
|
||||
const includeArchived = url.searchParams.get("archived") === "1";
|
||||
const mimeGroup = url.searchParams.get("mime");
|
||||
const entityType = url.searchParams.get("entity");
|
||||
const tag = url.searchParams.get("tag");
|
||||
const assignedToUserId = url.searchParams.get("assignee");
|
||||
const cursor = url.searchParams.get("cursor");
|
||||
const viewMode: FileViewMode = url.searchParams.get("view") === "grid" ? "grid" : "table";
|
||||
|
||||
const { rows, nextCursor } = await listFilesForBrowser({
|
||||
tenantId: ctx.tenantId,
|
||||
ctx,
|
||||
filter: { includeArchived, mimeGroup },
|
||||
cursor,
|
||||
});
|
||||
const [{ rows, nextCursor }, filterOptions] = await Promise.all([
|
||||
listFilesForBrowser({
|
||||
tenantId: ctx.tenantId,
|
||||
ctx,
|
||||
filter: { includeArchived, mimeGroup, entityType, tags: tag ? [tag] : undefined, assignedToUserId },
|
||||
cursor,
|
||||
}),
|
||||
listFileFilterOptions({ tenantId: ctx.tenantId }),
|
||||
]);
|
||||
|
||||
const canWrite = ctx.permissions.includes("files.write");
|
||||
const canDelete = ctx.permissions.includes("files.delete");
|
||||
@@ -68,83 +81,63 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
}));
|
||||
|
||||
const vm = buildFileBrowserVM({
|
||||
viewMode,
|
||||
rows: browserRows,
|
||||
filter: { entityType: null, mimeGroup, tags: [], assignedToUserId: null, includeArchived },
|
||||
filter: { entityType, mimeGroup, tags: tag ? [tag] : [], assignedToUserId, includeArchived },
|
||||
filterOptions,
|
||||
canWrite,
|
||||
canDelete,
|
||||
nextCursor,
|
||||
});
|
||||
|
||||
return Response.json({ title: `${t("files.browser.title")} | ${process.env.APP_NAME}`, vm } satisfies LoaderData);
|
||||
// Preserve the active filter/view when paging via cursor.
|
||||
const nextParams = new URLSearchParams();
|
||||
if (mimeGroup) nextParams.set("mime", mimeGroup);
|
||||
if (entityType) nextParams.set("entity", entityType);
|
||||
if (tag) nextParams.set("tag", tag);
|
||||
if (assignedToUserId) nextParams.set("assignee", assignedToUserId);
|
||||
if (includeArchived) nextParams.set("archived", "1");
|
||||
if (viewMode === "grid") nextParams.set("view", "grid");
|
||||
if (nextCursor) nextParams.set("cursor", nextCursor);
|
||||
const nextHref = nextCursor ? `?${nextParams.toString()}` : null;
|
||||
|
||||
return Response.json({ title: `${t("files.browser.title")} | ${process.env.APP_NAME}`, vm, nextHref, uploadHref, bulkZipAction } satisfies LoaderData);
|
||||
};
|
||||
|
||||
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 default function FilesBrowserRoute() {
|
||||
const { t, i18n } = useTranslation();
|
||||
const { vm } = useLoaderData<LoaderData>();
|
||||
const { vm, nextHref, uploadHref, bulkZipAction } = useLoaderData<LoaderData>();
|
||||
const navigate = useNavigate();
|
||||
const [selectedIds, setSelectedIds] = useState<string[]>([]);
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <main className="mx-auto max-w-5xl px-4 py-10" data-ui-id="ui.files.browser" />;
|
||||
function onToggleSelect(id: string) {
|
||||
setSelectedIds((prev) => (prev.includes(id) ? prev.filter((value) => value !== id) : [...prev, id]));
|
||||
}
|
||||
|
||||
const { rows, canWrite, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
function onToggleSelectAll(ids: readonly string[], selectAll: boolean) {
|
||||
setSelectedIds(selectAll ? [...ids] : []);
|
||||
}
|
||||
|
||||
function onApply(query: FilesBrowserQuery) {
|
||||
const params = new URLSearchParams();
|
||||
if (query.mimeGroup) params.set("mime", query.mimeGroup);
|
||||
if (query.entityType) params.set("entity", query.entityType);
|
||||
if (query.tag) params.set("tag", query.tag);
|
||||
if (query.assignedToUserId) params.set("assignee", query.assignedToUserId);
|
||||
if (query.includeArchived) params.set("archived", "1");
|
||||
if (query.viewMode === "grid") params.set("view", "grid");
|
||||
// Reset cursor pagination whenever the filter/view changes.
|
||||
navigate({ search: params.toString() });
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-4 py-10" data-ui-id="ui.files.browser">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-foreground text-xl font-semibold">{t("files.browser.title")}</h1>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t("files.browser.subtitle")}</p>
|
||||
</div>
|
||||
{canWrite ? (
|
||||
<a href="upload" className="text-theme-600 font-medium" data-ui-id="ui.files.browser.upload">
|
||||
{t("files.browser.actions.upload")}
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div className="mt-10 text-center" data-ui-id="ui.files.browser.empty">
|
||||
<p className="text-foreground font-medium">{t(emptyHeadlineKey)}</p>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t(emptyBodyKey)}</p>
|
||||
</div>
|
||||
) : (
|
||||
<table className="mt-6 w-full text-left text-sm" data-ui-id="ui.files.browser.table">
|
||||
<thead>
|
||||
<tr className="text-muted-foreground border-b">
|
||||
<th className="py-2">{t("files.browser.column.name")}</th>
|
||||
<th className="py-2">{t("files.browser.column.size")}</th>
|
||||
<th className="py-2">{t("files.browser.column.date")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((row) => (
|
||||
<tr key={row.id} className="border-b" data-row-id={row.id}>
|
||||
<td className="py-2">
|
||||
<a href={row.detailHref} className="text-theme-600">
|
||||
{row.displayName}
|
||||
</a>
|
||||
</td>
|
||||
<td className="py-2">{formatBytes(row.sizeBytes)}</td>
|
||||
<td className="py-2">{dateFormatter.format(new Date(row.createdAtIso))}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</main>
|
||||
<FilesBrowserPage
|
||||
vm={vm}
|
||||
uploadHref={uploadHref}
|
||||
nextHref={nextHref}
|
||||
bulkZipAction={bulkZipAction}
|
||||
selectedIds={selectedIds}
|
||||
actions={{ onApply, onToggleSelect, onToggleSelectAll }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user