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: display cards for each work center in production dashboard

Brad Barbin57489836af31
diff --git a/apps/erp/app/components/Gantt/Gantt.tsx b/apps/erp/app/components/Gantt/Gantt.tsx
index 1595d526ca..f54e0df2f4 100644
--- a/apps/erp/app/components/Gantt/Gantt.tsx
+++ b/apps/erp/app/components/Gantt/Gantt.tsx
@@ -9,6 +9,7 @@ import {
Popover,
PopoverContent,
PopoverTrigger,
+ PulsingDot,
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
@@ -663,17 +664,6 @@ function LiveReloadingStatus({
);
}
-function PulsingDot() {
- return (
- <span className="relative flex h-2 w-2">
- <span
- className={`absolute h-full w-full animate-ping rounded-full border border-emerald-500 opacity-100 duration-1000`}
- />
- <span className={`h-2 w-2 rounded-full bg-emerald-500`} />
- </span>
- );
-}
-
function SpanWithDuration({
showDuration,
node,
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index afc1b2a194..28bfdfe215 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -25,10 +25,6 @@ export async function deleteJob(
return client.from("job").delete().eq("id", jobId);
}
-export async function getJob(client: SupabaseClient<Database>, id: string) {
- return client.from("jobs").select("*").eq("id", id).single();
-}
-
export async function deleteJobMaterial(
client: SupabaseClient<Database>,
jobMaterialId: string
@@ -78,6 +74,19 @@ export async function getActiveJobOperationsByLocation(
});
}
+export async function getActiveProductionEvents(
+ client: SupabaseClient<Database>,
+ companyId: string
+) {
+ return client
+ .from("productionEvent")
+ .select(
+ "*, ...jobOperation(description, ...job(jobId, customerId, dueDate, deadlineType, ...salesOrderLine(...salesOrder(salesOrderId))))"
+ )
+ .eq("companyId", companyId)
+ .is("endTime", null);
+}
+
export async function deleteScrapReason(
client: SupabaseClient<Database>,
scrapReasonId: string
@@ -116,6 +125,10 @@ export async function getJobDocuments(
}
}
+export async function getJob(client: SupabaseClient<Database>, id: string) {
+ return client.from("jobs").select("*").eq("id", id).single();
+}
+
export async function getJobs(
client: SupabaseClient<Database>,
companyId: string,
diff --git a/apps/erp/app/modules/production/types.ts b/apps/erp/app/modules/production/types.ts
index f2f512ab1a..d91b070f3c 100644
--- a/apps/erp/app/modules/production/types.ts
+++ b/apps/erp/app/modules/production/types.ts
@@ -1,4 +1,5 @@
import type {
+ getActiveProductionEvents,
getJob,
getJobMaterialsWithQuantityOnHand,
getJobMethodTree,
@@ -8,6 +9,10 @@ import type {
getScrapReasons,
} from "./production.service";
+export type ActiveProductionEvent = NonNullable<
+ Awaited<ReturnType<typeof getActiveProductionEvents>>["data"]
+>[number];
+
export type Job = NonNullable<Awaited<ReturnType<typeof getJob>>["data"]>;
export type JobMaterial = NonNullable<
diff --git a/apps/erp/app/modules/production/ui/Schedule/Kanban/components/ColumnCard.tsx b/apps/erp/app/modules/production/ui/Schedule/Kanban/components/ColumnCard.tsx
index 5c86ce4e7c..7a47af4671 100644
--- a/apps/erp/app/modules/production/ui/Schedule/Kanban/components/ColumnCard.tsx
+++ b/apps/erp/app/modules/production/ui/Schedule/Kanban/components/ColumnCard.tsx
@@ -1,4 +1,10 @@
-import { cn, IconButton, ScrollArea, ScrollBar } from "@carbon/react";
+import {
+ cn,
+ IconButton,
+ PulsingDot,
+ ScrollArea,
+ ScrollBar,
+} from "@carbon/react";
import { useUrlParams } from "@carbon/remix";
import { formatDurationMilliseconds } from "@carbon/utils";
import { useDndContext } from "@dnd-kit/core";
@@ -84,16 +90,7 @@ export function ColumnCard({
>
<div className="p-4 w-full font-semibold text-left flex flex-row space-between items-center sticky top-0 bg-card z-1 border-b">
<div className="flex flex-grow items-start space-x-2">
- {column.active ? (
- <PulsingDot />
- ) : (
- <div
- className={cn(
- "w-2 h-2 bg-muted rounded-full mt-2",
- totalDuration > 0 && "bg-red-500"
- )}
- />
- )}
+ <PulsingDot inactive={!column.active} />
<div className="flex flex-col flex-grow">
<span className="mr-auto truncate"> {column.title}</span>
{totalDuration > 0 ? (
@@ -159,14 +156,3 @@ export function BoardContainer({ children }: { children: React.ReactNode }) {
</ScrollArea>
);
}
-
-function PulsingDot() {
- return (
- <span className="relative flex h-2 w-2 mt-2">
- <span
- className={`absolute h-full w-full animate-ping rounded-full border border-emerald-500 opacity-100 duration-1000`}
- />
- <span className={`h-2 w-2 rounded-full bg-emerald-500`} />
- </span>
- );
-}
diff --git a/apps/erp/app/routes/x+/production+/_index.tsx b/apps/erp/app/routes/x+/production+/_index.tsx
index 3f98d1ef6b..10a6099a99 100644
--- a/apps/erp/app/routes/x+/production+/_index.tsx
+++ b/apps/erp/app/routes/x+/production+/_index.tsx
@@ -4,6 +4,7 @@ import {
CardAction,
CardContent,
CardHeader,
+ CardTitle,
DateRangePicker,
DropdownMenu,
DropdownMenuContent,
@@ -15,6 +16,7 @@ import {
HStack,
IconButton,
Loading,
+ PulsingDot,
Skeleton,
} from "@carbon/react";
import {
@@ -35,21 +37,36 @@ import {
import { formatDurationMilliseconds } from "@carbon/utils";
import { now, toCalendarDateTime } from "@internationalized/date";
import type { DateRange } from "@react-types/datepicker";
-import { json, Link, useFetcher, useLoaderData } from "@remix-run/react";
-import { useEffect, useMemo, useState } from "react";
+import {
+ Await,
+ defer,
+ Link,
+ useFetcher,
+ useLoaderData,
+} from "@remix-run/react";
+import { Suspense, useEffect, useMemo, useState } from "react";
import { CSVLink } from "react-csv";
import {
LuArrowUpRight,
LuChevronDown,
LuEllipsisVertical,
LuFile,
+ LuHardHat,
LuLayoutList,
+ LuSquareUser,
LuUserRoundCheck,
+ LuUsers,
} from "react-icons/lu";
import { Bar, BarChart, LabelList, XAxis, YAxis } from "recharts";
-import { Empty } from "~/components";
+import {
+ CustomerAvatar,
+ EmployeeAvatarGroup,
+ Empty,
+ Hyperlink,
+} from "~/components";
import { useUser } from "~/hooks/useUser";
-import { KPIs } from "~/modules/production";
+import type { ActiveProductionEvent } from "~/modules/production";
+import { getActiveProductionEvents, KPIs } from "~/modules/production";
import { chartIntervals } from "~/modules/shared";
import type { loader as kpiLoader } from "~/routes/api+/production.kpi.$key";
import { path } from "~/utils/path";
@@ -57,6 +74,9 @@ import { capitalize } from "~/utils/string";
import { requirePermissions } from "@carbon/auth/auth.server";
import type { LoaderFunctionArgs } from "@vercel/remix";
+import { RiProgress8Line } from "react-icons/ri";
+import type { WorkCenter } from "~/modules/resources";
+import { getWorkCentersList } from "~/modules/resources";
const OPEN_JOB_STATUSES = ["Ready", "In Progress", "Paused"] as const;
@@ -79,7 +99,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
view: "production",
});
- const [activeJobs, assignedJobs] = await Promise.all([
+ const [activeJobs, assignedJobs, workCenters] = await Promise.all([
client
.from("job")
.select("id,status,assignee")
@@ -90,16 +110,20 @@ export async function loader({ request }: LoaderFunctionArgs) {
.select("id,status,assignee")
.eq("companyId", companyId)
.eq("assignee", userId),
+ getWorkCentersList(client, companyId),
]);
- return json({
+ return defer({
activeJobs: activeJobs.data?.length ?? 0,
assignedJobs: assignedJobs.data?.length ?? 0,
+ workCenters: workCenters.data ?? [],
+ events: getActiveProductionEvents(client, companyId),
});
}
export default function ProductionDashboard() {
- const { activeJobs, assignedJobs } = useLoaderData<typeof loader>();
+ const { activeJobs, assignedJobs, events, workCenters } =
+ useLoaderData<typeof loader>();
const user = useUser();
const kpiFetcher = useFetcher<typeof kpiLoader>();
@@ -308,24 +332,6 @@ export default function ProductionDashboard() {
</Card>
</div>
- <div className="w-full">
- <Carousel className="w-full">
- <CarouselContent>
- {Array.from({ length: 5 }).map((_, index) => (
- <CarouselItem key={index} className="md:basis-1/2 lg:basis-1/4">
- <Card className="dark:border-none dark:shadow-[inset_0_0.5px_0_rgb(255_255_255_/_0.08),_inset_0_0_1px_rgb(255_255_255_/_0.24),_0_0_0_0.5px_rgb(0,0,0,1)]">
- <CardContent className="flex aspect-square items-center justify-center p-6">
- <span className="text-2xl font-semibold">{index + 1}</span>
- </CardContent>
- </Card>
- </CarouselItem>
- ))}
- </CarouselContent>
- <CarouselPrevious className="absolute top-1/2 -translate-y-1/2 left-3" />
- <CarouselNext className="absolute top-1/2 -translate-y-1/2 right-3" />
- </Carousel>
- </div>
-
<div className="w-full">
<Card className="p-0">
<HStack className="justify-between items-start">
@@ -594,6 +600,148 @@ export default function ProductionDashboard() {
</CardContent>
</Card>
</div>
+ <div className="w-full">
+ <Suspense fallback={null}>
+ <Await resolve={events}>
+ {(resolvedEvents) => (
+ <WorkCenterCards
+ events={resolvedEvents.data ?? []}
+ workCenters={workCenters}
+ />
+ )}
+ </Await>
+ </Suspense>
+ </div>
</div>
);
}
+
+function WorkCenterCards({
+ events,
+ workCenters,
+}: {
+ events: ActiveProductionEvent[];
+ workCenters: WorkCenter[];
+}) {
+ const eventsByWorkCenterId = workCenters.reduce<
+ Record<
+ string,
+ {
+ hasEvents: boolean;
+ customerId?: string | null;
+ employeeIds?: (string | null)[];
+ salesOrderId?: string | null;
+ jobId?: string | null;
+ }
+ >
+ >((acc, workCenter) => {
+ const wcEvents = events.filter(
+ (event) => event.workCenterId === workCenter.id
+ );
+
+ if (wcEvents.length === 0) {
+ acc[workCenter.id!] = {
+ hasEvents: false,
+ };
+ return acc;
+ }
+
+ const firstEvent = wcEvents[0];
+ const jobId = firstEvent.jobId;
+ const salesOrderId = firstEvent.salesOrderId;
+ const customerId = firstEvent.customerId;
+ const employeeIds =
+ Array.from(new Set(wcEvents.map((event) => event.employeeId))) ?? [];
+
+ if (workCenter.id) {
+ acc[workCenter.id!] = {
+ hasEvents: true,
+ customerId,
+ employeeIds,
+ jobId,
+ salesOrderId,
+ };
+ }
+
+ return acc;
+ }, {});
+
+ return (
+ <Carousel className="w-full">
+ <CarouselContent>
+ {workCenters.map((workCenter) => {
+ const { hasEvents, customerId, employeeIds, jobId, salesOrderId } =
+ eventsByWorkCenterId[workCenter?.id ?? ""];
+
+ return (
+ <CarouselItem
+ key={workCenter.id}
+ className="md:basis-1/2 lg:basis-1/4"
+ >
+ <Card className="p-0 dark:border-none dark:shadow-[inset_0_0.5px_0_rgb(255_255_255_/_0.08),_inset_0_0_1px_rgb(255_255_255_/_0.24),_0_0_0_0.5px_rgb(0,0,0,1)] h-[280px]">
+ <HStack className="justify-between items-start w-full relative">
+ <CardHeader>
+ <CardTitle className="line-clamp-2 text-base">
+ {workCenter.name}
+ </CardTitle>
+ </CardHeader>
+ <CardAction>
+ <PulsingDot inactive={!hasEvents} />
+ </CardAction>
+ </HStack>
+ <CardContent className="flex items-start justify-start p-6 pt-3 border-t">
+ {!hasEvents ? (
+ <p className="text-muted-foreground text-center w-full h-full flex items-center justify-center">
+ Inactive
+ </p>
+ ) : (
+ <div className="flex flex-col gap-2 items-start justify-start text-sm">
+ {jobId && (
+ <HStack className="justify-start space-x-2">
+ <LuHardHat className="text-muted-foreground" />
+ <Hyperlink to={path.to.job(jobId)}>{jobId}</Hyperlink>
+ </HStack>
+ )}
+
+ {employeeIds?.length ? (
+ <HStack className="justify-start space-x-2">
+ <LuUsers className="text-muted-foreground" />
+ <EmployeeAvatarGroup
+ employeeIds={employeeIds.filter(
+ (id) => id !== null
+ )}
+ />
+ </HStack>
+ ) : null}
+
+ {salesOrderId && (
+ <HStack className="justify-start space-x-2">
+ <RiProgress8Line className="text-muted-foreground" />
+ <Hyperlink
+ to={path.to.salesOrderDetails(salesOrderId)}
+ >
+ {salesOrderId}
+ </Hyperlink>
+ </HStack>
+ )}
+
+ {customerId && (
+ <HStack className="justify-start space-x-2">
+ <LuSquareUser className="text-muted-foreground" />
+ <CustomerAvatar customerId={customerId} />
+ </HStack>
+ )}
+ </div>
+ )}
+ </CardContent>
+ <div className="h-[72px]" />
+ </Card>
+ </CarouselItem>
+ );
+ })}
+ </CarouselContent>
+ <CarouselPrevious className="absolute top-1/2 -translate-y-1/2 left-3" />
+ <CarouselNext className="absolute top-1/2 -translate-y-1/2 right-3" />
+ </Carousel>
+ );
+}
diff --git a/apps/mes/app/components/Kanban/components/ColumnCard.tsx b/apps/mes/app/components/Kanban/components/ColumnCard.tsx
index 6d63ebaa64..7dec49d604 100644
--- a/apps/mes/app/components/Kanban/components/ColumnCard.tsx
+++ b/apps/mes/app/components/Kanban/components/ColumnCard.tsx
@@ -1,4 +1,10 @@
-import { cn, IconButton, ScrollArea, ScrollBar } from "@carbon/react";
+import {
+ cn,
+ IconButton,
+ PulsingDot,
+ ScrollArea,
+ ScrollBar,
+} from "@carbon/react";
import { formatDurationMilliseconds } from "@carbon/utils";
import { useDndContext } from "@dnd-kit/core";
import { SortableContext, useSortable } from "@dnd-kit/sortable";
@@ -83,17 +89,9 @@ export function ColumnCard({
>
<div className="p-4 w-full font-semibold text-left flex flex-row space-between items-center sticky top-0 bg-card z-1 border-b">
<div className="flex flex-grow items-start space-x-2">
- {column.active ? (
- <PulsingDot />
- ) : (
- <div
- className={cn(
- "w-2 h-2 bg-muted rounded-full mt-2",
- totalDuration > 0 && "bg-red-500"
- )}
- />
- )}
+ <PulsingDot inactive={!column.active} />
<div className="flex flex-col flex-grow">
+ <span className="mr-auto truncate"> {column.title}</span>
<span className="mr-auto truncate"> {column.title}</span>
{totalDuration > 0 ? (
<span className="text-muted-foreground text-xs">
@@ -154,14 +152,3 @@ export function BoardContainer({ children }: { children: React.ReactNode }) {
</ScrollArea>
);
}
-
-function PulsingDot() {
- return (
- <span className="relative flex h-2 w-2 mt-2">
- <span
- className={`absolute h-full w-full animate-ping rounded-full border border-emerald-500 opacity-100 duration-1000`}
- />
- <span className={`h-2 w-2 rounded-full bg-emerald-500`} />
- </span>
- );
-}
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index ad5e0e11f4..a97285fb29 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -219,6 +219,7 @@ import {
PopoverTrigger,
} from "./Popover";
import { Progress } from "./Progress";
+import { PulsingDot } from "./PulsingDot";
import { RadioGroup, RadioGroupItem } from "./Radio";
import {
ResizableHandle,
@@ -471,6 +472,7 @@ export {
PopoverHeader,
PopoverTrigger,
Progress,
+ PulsingDot,
RadioGroup,
RadioGroupItem,
ResizableHandle,