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
+23
-128
@@ -3,8 +3,7 @@
|
||||
// audit. Not-visible / foreign file -> 404. Baseline functional UI.
|
||||
|
||||
import { type ActionFunctionArgs, type LoaderFunctionArgs, redirect, useLoaderData } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { buildFileDetailVM, type FileDetailVM, type FileLinkedEntity } from "@toolctrl/view-models";
|
||||
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 {
|
||||
@@ -15,13 +14,15 @@ import {
|
||||
reactivateFile,
|
||||
regenerateFilePreview,
|
||||
unlinkFile,
|
||||
updateFileMeta,
|
||||
type FileEntityType,
|
||||
} from "~/utils/integrations/fileService.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";
|
||||
|
||||
type LoaderData = { title: string; vm: FileDetailVM };
|
||||
type LoaderData = { title: string; vm: FileDetailVM; filesHref: string };
|
||||
|
||||
const FILE_ENTITY_TYPES: FileEntityType[] = [
|
||||
"contact",
|
||||
@@ -76,7 +77,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
canAdmin: ctx.permissions.includes("files.admin"),
|
||||
});
|
||||
|
||||
return Response.json({ title: `${file.displayName} | ${process.env.APP_NAME}`, vm } satisfies LoaderData);
|
||||
return Response.json({ title: `${file.displayName} | ${process.env.APP_NAME}`, vm, filesHref: `/${tenantSlug}/files` } satisfies LoaderData);
|
||||
};
|
||||
|
||||
export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
@@ -113,6 +114,21 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
await auditFileEvent({ ctx, action: "file.unlinked", fileId, metadata: { entityType, entityId } });
|
||||
return redirect(filesDetailPath(tenantSlug, fileId));
|
||||
}
|
||||
if (intent === "updateMeta") {
|
||||
// Tags come in as a comma-separated list; normalize (trim, drop empties,
|
||||
// de-dupe, cap) into the String[] the File row stores.
|
||||
const tags = Array.from(
|
||||
new Set(
|
||||
String(formData.get("tags") ?? "")
|
||||
.split(",")
|
||||
.map((tag) => tag.trim())
|
||||
.filter(Boolean),
|
||||
),
|
||||
).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));
|
||||
}
|
||||
if (intent === "archive") {
|
||||
await archiveFile({ tenantId: ctx.tenantId, fileId });
|
||||
await auditFileEvent({ ctx, action: "file.archived", fileId });
|
||||
@@ -131,132 +147,11 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
};
|
||||
|
||||
export default function FileDetailRoute() {
|
||||
const { t, i18n } = useTranslation();
|
||||
const { vm } = useLoaderData<LoaderData>();
|
||||
const { vm, filesHref } = useLoaderData<LoaderData>();
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <main className="mx-auto max-w-3xl px-4 py-10" data-ui-id="ui.files.detail" />;
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.files.detail" />;
|
||||
}
|
||||
const data = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-3xl px-4 py-10" data-ui-id="ui.files.detail">
|
||||
<h1 className="text-foreground text-xl font-semibold">{data.displayName}</h1>
|
||||
<p className="text-muted-foreground mt-1 text-sm">
|
||||
{data.mimeType} · {dateFormatter.format(new Date(data.createdAtIso))}
|
||||
</p>
|
||||
|
||||
{data.scanNoticeKey ? (
|
||||
<p className="text-theme-600 mt-4 text-sm" data-ui-id="ui.files.detail.scanNotice">
|
||||
{t(data.scanNoticeKey)}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="mt-6" data-ui-id="ui.files.detail.preview">
|
||||
{data.previewUrl ? (
|
||||
<img src={data.previewUrl} alt={data.displayName} className="max-h-96 rounded border" />
|
||||
) : data.previewFallbackKey ? (
|
||||
<p className="text-muted-foreground text-sm">{t(data.previewFallbackKey)}</p>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="mt-6 flex flex-wrap gap-3">
|
||||
<a href={data.downloadUrl} className="text-theme-600 font-medium" data-ui-id="ui.files.detail.download">
|
||||
{t("files.detail.actions.download")}
|
||||
</a>
|
||||
{data.canWrite && data.canRegeneratePreview ? (
|
||||
<form method="post">
|
||||
<input type="hidden" name="intent" value="regeneratePreview" />
|
||||
<button type="submit" className="text-theme-600 font-medium">
|
||||
{t("files.detail.actions.regeneratePreview")}
|
||||
</button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<input type="hidden" name="intent" value="archive" />
|
||||
<button type="submit" className="text-theme-600 font-medium" data-ui-id="ui.files.detail.archive">
|
||||
{t("files.detail.actions.archive")}
|
||||
</button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canDelete ? (
|
||||
<form method="post">
|
||||
<input type="hidden" name="intent" value="delete" />
|
||||
<button type="submit" className="text-destructive font-medium" data-ui-id="ui.files.detail.delete">
|
||||
{t("files.detail.actions.delete")}
|
||||
</button>
|
||||
</form>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{data.tags.length > 0 ? (
|
||||
<section className="mt-6">
|
||||
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("files.detail.section.tags")}</h2>
|
||||
<p className="mt-1 text-sm">{data.tags.join(", ")}</p>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{data.notes ? (
|
||||
<section className="mt-6">
|
||||
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("files.detail.section.notes")}</h2>
|
||||
<p className="mt-1 text-sm">{data.notes}</p>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
<section className="mt-6" data-ui-id="ui.files.detail.links">
|
||||
<h2 className="text-muted-foreground text-xs font-semibold uppercase">{t("files.detail.section.links")}</h2>
|
||||
{data.linkedEntities.length > 0 ? (
|
||||
<ul className="mt-1 text-sm">
|
||||
{data.linkedEntities.map((link) => (
|
||||
<li key={`${link.entityType}-${link.entityId}`} className="flex items-center gap-2" data-link-id={`${link.entityType}-${link.entityId}`}>
|
||||
<span>
|
||||
{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} />
|
||||
<button type="submit" className="text-muted-foreground text-xs underline">
|
||||
{t("files.detail.actions.unlink")}
|
||||
</button>
|
||||
</form>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
{data.canWrite ? (
|
||||
<form method="post" className="mt-3 flex flex-wrap items-end gap-2" data-ui-id="ui.files.detail.linkForm">
|
||||
<input type="hidden" name="intent" value="link" />
|
||||
<label className="text-sm">
|
||||
<span className="text-muted-foreground block text-xs">{t("files.detail.link.entityType")}</span>
|
||||
<select name="entityType" className="border-muted-foreground/40 rounded border px-2 py-1">
|
||||
{FILE_ENTITY_TYPES.map((type) => (
|
||||
<option key={type} value={type}>
|
||||
{type}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="text-sm">
|
||||
<span className="text-muted-foreground block text-xs">{t("files.detail.link.entityId")}</span>
|
||||
<input name="entityId" required className="border-muted-foreground/40 rounded border px-2 py-1" />
|
||||
</label>
|
||||
<label className="text-sm">
|
||||
<span className="text-muted-foreground block text-xs">{t("files.detail.link.role")}</span>
|
||||
<input name="linkRole" className="border-muted-foreground/40 rounded border px-2 py-1" />
|
||||
</label>
|
||||
<button type="submit" className="text-theme-600 font-medium">
|
||||
{t("files.detail.actions.link")}
|
||||
</button>
|
||||
</form>
|
||||
) : null}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
return <FileDetailPage data={vm.data} entityTypes={FILE_ENTITY_TYPES} filesHref={filesHref} />;
|
||||
}
|
||||
|
||||
export function ErrorBoundary() {
|
||||
|
||||
Reference in new issue
Block a user