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
+63
-15
@@ -2,12 +2,13 @@
|
||||
// URLs only, AD-23); action handles archive/reactivate/delete/regenerate +
|
||||
// audit. Not-visible / foreign file -> 404. Baseline functional UI.
|
||||
|
||||
import { type ActionFunctionArgs, type LoaderFunctionArgs, redirect, useLoaderData } from "react-router";
|
||||
import { type ActionFunctionArgs, type LoaderFunctionArgs, redirect, useActionData, useLoaderData } from "react-router";
|
||||
import { buildFileDetailVM, type FileDetailVM, type FileLinkedEntity } from "@hivegrid/view-models";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { badRequestResponse, loadFilesContext, notFoundResponse, requireFilesPermission } from "~/utils/integrations/fileAccess.server";
|
||||
import {
|
||||
archiveFile,
|
||||
findFileNeighbours,
|
||||
getVisibleFileOrThrow,
|
||||
getVisibleFileWithLinks,
|
||||
hardDeleteFile,
|
||||
linkFile,
|
||||
@@ -17,12 +18,26 @@ import {
|
||||
updateFileMeta,
|
||||
type FileEntityType,
|
||||
} from "~/utils/integrations/fileService.server";
|
||||
import { fileLinkKey, resolveFileLinkLabels } from "~/utils/integrations/fileLinkTargets.server";
|
||||
import { auditFileEvent, logFileActivity } from "~/utils/integrations/fileAudit.server";
|
||||
import { filesDetailPath, mediaVariantPath } from "~/utils/integrations/fileRoutePaths";
|
||||
import { FileDetailPage } from "~/components/screens/files/FileDetailPage";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
import { useSaveToast } from "~/hooks/use-save-toast";
|
||||
|
||||
type LoaderData = { title: string; vm: FileDetailVM; filesHref: string };
|
||||
type LoaderData = { title: string; vm: FileDetailVM; filesHref: string; linkSearchHref: string };
|
||||
|
||||
type ActionData = { intent: string; ok?: true; messageKey?: string; error?: string };
|
||||
|
||||
const FILE_SUCCESS_KEYS: Readonly<Record<string, string>> = {
|
||||
link: "files.toast.linked",
|
||||
unlink: "files.toast.unlinked",
|
||||
rename: "files.toast.renamed",
|
||||
updateMeta: "files.toast.tagsSaved",
|
||||
archive: "files.toast.archived",
|
||||
reactivate: "files.toast.reactivated",
|
||||
regeneratePreview: "files.toast.previewRequested",
|
||||
};
|
||||
|
||||
const FILE_ENTITY_TYPES: FileEntityType[] = [
|
||||
"contact",
|
||||
@@ -38,7 +53,6 @@ const FILE_ENTITY_TYPES: FileEntityType[] = [
|
||||
];
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const { t } = await getTranslations(request);
|
||||
const ctx = await loadFilesContext({ request, params, requireModule: true });
|
||||
const fileId = params.id ?? "";
|
||||
const tenantSlug = params.tenant ?? "";
|
||||
@@ -50,10 +64,17 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
throw notFoundResponse();
|
||||
}
|
||||
|
||||
// Paging through the library happens from the detail view, so the neighbours
|
||||
// are resolved here rather than carried along in the URL.
|
||||
const neighbours = await findFileNeighbours({ tenantId: ctx.tenantId, ctx, fileId: file.id });
|
||||
|
||||
// A link that only says "Kontakt" names nothing; resolve what it points at.
|
||||
const linkLabels = await resolveFileLinkLabels({ tenantId: ctx.tenantId, links });
|
||||
const linkedEntities: FileLinkedEntity[] = links.map((link) => ({
|
||||
entityType: link.entityType,
|
||||
entityId: link.entityId,
|
||||
linkRole: link.linkRole,
|
||||
label: linkLabels.get(fileLinkKey(link.entityType, link.entityId)) ?? null,
|
||||
href: null,
|
||||
}));
|
||||
|
||||
@@ -72,12 +93,19 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
downloadUrl: mediaVariantPath(tenantSlug, file.id, "original"),
|
||||
assignedToUserId: file.assignedToUserId,
|
||||
linkedEntities,
|
||||
previousHref: neighbours.previousId ? filesDetailPath(tenantSlug, neighbours.previousId) : null,
|
||||
nextHref: neighbours.nextId ? filesDetailPath(tenantSlug, neighbours.nextId) : null,
|
||||
canWrite: ctx.permissions.includes("files.write"),
|
||||
canDelete: ctx.permissions.includes("files.delete"),
|
||||
canAdmin: ctx.permissions.includes("files.admin"),
|
||||
});
|
||||
|
||||
return Response.json({ title: `${file.displayName} | ${process.env.APP_NAME}`, vm, filesHref: `/${tenantSlug}/files` } satisfies LoaderData);
|
||||
return Response.json({
|
||||
title: `${file.displayName} | ${process.env.APP_NAME}`,
|
||||
vm,
|
||||
filesHref: `/${tenantSlug}/files`,
|
||||
linkSearchHref: `/${tenantSlug}/files/link-targets`,
|
||||
} satisfies LoaderData);
|
||||
};
|
||||
|
||||
export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
@@ -90,11 +118,13 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
try {
|
||||
if (intent === "delete") {
|
||||
requireFilesPermission(ctx, "files.delete");
|
||||
await getVisibleFileOrThrow(ctx.tenantId, fileId, ctx);
|
||||
await hardDeleteFile({ tenantId: ctx.tenantId, fileId });
|
||||
await auditFileEvent({ ctx, action: "file.deleted", fileId });
|
||||
return redirect(`/${tenantSlug}/files`);
|
||||
return redirect(`/${tenantSlug}/files?toast=${encodeURIComponent("files.toast.deleted")}`);
|
||||
}
|
||||
requireFilesPermission(ctx, "files.write");
|
||||
await getVisibleFileOrThrow(ctx.tenantId, fileId, ctx);
|
||||
if (intent === "link") {
|
||||
const entityType = String(formData.get("entityType") ?? "") as FileEntityType;
|
||||
const entityId = String(formData.get("entityId") ?? "").trim();
|
||||
@@ -102,17 +132,29 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
if (!FILE_ENTITY_TYPES.includes(entityType) || !entityId) {
|
||||
throw badRequestResponse();
|
||||
}
|
||||
await linkFile({ tenantId: ctx.tenantId, userId: ctx.userId, fileId, entityType, entityId, linkRole });
|
||||
await linkFile({ tenantId: ctx.tenantId, userId: ctx.userId, fileId, entityType, entityId, linkRole, ctx });
|
||||
await auditFileEvent({ ctx, action: "file.linked", fileId, metadata: { entityType, entityId } });
|
||||
await logFileActivity({ ctx, entityType, entityId, activityType: "file_uploaded", summaryText: "Datei verknüpft", fileId });
|
||||
return redirect(filesDetailPath(tenantSlug, fileId));
|
||||
await logFileActivity({ ctx, entityType, entityId, activityType: "file_uploaded", summaryText: "files.toast.linked", fileId });
|
||||
return Response.json({ intent, ok: true, messageKey: FILE_SUCCESS_KEYS[intent] } satisfies ActionData);
|
||||
}
|
||||
if (intent === "unlink") {
|
||||
const entityType = String(formData.get("entityType") ?? "") as FileEntityType;
|
||||
const entityId = String(formData.get("entityId") ?? "").trim();
|
||||
await unlinkFile({ tenantId: ctx.tenantId, fileId, entityType, entityId });
|
||||
if (!FILE_ENTITY_TYPES.includes(entityType) || !entityId) {
|
||||
throw badRequestResponse();
|
||||
}
|
||||
await unlinkFile({ tenantId: ctx.tenantId, fileId, entityType, entityId, ctx });
|
||||
await auditFileEvent({ ctx, action: "file.unlinked", fileId, metadata: { entityType, entityId } });
|
||||
return redirect(filesDetailPath(tenantSlug, fileId));
|
||||
return Response.json({ intent, ok: true, messageKey: FILE_SUCCESS_KEYS[intent] } satisfies ActionData);
|
||||
}
|
||||
if (intent === "rename") {
|
||||
// The title is edited in place in the header; an empty name would leave
|
||||
// the file without any handle at all, so it stays as it was.
|
||||
const displayName = String(formData.get("displayName") ?? "").trim();
|
||||
if (!displayName) throw badRequestResponse();
|
||||
await updateFileMeta({ tenantId: ctx.tenantId, fileId, displayName });
|
||||
await auditFileEvent({ ctx, action: "file.updated", fileId, metadata: { renamed: true } });
|
||||
return Response.json({ intent, ok: true, messageKey: FILE_SUCCESS_KEYS[intent] } satisfies ActionData);
|
||||
}
|
||||
if (intent === "updateMeta") {
|
||||
// Tags come in as a comma-separated list; normalize (trim, drop empties,
|
||||
@@ -127,7 +169,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
).slice(0, 30);
|
||||
await updateFileMeta({ tenantId: ctx.tenantId, fileId, tags });
|
||||
await auditFileEvent({ ctx, action: "file.updated", fileId, metadata: { tagsUpdated: true } });
|
||||
return redirect(filesDetailPath(tenantSlug, fileId));
|
||||
return Response.json({ intent, ok: true, messageKey: FILE_SUCCESS_KEYS[intent] } satisfies ActionData);
|
||||
}
|
||||
if (intent === "archive") {
|
||||
await archiveFile({ tenantId: ctx.tenantId, fileId });
|
||||
@@ -139,7 +181,9 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
await regenerateFilePreview({ tenantId: ctx.tenantId, fileId });
|
||||
await auditFileEvent({ ctx, action: "file.updated", fileId, metadata: { previewRegenerated: true } });
|
||||
}
|
||||
return redirect(filesDetailPath(tenantSlug, fileId));
|
||||
const messageKey = FILE_SUCCESS_KEYS[intent];
|
||||
if (!messageKey) return Response.json({ intent, error: "files.error.invalidAction" } satisfies ActionData, { status: 400 });
|
||||
return Response.json({ intent, ok: true, messageKey } satisfies ActionData);
|
||||
} catch (error) {
|
||||
if (error instanceof Response) throw error;
|
||||
throw notFoundResponse();
|
||||
@@ -147,11 +191,15 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
};
|
||||
|
||||
export default function FileDetailRoute() {
|
||||
const { vm, filesHref } = useLoaderData<LoaderData>();
|
||||
const { vm, filesHref, linkSearchHref } = useLoaderData<LoaderData>();
|
||||
const actionData = useActionData<ActionData>();
|
||||
|
||||
useSaveToast(actionData);
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.files.detail" />;
|
||||
}
|
||||
return <FileDetailPage data={vm.data} entityTypes={FILE_ENTITY_TYPES} filesHref={filesHref} />;
|
||||
return <FileDetailPage data={vm.data} entityTypes={FILE_ENTITY_TYPES} filesHref={filesHref} linkSearchHref={linkSearchHref} />;
|
||||
}
|
||||
|
||||
export function ErrorBoundary() {
|
||||
|
||||
Reference in new issue
Block a user