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
+108
@@ -0,0 +1,108 @@
|
||||
// WF-P8 Subframe delta (S00 boards start page) — route `/projects/boards`.
|
||||
// Loader guards via requireProjectView (module off / missing read permission →
|
||||
// 404), lists the viewer-visible pipelines with stage/project counts plus the
|
||||
// locked ones (deny-based PipelineAccess rule, greyed out per the Subframe
|
||||
// design) and builds the BoardsStartVM. The action handles the locked-board
|
||||
// "request access" intent; the screen is composed from ~/ui and gets its
|
||||
// callbacks injected here.
|
||||
|
||||
import { useActionData, useLoaderData, useNavigation, useSubmit, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
||||
import { buildBoardsStartVM, type BoardsStartVM } from "@hivegrid/view-models";
|
||||
import {
|
||||
loadProjectContext,
|
||||
PROJECT_READ_PERMISSIONS,
|
||||
projectActionErrorResponse,
|
||||
requireAnyProjectPermission,
|
||||
requireProjectView,
|
||||
} from "~/utils/integrations/projects/projectAccess.server";
|
||||
import {
|
||||
PROJECTS_MODULE_KEY,
|
||||
projectBoardSettingsPath,
|
||||
projectLostReasonsAdminPath,
|
||||
projectPipelinesAdminPath,
|
||||
projectsPath,
|
||||
} from "~/utils/integrations/projects/projectRoutePaths";
|
||||
import { loadBoardsStartPipelines } from "~/utils/integrations/projects/boardsStartRoute.server";
|
||||
import { listLockedPipelinesForViewer, requestPipelineAccess } from "~/utils/integrations/projects/pipelineAccessRequest.server";
|
||||
import { BoardsStartPage } from "~/components/screens/projects/BoardsStartPage";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { v2MetaFunction } from "~/utils/compat/v2MetaFunction";
|
||||
import { useSaveToast, type SaveActionResult } from "~/hooks/use-save-toast";
|
||||
|
||||
type LoaderData = { vm: BoardsStartVM; title: string };
|
||||
|
||||
export const meta: v2MetaFunction<LoaderData> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
const ctx = await requireProjectView({ request, params }, PROJECT_READ_PERMISSIONS);
|
||||
const { t } = await getTranslations(request);
|
||||
const tenantSlug = params.tenant!;
|
||||
const [pipelines, lockedPipelines] = await Promise.all([
|
||||
loadBoardsStartPipelines({ tenantId: ctx.tenantId, ctx }),
|
||||
listLockedPipelinesForViewer({ tenantId: ctx.tenantId, ctx }),
|
||||
]);
|
||||
const vm = buildBoardsStartVM({
|
||||
pipelines,
|
||||
lockedPipelines,
|
||||
perms: { canAdmin: ctx.permissions.includes("projects.admin") },
|
||||
buildOpenHref: (pipelineId) => `${projectsPath(tenantSlug)}?pipelineId=${pipelineId}`,
|
||||
// S00 row gear → this board's own settings page (S04). Used to be a hash
|
||||
// anchor into an accordion card on the admin page; that card is gone now
|
||||
// that the settings are a route of their own.
|
||||
buildSettingsHref: (pipelineId) => projectBoardSettingsPath(tenantSlug, pipelineId),
|
||||
adminHref: projectPipelinesAdminPath(tenantSlug),
|
||||
lostReasonsHref: projectLostReasonsAdminPath(tenantSlug),
|
||||
});
|
||||
return Response.json({
|
||||
vm,
|
||||
title: `${t("projects.boards.title")} | ${process.env.APP_NAME}`,
|
||||
} satisfies LoaderData);
|
||||
}
|
||||
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
const ctx = await loadProjectContext({ request, params, requireModule: true });
|
||||
const form = await request.formData();
|
||||
const intent = form.get("_action")?.toString() ?? null;
|
||||
try {
|
||||
requireAnyProjectPermission(ctx, PROJECT_READ_PERMISSIONS);
|
||||
if (intent === "requestAccess") {
|
||||
const pipelineId = form.get("pipelineId")?.toString() ?? "";
|
||||
await requestPipelineAccess({ tenantId: ctx.tenantId, pipelineId, userId: ctx.userId, ctx });
|
||||
return Response.json({ intent, ok: true, messageKey: "projects.toast.accessRequested" });
|
||||
}
|
||||
return Response.json({ error: "projects.error.unsupportedAction" }, { status: 400 });
|
||||
} catch (error) {
|
||||
return projectActionErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export default function ProjectsBoardsRoute() {
|
||||
const data = useLoaderData<LoaderData>();
|
||||
const actionData = useActionData<SaveActionResult>();
|
||||
const submit = useSubmit();
|
||||
const navigation = useNavigation();
|
||||
const vmData = data.vm.status === "ready" ? data.vm.data : null;
|
||||
|
||||
useSaveToast(actionData);
|
||||
|
||||
if (!vmData) return null;
|
||||
|
||||
return (
|
||||
<main className="w-full">
|
||||
<BoardsStartPage
|
||||
data={vmData}
|
||||
submitting={navigation.state !== "idle"}
|
||||
actions={{
|
||||
onRequestAccess: (pipelineId) => {
|
||||
const fd = new FormData();
|
||||
fd.set("_action", "requestAccess");
|
||||
fd.set("pipelineId", pipelineId);
|
||||
submit(fd, { method: "post" });
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
export const handle = { moduleKey: PROJECTS_MODULE_KEY };
|
||||
Reference in new issue
Block a user