Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
refactor: add the key to the suspense component
Brad Barbin942f3dcb43ec
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsxindex 25c16e3f17..c28dca169c 100644--- a/apps/mes/app/components/JobOperation.tsx+++ b/apps/mes/app/components/JobOperation.tsx@@ -41,7 +41,7 @@ import {VStack,type JSONContent,} from "@carbon/react";-import { Await, Link, useFetcher } from "@remix-run/react";+import { Await, Link, useFetcher, useParams } from "@remix-run/react";import type { ComponentProps, ReactNode } from "react";import {Suspense,@@ -160,6 +160,7 @@ export const JobOperation = ({} = useActiveEvents(originalOperation, events);const mode = useMode();+ const { operationId } = useParams();return (<OptionallyFullscreen@@ -418,7 +419,7 @@ export const JobOperation = ({<div className="flex flex-col items-start justify-between w-full"><div className="flex flex-col gap-4 p-4 w-full"><Heading size="h3">Materials</Heading>- <Suspense fallback={<TableSkeleton />}>+ <Suspense key={operationId} fallback={<TableSkeleton />}><Await resolve={materials}>{(resolvedMaterials) => (<Table className="w-full">@@ -477,7 +478,7 @@ export const JobOperation = ({<div className="flex flex-col items-start justify-between w-full"><div className="flex flex-col gap-4 p-4 w-full"><Heading size="h3">Files</Heading>- <Suspense fallback={<TableSkeleton />}>+ <Suspense key={operationId} fallback={<TableSkeleton />}><Await resolve={files}>{(resolvedFiles) => (<Table className="w-full">@@ -1196,9 +1197,9 @@ function StartStopButton({<Hidden name="type" value={eventType} /><Hidden name="workCenterId" value={operation.workCenterId ?? undefined} />{isActive ? (- <PauseButton disabled={fetcher.state === "submitting"} type="submit" />+ <PauseButton disabled={fetcher.state !== "idle"} type="submit" />) : (- <PlayButton disabled={fetcher.state === "submitting"} type="submit" />+ <PlayButton disabled={fetcher.state !== "idle"} type="submit" />)}</ValidatedForm>);diff --git a/apps/mes/app/routes/x+/active.$operationId.tsx b/apps/mes/app/routes/x+/active.$operationId.tsxindex 638fee4e85..640a00c337 100644--- a/apps/mes/app/routes/x+/active.$operationId.tsx+++ b/apps/mes/app/routes/x+/active.$operationId.tsx@@ -2,74 +2,9 @@ import { useLoaderData, useParams } from "@remix-run/react";import { JobOperation } from "~/components";-import { error } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "@vercel/remix";-import { defer, redirect } from "@vercel/remix";-import type { OperationWithDetails } from "~/services/jobs.service";-import {- getJobByOperationId,- getJobFiles,- getJobMaterialsByOperationId,- getJobOperationById,- getProductionEventsForJobOperation,- getProductionQuantitiesForJobOperation,-} from "~/services/jobs.service";-import { makeDurations } from "~/utils/durations";+import type { loader } from "~/services/operation.server";import { path } from "~/utils/path";--export async function loader({ request, params }: LoaderFunctionArgs) {- const { client, userId, companyId } = await requirePermissions(request, {});-- const { operationId } = params;- if (!operationId) throw new Error("Operation ID is required");-- const [events, quantities, job, operation] = await Promise.all([- getProductionEventsForJobOperation(client, {- operationId,- userId,- }),- getProductionQuantitiesForJobOperation(client, operationId),- getJobByOperationId(client, operationId),- getJobOperationById(client, operationId),- ]);-- if (job.error) {- throw redirect(- path.to.jobs,- await flash(request, error(job.error, "Failed to fetch job"))- );- }-- if (operation.error) {- throw redirect(- path.to.jobs,- await flash(request, error(operation.error, "Failed to fetch operation"))- );- }-- return defer({- events: events.data ?? [],- quantities: (quantities.data ?? []).reduce(- (acc, curr) => {- if (curr.type === "Scrap") {- acc.scrap += curr.quantity;- } else if (curr.type === "Production") {- acc.production += curr.quantity;- } else if (curr.type === "Rework") {- acc.rework += curr.quantity;- }- return acc;- },- { scrap: 0, production: 0, rework: 0 }- ),- job: job.data,- files: getJobFiles(client, companyId, job.data),- materials: getJobMaterialsByOperationId(client, operation.data?.[0]),- operation: makeDurations(operation.data?.[0]) as OperationWithDetails,- });-}+export { loader } from "~/services/operation.server";export default function OperationRoute() {const { operationId } = useParams();@@ -80,7 +15,6 @@ export default function OperationRoute() {return (<JobOperation- key={operationId}backPath={path.to.active}events={events}files={files}diff --git a/apps/mes/app/routes/x+/jobs.$workCenterId.$operationId.tsx b/apps/mes/app/routes/x+/jobs.$workCenterId.$operationId.tsxindex 75b4313e5b..895529059a 100644--- a/apps/mes/app/routes/x+/jobs.$workCenterId.$operationId.tsx+++ b/apps/mes/app/routes/x+/jobs.$workCenterId.$operationId.tsx@@ -2,74 +2,9 @@ import { useLoaderData, useParams } from "@remix-run/react";import { JobOperation } from "~/components";-import { error } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "@vercel/remix";-import { defer, redirect } from "@vercel/remix";-import type { OperationWithDetails } from "~/services/jobs.service";-import {- getJobByOperationId,- getJobFiles,- getJobMaterialsByOperationId,- getJobOperationById,- getProductionEventsForJobOperation,- getProductionQuantitiesForJobOperation,-} from "~/services/jobs.service";-import { makeDurations } from "~/utils/durations";+import type { loader } from "~/services/operation.server";import { path } from "~/utils/path";--export async function loader({ request, params }: LoaderFunctionArgs) {- const { client, userId, companyId } = await requirePermissions(request, {});-- const { operationId } = params;- if (!operationId) throw new Error("Operation ID is required");-- const [events, quantities, job, operation] = await Promise.all([- getProductionEventsForJobOperation(client, {- operationId,- userId,- }),- getProductionQuantitiesForJobOperation(client, operationId),- getJobByOperationId(client, operationId),- getJobOperationById(client, operationId),- ]);-- if (job.error) {- throw redirect(- path.to.jobs,- await flash(request, error(job.error, "Failed to fetch job"))- );- }-- if (operation.error) {- throw redirect(- path.to.jobs,- await flash(request, error(operation.error, "Failed to fetch operation"))- );- }-- return defer({- events: events.data ?? [],- quantities: (quantities.data ?? []).reduce(- (acc, curr) => {- if (curr.type === "Scrap") {- acc.scrap += curr.quantity;- } else if (curr.type === "Production") {- acc.production += curr.quantity;- } else if (curr.type === "Rework") {- acc.rework += curr.quantity;- }- return acc;- },- { scrap: 0, production: 0, rework: 0 }- ),- job: job.data,- files: getJobFiles(client, companyId, job.data),- materials: getJobMaterialsByOperationId(client, operation.data?.[0]),- operation: makeDurations(operation.data?.[0]) as OperationWithDetails,- });-}+export { loader } from "~/services/operation.server";export default function OperationRoute() {const { operationId, workCenterId } = useParams();@@ -81,7 +16,6 @@ export default function OperationRoute() {return (<JobOperation- key={operationId}backPath={path.to.workCenter(workCenterId)}events={events}files={files}diff --git a/apps/mes/app/routes/x+/recent.$operationId.tsx b/apps/mes/app/routes/x+/recent.$operationId.tsxindex 32f8a8b18f..3739d30085 100644--- a/apps/mes/app/routes/x+/recent.$operationId.tsx+++ b/apps/mes/app/routes/x+/recent.$operationId.tsx@@ -2,74 +2,9 @@ import { useLoaderData, useParams } from "@remix-run/react";import { JobOperation } from "~/components";-import { error } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "@vercel/remix";-import { defer, redirect } from "@vercel/remix";-import type { OperationWithDetails } from "~/services/jobs.service";-import {- getJobByOperationId,- getJobFiles,- getJobMaterialsByOperationId,- getJobOperationById,- getProductionEventsForJobOperation,- getProductionQuantitiesForJobOperation,-} from "~/services/jobs.service";-import { makeDurations } from "~/utils/durations";+import type { loader } from "~/services/operation.server";import { path } from "~/utils/path";--export async function loader({ request, params }: LoaderFunctionArgs) {- const { client, userId, companyId } = await requirePermissions(request, {});-- const { operationId } = params;- if (!operationId) throw new Error("Operation ID is required");-- const [events, quantities, job, operation] = await Promise.all([- getProductionEventsForJobOperation(client, {- operationId,- userId,- }),- getProductionQuantitiesForJobOperation(client, operationId),- getJobByOperationId(client, operationId),- getJobOperationById(client, operationId),- ]);-- if (job.error) {- throw redirect(- path.to.jobs,- await flash(request, error(job.error, "Failed to fetch job"))- );- }-- if (operation.error) {- throw redirect(- path.to.jobs,- await flash(request, error(operation.error, "Failed to fetch operation"))- );- }-- return defer({- events: events.data ?? [],- quantities: (quantities.data ?? []).reduce(- (acc, curr) => {- if (curr.type === "Scrap") {- acc.scrap += curr.quantity;- } else if (curr.type === "Production") {- acc.production += curr.quantity;- } else if (curr.type === "Rework") {- acc.rework += curr.quantity;- }- return acc;- },- { scrap: 0, production: 0, rework: 0 }- ),- job: job.data,- files: getJobFiles(client, companyId, job.data),- materials: getJobMaterialsByOperationId(client, operation.data?.[0]),- operation: makeDurations(operation.data?.[0]) as OperationWithDetails,- });-}+export { loader } from "~/services/operation.server";export default function OperationRoute() {const { operationId } = useParams();@@ -80,7 +15,6 @@ export default function OperationRoute() {return (<JobOperation- key={operationId}backPath={path.to.recent}events={events}files={files}