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
+133
-121
@@ -1,144 +1,156 @@
|
||||
import { Form, Link, useLoaderData, redirect, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { createProject, listProjects, loadProjectBoard, moveProjectStage, undoLastProjectStageChange } from "~/utils/integrations/projects/projectService.server";
|
||||
import { loadProjectContext, projectActionErrorResponse, requireProjectPermission } from "~/utils/integrations/projects/projectAccess.server";
|
||||
import { projectDetailPath, projectPlantafelPath, projectsListPath } from "~/utils/integrations/projects/projectRoutePaths";
|
||||
import type { ProjectBoardVM, ProjektRow } from "~/utils/integrations/projects/projectService.server";
|
||||
// R-P8b (P8 configurable Kanban) Interim-UI (AD-28) — board route `/projects`.
|
||||
// Loader builds the KanbanBoardVM via the shared board helper; the screen is
|
||||
// composed from ~/ui. Pipeline switch + only-mine are navigation (GET query);
|
||||
// stage moves / bulk / quick-create POST intents. Final Subframe optics =
|
||||
// tracked design-nachzug.
|
||||
|
||||
type LoaderData = { tenantSlug: string; projects: ProjektRow[]; board: ProjectBoardVM; includeDemoData: boolean };
|
||||
import { redirect, useActionData, useLoaderData, useNavigate, useNavigation, useSubmit, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { PipelineHandoverVM } from "@hivegrid/view-models";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { loadProjectContext, PROJECT_READ_PERMISSIONS, projectActionErrorResponse, requireProjectPermission, requireProjectView } from "~/utils/integrations/projects/projectAccess.server";
|
||||
import { PROJECTS_MODULE_KEY, projectBoardSettingsPath, projectDetailPath } from "~/utils/integrations/projects/projectRoutePaths";
|
||||
import {
|
||||
handleKanbanIntent,
|
||||
kanbanIntentPermission,
|
||||
loadKanbanData,
|
||||
parseBoardFacetParams,
|
||||
type KanbanLoaderData,
|
||||
} from "~/utils/integrations/projects/projectBoardRoute.server";
|
||||
import { ProjectServiceError } from "~/utils/integrations/projects/projectService.server";
|
||||
import { PipelineKanbanPage } from "~/components/screens/projects/PipelineKanbanPage";
|
||||
import { useBoardLiveUpdates } from "~/utils/stream/useBoardLiveUpdates";
|
||||
import { useBoardFacetParams } from "~/hooks/use-board-facet-params";
|
||||
import { useSaveToast } from "~/hooks/use-save-toast";
|
||||
|
||||
const BOARD_SUCCESS_KEYS: Record<string, string> = {
|
||||
bulkMoveStage: "projects.toast.projectsMoved",
|
||||
duplicateProject: "projects.toast.projectDuplicated",
|
||||
archiveProject: "projects.toast.projectArchived",
|
||||
handoverProject: "projects.toast.handoverCompleted",
|
||||
moveToPipeline: "projects.toast.projectMovedToPipeline",
|
||||
};
|
||||
|
||||
type ProjectsBoardLoaderData = KanbanLoaderData | { noPipeline: true; title: string; tenantSlug: string };
|
||||
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
const ctx = requireProjectPermission(await loadProjectContext({ request, params, requireModule: true }), "projects.read_own");
|
||||
const ctx = await requireProjectView({ request, params }, PROJECT_READ_PERMISSIONS);
|
||||
const { t, locale } = await getTranslations(request);
|
||||
const url = new URL(request.url);
|
||||
const includeDemoData = url.searchParams.get("demo") === "show";
|
||||
const [projects, board] = await Promise.all([
|
||||
listProjects({ tenantId: ctx.tenantId, ctx, includeDemoData }),
|
||||
loadProjectBoard({
|
||||
try {
|
||||
const data = await loadKanbanData({
|
||||
tenantSlug: params.tenant!,
|
||||
tenantId: ctx.tenantId,
|
||||
ctx,
|
||||
pipelineId: url.searchParams.get("pipelineId"),
|
||||
onlyMine: url.searchParams.get("onlyMine") === "1",
|
||||
includeDemoData,
|
||||
}),
|
||||
]);
|
||||
return Response.json({ tenantSlug: params.tenant!, projects, board, includeDemoData } satisfies LoaderData);
|
||||
includeDemoData: url.searchParams.get("demo") === "show",
|
||||
q: url.searchParams.get("q"),
|
||||
facets: parseBoardFacetParams(url.searchParams),
|
||||
locale,
|
||||
});
|
||||
return Response.json(data satisfies KanbanLoaderData);
|
||||
} catch (error) {
|
||||
if (!(error instanceof ProjectServiceError) || error.messageKey !== "projects.error.pipelineRequired") throw error;
|
||||
return Response.json({
|
||||
noPipeline: true,
|
||||
title: t("projects.list.title"),
|
||||
tenantSlug: params.tenant!,
|
||||
} satisfies ProjectsBoardLoaderData);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
const form = await request.formData();
|
||||
const intent = form.get("intent")?.toString() ?? "createProject";
|
||||
if (intent === "moveStage") {
|
||||
const ctx = requireProjectPermission(await loadProjectContext({ request, params, requireModule: true }), "projects.change_stage");
|
||||
await moveProjectStage({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.userId,
|
||||
projectId: form.get("projectId")?.toString() ?? "",
|
||||
targetStageId: form.get("targetStageId")?.toString() ?? "",
|
||||
lostReasonId: form.get("lostReasonId")?.toString() || null,
|
||||
});
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
if (intent === "undoStage") {
|
||||
const ctx = requireProjectPermission(await loadProjectContext({ request, params, requireModule: true }), "projects.change_stage");
|
||||
await undoLastProjectStageChange({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.userId,
|
||||
projectId: form.get("projectId")?.toString() ?? "",
|
||||
});
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
const ctx = requireProjectPermission(await loadProjectContext({ request, params, requireModule: true }), "projects.write");
|
||||
const project = await createProject({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.userId,
|
||||
projektname: form.get("projektname")?.toString() ?? "",
|
||||
beschreibung: form.get("beschreibung")?.toString() ?? null,
|
||||
potenziellerAuftragswert: form.get("potenziellerAuftragswert")?.toString() || null,
|
||||
zustaendigePersonId: ctx.userId,
|
||||
});
|
||||
return redirect(projectDetailPath(params.tenant!, project.id));
|
||||
requireProjectPermission(ctx, kanbanIntentPermission(intent));
|
||||
const { createdProjectId, handover } = await handleKanbanIntent({ intent, form, tenantId: ctx.tenantId, ctx });
|
||||
if (createdProjectId) return redirect(projectDetailPath(params.tenant!, createdProjectId));
|
||||
// `handover` is non-null only when the move just put a card into a stage
|
||||
// that offers M04 — the screen opens the dialog on it.
|
||||
return Response.json({ ok: true, intent, messageKey: intent ? BOARD_SUCCESS_KEYS[intent] : undefined, handover: handover ?? null });
|
||||
} catch (error) {
|
||||
return projectActionErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export default function ProjectsIndexRoute() {
|
||||
export default function ProjectsBoardRoute() {
|
||||
const { t } = useTranslation();
|
||||
const data = useLoaderData<LoaderData>();
|
||||
const data = useLoaderData<ProjectsBoardLoaderData>();
|
||||
const navigate = useNavigate();
|
||||
const { setParam, toggleFacet, removeChip, setPeriodRange, resetFilters } = useBoardFacetParams();
|
||||
const submit = useSubmit();
|
||||
const navigation = useNavigation();
|
||||
const actionData = useActionData<{ intent?: string; ok?: boolean; error?: string; messageKey?: string; handover?: PipelineHandoverVM | null }>();
|
||||
const toastResult = actionData?.error || (actionData?.intent && BOARD_SUCCESS_KEYS[actionData.intent]) ? actionData : undefined;
|
||||
useSaveToast(toastResult);
|
||||
const vmData = "noPipeline" in data ? null : data.vm.status === "ready" ? data.vm.data : null;
|
||||
// Live board: subscribe to the pipeline SSE stream and revalidate on real
|
||||
// change-events (route owns data/revalidation; the screen stays pure).
|
||||
useBoardLiveUpdates(vmData?.sseHref, { paused: navigation.state !== "idle" });
|
||||
|
||||
function post(intent: string, fields: Record<string, string>) {
|
||||
const fd = new FormData();
|
||||
fd.set("_action", intent);
|
||||
for (const [key, value] of Object.entries(fields)) fd.set(key, value);
|
||||
submit(fd, { method: "post" });
|
||||
}
|
||||
|
||||
if ("noPipeline" in data || !vmData) {
|
||||
return (
|
||||
<main className="mx-auto w-full max-w-6xl p-6" data-ui-id="ui.projects.board.empty">
|
||||
<EmptyState title={t("projects.board.empty")} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex w-full max-w-6xl flex-col gap-6 p-6">
|
||||
<header className="flex flex-col gap-1">
|
||||
<h1 className="text-2xl font-semibold">{t("projects.list.title")}</h1>
|
||||
<p className="text-sm text-muted-foreground">{t("projects.list.description")}</p>
|
||||
<Link className="text-sm text-primary underline-offset-2 hover:underline" to={projectsListPath(data.tenantSlug)}>
|
||||
{t("projects.actions.openList")}
|
||||
</Link>
|
||||
<Link className="text-sm text-primary underline-offset-2 hover:underline" to={projectPlantafelPath(data.tenantSlug)}>
|
||||
{t("projects.actions.openPlantafel")}
|
||||
</Link>
|
||||
<Link className="text-sm text-primary underline-offset-2 hover:underline" to={data.includeDemoData ? "?" : "?demo=show"}>
|
||||
{t(data.includeDemoData ? "onboarding.demoData.hideInLists" : "onboarding.demoData.showInLists")}
|
||||
</Link>
|
||||
</header>
|
||||
|
||||
<section className="grid gap-3 md:grid-cols-3">
|
||||
{data.board.columns.map((column) => (
|
||||
<article key={column.stage.id} className="rounded-md border bg-background p-4">
|
||||
<h2 className="font-medium">{column.stage.name}</h2>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{column.projectCount} · {column.aggregateVisible ? column.aggregateValue : "—"}
|
||||
</p>
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
|
||||
<section className="rounded-md border bg-background p-4">
|
||||
<Form method="post" className="grid gap-3 md:grid-cols-[1fr_1fr_auto]">
|
||||
<input type="hidden" name="intent" value="createProject" />
|
||||
<label className="flex flex-col gap-1 text-sm">
|
||||
{t("projects.fields.name")}
|
||||
<input name="projektname" required className="rounded-md border px-3 py-2" />
|
||||
</label>
|
||||
<label className="flex flex-col gap-1 text-sm">
|
||||
{t("projects.fields.value")}
|
||||
<input name="potenziellerAuftragswert" inputMode="decimal" className="rounded-md border px-3 py-2" />
|
||||
</label>
|
||||
<button type="submit" className="self-end rounded-md bg-primary px-4 py-2 text-primary-foreground">
|
||||
{t("projects.actions.create")}
|
||||
</button>
|
||||
</Form>
|
||||
</section>
|
||||
|
||||
<section className="overflow-hidden rounded-md border bg-background">
|
||||
{data.projects.length === 0 ? (
|
||||
<p className="p-4 text-sm text-muted-foreground">{t("projects.list.empty")}</p>
|
||||
) : (
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-muted text-left">
|
||||
<tr>
|
||||
<th className="px-4 py-2">{t("projects.fields.number")}</th>
|
||||
<th className="px-4 py-2">{t("projects.fields.name")}</th>
|
||||
<th className="px-4 py-2">{t("projects.fields.priority")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.projects.map((project) => (
|
||||
<tr key={project.id} className="border-t">
|
||||
<td className="px-4 py-2">{project.projektNummer}</td>
|
||||
<td className="px-4 py-2">
|
||||
<Link className="text-primary underline-offset-2 hover:underline" to={projectDetailPath(data.tenantSlug, project.id)}>
|
||||
{project.projektname}
|
||||
</Link>
|
||||
</td>
|
||||
<td className="px-4 py-2">{project.prioritaet}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</section>
|
||||
// Full width so the screen's page header bar sits flush like every other list screen.
|
||||
<main className="w-full">
|
||||
<PipelineKanbanPage
|
||||
data={vmData}
|
||||
onlyMine={data.onlyMine}
|
||||
q={data.q}
|
||||
facets={data.facets}
|
||||
periodFrom={data.facetSelection.periodFrom}
|
||||
periodTo={data.facetSelection.periodTo}
|
||||
includeDemoData={data.includeDemoData}
|
||||
showDemoToggle={data.demoDataUiEnabled}
|
||||
submitting={navigation.state !== "idle"}
|
||||
errorKey={actionData?.error ?? null}
|
||||
handover={actionData?.handover ?? null}
|
||||
actions={{
|
||||
onOpenProject: (detailHref) => navigate(detailHref),
|
||||
onHandover: (projectId, fromPipelineId, selection) =>
|
||||
post("handoverProject", { projectId, fromPipelineId, selection: JSON.stringify(selection) }),
|
||||
onShowList: () => navigate(data.listHref),
|
||||
// Board settings of THIS board (S04), not the board table — the page
|
||||
// already knows which board it shows.
|
||||
onManageBoard: () => navigate(projectBoardSettingsPath(data.tenantSlug, vmData.pipelineId)),
|
||||
onSwitchPipeline: (pipelineId) => setParam("pipelineId", pipelineId),
|
||||
onToggleOnlyMine: (checked) => setParam("onlyMine", checked ? "1" : ""),
|
||||
onSearch: (q) => setParam("q", q),
|
||||
onToggleFacet: toggleFacet,
|
||||
onRemoveChip: removeChip,
|
||||
onResetFilters: resetFilters,
|
||||
onPeriodRangeChange: setPeriodRange,
|
||||
onToggleDemo: (show) => setParam("demo", show ? "show" : ""),
|
||||
onMove: (projectId, targetStageId, lostReasonId, notiz) =>
|
||||
post("moveStage", { projectId, targetStageId, ...(lostReasonId ? { lostReasonId } : {}), ...(notiz ? { notiz } : {}) }),
|
||||
onBulkMove: (projectIds, targetStageId) => post("bulkMoveStage", { projectIds: projectIds.join(","), targetStageId }),
|
||||
onCreateProject: (fields) => post("createProject", { ...fields, pipelineId: data.pipelineId }),
|
||||
onDuplicate: (projectId) => post("duplicateProject", { projectId }),
|
||||
onArchive: (projectId) => post("archiveProject", { projectId }),
|
||||
onUndoStage: (projectId) => post("undoStage", { projectId }),
|
||||
onRedoStage: (projectId) => post("redoStage", { projectId }),
|
||||
onMoveToPipeline: (projectId, targetPipelineId) => post("moveToPipeline", { projectId, targetPipelineId }),
|
||||
}}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
export const handle = { moduleKey: PROJECTS_MODULE_KEY };
|
||||
Reference in new issue
Block a user