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
+94
-39
@@ -6,36 +6,42 @@
|
||||
// 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 { useState } from "react";
|
||||
import { type LoaderFunctionArgs, useLoaderData, useNavigate } from "react-router";
|
||||
import { useCallback, useState } from "react";
|
||||
import { type LoaderFunctionArgs, useLoaderData, useNavigate, useRevalidator } 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, listFileFilterOptions } from "~/utils/integrations/fileService.server";
|
||||
import { loadFileBrowserData } from "~/utils/integrations/fileService.server";
|
||||
import { mediaVariantPath, filesDetailPath } from "~/utils/integrations/fileRoutePaths";
|
||||
import { FilesBrowserPage, type FilesBrowserQuery } from "~/components/screens/files/FilesBrowserPage";
|
||||
import type { FileUploadDisplayItem } from "~/components/screens/files/FileUploadPage";
|
||||
import { uploadFileInChunks, UploadFileClientError } from "~/utils/files/uploadFileClient";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
|
||||
type LoaderData = { title: string; vm: FileBrowserVM; nextHref: string | null; uploadHref: string; bulkZipAction: string };
|
||||
type LoaderData = { title: string; vm: FileBrowserVM; tenantSlug: 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
|
||||
// Absolute (host-aware) URL — a relative "bulk-zip" 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).
|
||||
const vm = buildFileBrowserVM({
|
||||
rows: [],
|
||||
filter: { entityType: null, mimeGroup: null, tags: [], assignedToUserId: null, includeArchived: false },
|
||||
filter: { entityType: null, mimeGroup: null, tags: [], assignedToUserId: null, includeArchived: false, q: "" },
|
||||
canWrite: false,
|
||||
canDelete: false,
|
||||
});
|
||||
return Response.json({ title: `${t("files.browser.title")} | ${process.env.APP_NAME}`, vm, nextHref: null, uploadHref, bulkZipAction } satisfies LoaderData);
|
||||
return Response.json({
|
||||
title: `${t("files.browser.title")} | ${process.env.APP_NAME}`,
|
||||
vm,
|
||||
tenantSlug,
|
||||
bulkZipAction,
|
||||
} satisfies LoaderData);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -50,18 +56,16 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
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 q = url.searchParams.get("q") ?? "";
|
||||
const pageParam = Number.parseInt(url.searchParams.get("page") ?? "1", 10);
|
||||
const viewMode: FileViewMode = url.searchParams.get("view") === "grid" ? "grid" : "table";
|
||||
|
||||
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 { rows, total, page, pageCount, filterOptions } = await loadFileBrowserData({
|
||||
tenantId: ctx.tenantId,
|
||||
ctx,
|
||||
filter: { includeArchived, mimeGroup, entityType, tags: tag ? [tag] : undefined, assignedToUserId, q },
|
||||
page: Number.isFinite(pageParam) ? pageParam : 1,
|
||||
});
|
||||
|
||||
const canWrite = ctx.permissions.includes("files.write");
|
||||
const canDelete = ctx.permissions.includes("files.delete");
|
||||
@@ -83,31 +87,25 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const vm = buildFileBrowserVM({
|
||||
viewMode,
|
||||
rows: browserRows,
|
||||
filter: { entityType, mimeGroup, tags: tag ? [tag] : [], assignedToUserId, includeArchived },
|
||||
filter: { entityType, mimeGroup, tags: tag ? [tag] : [], assignedToUserId, includeArchived, q },
|
||||
filterOptions,
|
||||
canWrite,
|
||||
canDelete,
|
||||
nextCursor,
|
||||
page,
|
||||
pageCount,
|
||||
total,
|
||||
});
|
||||
|
||||
// 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);
|
||||
return Response.json({ title: `${t("files.browser.title")} | ${process.env.APP_NAME}`, vm, tenantSlug, bulkZipAction } satisfies LoaderData);
|
||||
};
|
||||
|
||||
export default function FilesBrowserRoute() {
|
||||
const { vm, nextHref, uploadHref, bulkZipAction } = useLoaderData<LoaderData>();
|
||||
const { vm, tenantSlug, bulkZipAction } = useLoaderData<LoaderData>();
|
||||
const navigate = useNavigate();
|
||||
const revalidator = useRevalidator();
|
||||
const [selectedIds, setSelectedIds] = useState<string[]>([]);
|
||||
const [uploadItems, setUploadItems] = useState<FileUploadDisplayItem[]>([]);
|
||||
const canWrite = vm.status === "ready" && vm.data.canWrite;
|
||||
|
||||
function onToggleSelect(id: string) {
|
||||
setSelectedIds((prev) => (prev.includes(id) ? prev.filter((value) => value !== id) : [...prev, id]));
|
||||
@@ -117,26 +115,83 @@ export default function FilesBrowserRoute() {
|
||||
setSelectedIds(selectAll ? [...ids] : []);
|
||||
}
|
||||
|
||||
function onApply(query: FilesBrowserQuery) {
|
||||
// --- Upload pipeline of the browser's upload dialog ---------------------
|
||||
// Same chunked client as the former upload view (init -> chunk -> complete);
|
||||
// it lives here because the screen stays presentational. Every finished file
|
||||
// revalidates the loader, so the new file is in the list behind the dialog.
|
||||
const updateItem = useCallback((clientId: string, patch: Partial<FileUploadDisplayItem>) => {
|
||||
setUploadItems((current) => current.map((item) => (item.clientId === clientId ? { ...item, ...patch } : item)));
|
||||
}, []);
|
||||
|
||||
const uploadOne = useCallback(
|
||||
async (file: File, clientId: string) => {
|
||||
try {
|
||||
updateItem(clientId, { status: "uploading", progressPercent: 0 });
|
||||
await uploadFileInChunks({
|
||||
tenantSlug,
|
||||
file,
|
||||
onProgress: (percent) => updateItem(clientId, { progressPercent: percent }),
|
||||
onProcessing: () => updateItem(clientId, { status: "processing" }),
|
||||
});
|
||||
updateItem(clientId, { status: "done", progressPercent: 100 });
|
||||
revalidator.revalidate();
|
||||
} catch (error) {
|
||||
updateItem(clientId, {
|
||||
status: "error",
|
||||
errorKey: error instanceof UploadFileClientError ? error.errorKey : "files.error.uploadIncomplete",
|
||||
});
|
||||
}
|
||||
},
|
||||
[revalidator, tenantSlug, updateItem],
|
||||
);
|
||||
|
||||
const onFiles = useCallback(
|
||||
(fileList: FileList | null) => {
|
||||
if (!fileList) return;
|
||||
const next: FileUploadDisplayItem[] = [];
|
||||
for (const file of Array.from(fileList)) {
|
||||
const clientId = `${file.name}-${file.size}-${file.lastModified}`;
|
||||
next.push({ clientId, filename: file.name, sizeBytes: file.size, status: "queued", progressPercent: 0, errorKey: null });
|
||||
void uploadOne(file, clientId);
|
||||
}
|
||||
setUploadItems((current) => [...current, ...next]);
|
||||
},
|
||||
[uploadOne],
|
||||
);
|
||||
|
||||
const clearUploadQueue = useCallback(() => setUploadItems([]), []);
|
||||
const uploading = uploadItems.some((item) => item.status === "queued" || item.status === "uploading" || item.status === "processing");
|
||||
|
||||
function buildSearch(query: FilesBrowserQuery, page: number): string {
|
||||
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.q.trim()) params.set("q", query.q.trim());
|
||||
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() });
|
||||
if (page > 1) params.set("page", String(page));
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
function onApply(query: FilesBrowserQuery) {
|
||||
// Any filter/search/view change starts over at page 1: page 3 of the old
|
||||
// result set says nothing about the new one.
|
||||
navigate({ search: buildSearch(query, 1) });
|
||||
}
|
||||
|
||||
function onGoToPage(query: FilesBrowserQuery, page: number) {
|
||||
navigate({ search: buildSearch(query, page) });
|
||||
}
|
||||
|
||||
return (
|
||||
<FilesBrowserPage
|
||||
vm={vm}
|
||||
uploadHref={uploadHref}
|
||||
nextHref={nextHref}
|
||||
upload={canWrite ? { items: uploadItems, onFiles, uploading, onClose: clearUploadQueue } : undefined}
|
||||
bulkZipAction={bulkZipAction}
|
||||
selectedIds={selectedIds}
|
||||
actions={{ onApply, onToggleSelect, onToggleSelectAll }}
|
||||
actions={{ onApply, onGoToPage, onToggleSelect, onToggleSelectAll }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user