Skip to content

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.

feat: add table for job operations

Brad Barbin01d599a6a0da
diff --git a/apps/carbon/app/components/RealtimeDataProvider.tsx b/apps/carbon/app/components/RealtimeDataProvider.tsx
index cbfbe54219..e30d49078f 100644
--- a/apps/carbon/app/components/RealtimeDataProvider.tsx
+++ b/apps/carbon/app/components/RealtimeDataProvider.tsx
@@ -1,3 +1,5 @@
+"use client";
+
import idb from "localforage";
import { useEffect } from "react";
import { useUser } from "~/hooks";
diff --git a/apps/carbon/app/modules/production/production.service.ts b/apps/carbon/app/modules/production/production.service.ts
index 21aa8f22ad..4ca6ca512d 100644
--- a/apps/carbon/app/modules/production/production.service.ts
+++ b/apps/carbon/app/modules/production/production.service.ts
@@ -243,7 +243,7 @@ export async function getJobOperations(
) {
let query = client
.from("jobOperation")
- .select("*", {
+ .select("*, jobMakeMethod(parentMaterialId, item(readableId))", {
count: "exact",
})
.eq("jobId", jobId);
diff --git a/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsx
index 277baf4edd..95517b95d4 100644
--- a/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsx
+++ b/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsx
@@ -16,6 +16,7 @@ import {
LuChevronDown,
LuClock,
LuHardHat,
+ LuList,
LuPackage,
LuSettings,
LuTable,
@@ -24,6 +25,7 @@ import { Assignee, Copy, useOptimisticAssignment } from "~/components";
import { useOptimisticLocation, usePermissions, useRouteData } from "~/hooks";
import { path } from "~/utils/path";
import type { Job } from "../../types";
+import JobStatus from "./JobStatus";
const JobHeader = () => {
const navigate = useNavigate();
@@ -78,6 +80,7 @@ const JobHeader = () => {
</Heading>
</Link>
<Copy text={routeData?.job?.jobId ?? ""} />
+ <JobStatus status={routeData?.job?.status} />
</HStack>
<HStack>
@@ -91,7 +94,7 @@ const JobHeader = () => {
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
- leftIcon={<LuTable />}
+ leftIcon={currentValue === "details" ? <LuList /> : <LuTable />}
rightIcon={<LuChevronDown />}
variant="secondary"
>
diff --git a/apps/carbon/app/modules/production/ui/Jobs/JobOperationsTable.tsx b/apps/carbon/app/modules/production/ui/Jobs/JobOperationsTable.tsx
new file mode 100644
index 0000000000..9a237152f5
--- /dev/null
+++ b/apps/carbon/app/modules/production/ui/Jobs/JobOperationsTable.tsx
@@ -0,0 +1,99 @@
+import { HStack } from "@carbon/react";
+import { useParams } from "@remix-run/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { memo, useMemo } from "react";
+import { Hyperlink, Table } from "~/components";
+import { Enumerable } from "~/components/Enumerable";
+import { operationTypes } from "~/modules/shared";
+import { path } from "~/utils/path";
+import type { JobOperation } from "../../types";
+
+type JobOperationsTableProps = {
+ data: JobOperation[];
+ count: number;
+};
+
+const JobOperationsTable = memo(({ data, count }: JobOperationsTableProps) => {
+ const { jobId } = useParams();
+ if (!jobId) throw new Error("Job ID is required");
+
+ const columns = useMemo<ColumnDef<JobOperation>[]>(() => {
+ return [
+ {
+ accessorKey: "description",
+ header: "Description",
+ cell: ({ row }) => (
+ <HStack className="py-1">
+ <Hyperlink
+ to={path.to.jobMakeMethod(
+ jobId,
+ "make",
+ row.original.jobMakeMethodId!
+ )}
+ className="max-w-[260px] truncate"
+ >
+ {row.original.description}
+ </Hyperlink>
+ </HStack>
+ ),
+ },
+ {
+ id: "item",
+ header: "Item",
+ cell: ({ row }) => {
+ return (
+ <Hyperlink
+ to={
+ row.original.jobMakeMethod?.parentMaterialId
+ ? path.to.jobMakeMethod(
+ jobId,
+ row.original.jobMakeMethodId!,
+ row.original.jobMakeMethod?.parentMaterialId
+ )
+ : path.to.jobMethod(jobId, row.original.jobMakeMethodId!)
+ }
+ >
+ {row.original.jobMakeMethod?.item?.readableId}
+ </Hyperlink>
+ );
+ },
+ },
+ {
+ accessorKey: "operationType",
+ header: "Operation Type",
+ cell: (item) => <Enumerable value={item.getValue<string>() ?? null} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: operationTypes.map((value) => ({
+ value,
+ label: <Enumerable value={value ?? null} />,
+ })),
+ },
+ },
+ },
+
+ {
+ accessorKey: "operationQuantity",
+ header: "Quantity",
+ cell: (item) => item.getValue(),
+ },
+ {
+ accessorKey: "quantityComplete",
+ header: "Qty. Complete",
+ cell: (item) => item.getValue(),
+ },
+ {
+ accessorKey: "quantityScrapped",
+ header: "Qty. Scrapped",
+ cell: (item) => item.getValue(),
+ },
+ ];
+ }, [jobId]);
+
+ return <Table<JobOperation> count={count} columns={columns} data={data} />;
+});
+
+JobOperationsTable.displayName = "JobOperationsTable";
+
+export default JobOperationsTable;
diff --git a/apps/carbon/app/modules/production/ui/Jobs/JobsTable.tsx b/apps/carbon/app/modules/production/ui/Jobs/JobsTable.tsx
index ebe5cec246..f98911a423 100644
--- a/apps/carbon/app/modules/production/ui/Jobs/JobsTable.tsx
+++ b/apps/carbon/app/modules/production/ui/Jobs/JobsTable.tsx
@@ -143,6 +143,22 @@ const JobsTable = memo(({ data, count, locations }: JobsTableProps) => {
pluralHeader: "Statuses",
},
},
+ {
+ id: "assignee",
+ header: "Assignee",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.assignee} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ })),
+ },
+ },
+ },
{
accessorKey: "dueDate",
header: "Due Date",
diff --git a/apps/carbon/app/modules/production/ui/Jobs/index.ts b/apps/carbon/app/modules/production/ui/Jobs/index.ts
index b8d4c80a0e..8928033dfc 100644
--- a/apps/carbon/app/modules/production/ui/Jobs/index.ts
+++ b/apps/carbon/app/modules/production/ui/Jobs/index.ts
@@ -6,6 +6,7 @@ import JobForm from "./JobForm";
import JobHeader from "./JobHeader";
import JobMaterialForm from "./JobMaterialForm";
import JobMaterialsTable from "./JobMaterialsTable";
+import JobOperationsTable from "./JobOperationsTable";
import JobsTable from "./JobsTable";
import JobStatus from "./JobStatus";
@@ -20,6 +21,7 @@ export {
JobHeader,
JobMaterialForm,
JobMaterialsTable,
+ JobOperationsTable,
JobsTable,
JobStatus,
};
diff --git a/apps/carbon/app/routes/assets+/theme[.]css.ts b/apps/carbon/app/routes/assets+/theme[.]css.ts
index e2f2f7cfdf..72d6d89e19 100644
--- a/apps/carbon/app/routes/assets+/theme[.]css.ts
+++ b/apps/carbon/app/routes/assets+/theme[.]css.ts
@@ -2,6 +2,8 @@ import { getThemeCode, themes } from "@carbon/utils";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { getTheme } from "~/services/theme.server";
+export const config = { runtime: "nodejs" };
+
export async function loader({ request }: LoaderFunctionArgs) {
const theme = getTheme(request) as string;
diff --git a/apps/carbon/app/routes/x+/job+/$jobId.operations.tsx b/apps/carbon/app/routes/x+/job+/$jobId.operations.tsx
new file mode 100644
index 0000000000..02820d9fb2
--- /dev/null
+++ b/apps/carbon/app/routes/x+/job+/$jobId.operations.tsx
@@ -0,0 +1,80 @@
+import { VStack } from "@carbon/react";
+import { useLoaderData } from "@remix-run/react";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
+import {
+ getJob,
+ getJobOperations,
+ JobOperationsTable,
+} from "~/modules/production";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import type { Handle } from "~/utils/handle";
+import { path } from "~/utils/path";
+import { getGenericQueryFilters } from "~/utils/query";
+import { error } from "~/utils/result";
+
+export const handle: Handle = {
+ breadcrumb: "Jobs",
+ to: path.to.jobs,
+};
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "production",
+ role: "employee",
+ });
+
+ const { jobId } = params;
+ if (!jobId) throw new Error("Could not find jobId");
+
+ const url = new URL(request.url);
+ const searchParams = new URLSearchParams(url.search);
+ const search = searchParams.get("search");
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
+
+ const job = await getJob(client, jobId);
+ if (job.error) {
+ throw redirect(
+ path.to.jobs,
+ await flash(request, error(job.error, "Failed to fetch job"))
+ );
+ }
+
+ const operations = await getJobOperations(client, jobId, {
+ search,
+ limit,
+ offset,
+ sorts,
+ filters,
+ });
+
+ if (operations.error) {
+ redirect(
+ path.to.production,
+ await flash(
+ request,
+ error(operations.error, "Failed to fetch job operations")
+ )
+ );
+ }
+
+ // TODO: get item inventory
+
+ return json({
+ count: operations.count ?? 0,
+ operations: operations.data ?? [],
+ });
+}
+
+export default function JobOperationsRoute() {
+ const { count, operations } = useLoaderData<typeof loader>();
+ console.log({ operations });
+
+ return (
+ <VStack spacing={0} className="h-[calc(100vh-99px)]">
+ <JobOperationsTable data={operations} count={count} />
+ </VStack>
+ );
+}
diff --git a/apps/developers/app/routes/assets+/theme[.]css.ts b/apps/developers/app/routes/assets+/theme[.]css.ts
index e2f2f7cfdf..72d6d89e19 100644
--- a/apps/developers/app/routes/assets+/theme[.]css.ts
+++ b/apps/developers/app/routes/assets+/theme[.]css.ts
@@ -2,6 +2,8 @@ import { getThemeCode, themes } from "@carbon/utils";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { getTheme } from "~/services/theme.server";
+export const config = { runtime: "nodejs" };
+
export async function loader({ request }: LoaderFunctionArgs) {
const theme = getTheme(request) as string;