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 quantities, employees, and job highlighting to kanban schedule

Brad Barbin16fda623596f
diff --git a/apps/carbon/app/modules/production/ui/Schedule/Kanban/Kanban.tsx b/apps/carbon/app/modules/production/ui/Schedule/Kanban/Kanban.tsx
index cba6912220..32282cc325 100644
--- a/apps/carbon/app/modules/production/ui/Schedule/Kanban/Kanban.tsx
+++ b/apps/carbon/app/modules/production/ui/Schedule/Kanban/Kanban.tsx
@@ -40,6 +40,7 @@ const Kanban = ({
...displaySettings
}: KanbanProps) => {
const submit = useSubmit();
+ const [selectedGroup, setSelectedGroup] = useState<string | null>(null);
const [columnOrder, setColumnOrder] = useState<string[]>(() => {
// Get stored column order from localStorage
const storedOrder = localStorage.getItem(COLUMN_ORDER_KEY);
@@ -219,6 +220,8 @@ const Kanban = ({
items={items.filter((item) => item.columnId === col.id)}
progressByItemId={progressByItemId}
{...displaySettings}
+ selectedGroup={selectedGroup}
+ setSelectedGroup={setSelectedGroup}
/>
);
})}
@@ -233,24 +236,31 @@ const Kanban = ({
<ColumnCard
isOverlay
column={activeColumn}
+ selectedGroup={selectedGroup}
items={items.filter(
(item) => item.columnId === activeColumn.id
)}
progressByItemId={progressByItemId}
{...displaySettings}
+ setSelectedGroup={setSelectedGroup}
/>
)}
{activeItem && (
<ItemCard
+ selectedGroup={selectedGroup}
item={{
...activeItem,
status: progressByItemId[activeItem.id]?.active
? "In Progress"
: activeItem.status,
+ employeeIds: progressByItemId[activeItem.id]?.employees
+ ? Array.from(progressByItemId[activeItem.id].employees!)
+ : undefined,
progress: progressByItemId[activeItem.id]?.progress ?? 0,
}}
isOverlay
{...displaySettings}
+ setSelectedGroup={setSelectedGroup}
/>
)}
</DragOverlay>,
diff --git a/apps/carbon/app/modules/production/ui/Schedule/Kanban/components/ColumnCard.tsx b/apps/carbon/app/modules/production/ui/Schedule/Kanban/components/ColumnCard.tsx
index 875cfafec4..a567339a0f 100644
--- a/apps/carbon/app/modules/production/ui/Schedule/Kanban/components/ColumnCard.tsx
+++ b/apps/carbon/app/modules/production/ui/Schedule/Kanban/components/ColumnCard.tsx
@@ -29,6 +29,8 @@ type ColumnCardProps = {
items: Item[];
isOverlay?: boolean;
progressByItemId: Record<string, Progress>;
+ selectedGroup: string | null;
+ setSelectedGroup: (jobId: string | null) => void;
} & DisplaySettings;
export function ColumnCard({
@@ -36,6 +38,8 @@ export function ColumnCard({
items,
isOverlay,
progressByItemId,
+ selectedGroup,
+ setSelectedGroup,
...displaySettings
}: ColumnCardProps) {
const [params] = useUrlParams();
@@ -104,7 +108,16 @@ export function ColumnCard({
>
<CardHeader className="p-4 w-full font-semibold text-left flex flex-row space-between items-center sticky top-0 bg-card z-10 border-b">
<div className="flex flex-grow items-start space-x-2">
- {isActive && <PulsingDot />}
+ {isActive ? (
+ <PulsingDot />
+ ) : (
+ <div
+ className={cn(
+ "w-2 h-2 bg-muted rounded-full mt-2",
+ totalDuration > 0 && "bg-red-500"
+ )}
+ />
+ )}
<div className="flex flex-col flex-grow">
<span className="mr-auto truncate"> {column.title}</span>
{totalDuration > 0 ? (
@@ -138,8 +151,13 @@ export function ColumnCard({
status: progressByItemId[item.id]?.active
? "In Progress"
: item.status,
+ employeeIds: progressByItemId[item.id]?.employees
+ ? Array.from(progressByItemId[item.id].employees!)
+ : undefined,
progress: progressByItemId[item.id]?.progress ?? 0,
}}
+ selectedGroup={selectedGroup}
+ setSelectedGroup={setSelectedGroup}
{...displaySettings}
/>
))}
diff --git a/apps/carbon/app/modules/production/ui/Schedule/Kanban/components/ItemCard.tsx b/apps/carbon/app/modules/production/ui/Schedule/Kanban/components/ItemCard.tsx
index f9d691ca25..6394b05d24 100644
--- a/apps/carbon/app/modules/production/ui/Schedule/Kanban/components/ItemCard.tsx
+++ b/apps/carbon/app/modules/production/ui/Schedule/Kanban/components/ItemCard.tsx
@@ -24,8 +24,11 @@ import {
LuCheckCircle,
LuClipboardCheck,
LuExternalLink,
+ LuFlashlight,
+ LuFlashlightOff,
LuGripVertical,
LuTimer,
+ LuTrash,
LuUsers,
LuUserSquare,
LuXCircle,
@@ -38,6 +41,7 @@ import { InProgressStatusIcon } from "~/assets/icons/InProgressStatusIcon";
import { TodoStatusIcon } from "~/assets/icons/TodoStatusIcon";
import { CustomerAvatar, EmployeeAvatarGroup } from "~/components";
+import { FaTasks } from "react-icons/fa";
import { getPrivateUrl, path } from "~/utils/path";
import { getDeadlineIcon, getDeadlineText } from "../../../Jobs/Deadline";
import type { DisplaySettings, Item, ItemDragData } from "../types";
@@ -45,12 +49,18 @@ import type { DisplaySettings, Item, ItemDragData } from "../types";
type ItemCardProps = {
item: Item;
isOverlay?: boolean;
+ selectedGroup: string | null;
+ setSelectedGroup: (jobId: string | null) => void;
} & DisplaySettings;
const cardVariants = cva(
"dark:bg-gradient-to-tr dark:via-card dark:to-card dark:hover:to-muted/30 dark:hover:via-muted/30 bg-card hover:bg-muted/30",
{
variants: {
+ highlighted: {
+ true: "ring-2 ring-primary opacity-100",
+ false: "",
+ },
dragging: {
over: "ring-2 ring-primary opacity-30",
overlay:
@@ -61,9 +71,9 @@ const cardVariants = cva(
"border-emerald-600/30 dark:from-emerald-600/10 bg-emerald-600/5",
Ready: "",
Done: "",
- Paused: "border-yellow-500/30 dark:from-yellow-500/10 bg-yellow-500/5",
+ Paused: "",
Canceled: "border-red-500/30 dark:from-red-500/10 bg-red-500/5",
- Waiting: "border-yellow-500/30 dark:from-yellow-500/10 bg-yellow-500/5",
+ Waiting: "",
Todo: "border-border",
},
},
@@ -91,6 +101,7 @@ const cardHeaderVariants = cva("border-b", {
});
export function ItemCard({
+ selectedGroup,
item,
isOverlay,
showCustomer,
@@ -99,9 +110,11 @@ export function ItemCard({
showDuration,
showEmployee,
showProgress,
+ showQuantity,
showStatus,
showSalesOrder,
showThumbnail,
+ setSelectedGroup,
}: ItemCardProps) {
const {
setNodeRef,
@@ -121,6 +134,8 @@ export function ItemCard({
},
});
+ const isHighlighted = selectedGroup === item.title;
+
const style = {
transition,
transform: CSS.Translate.toString(transform),
@@ -140,6 +155,7 @@ export function ItemCard({
cardVariants({
dragging: isOverlay ? "overlay" : isDragging ? "over" : undefined,
status: item.status,
+ highlighted: isHighlighted,
})
)}
>
@@ -166,6 +182,14 @@ export function ItemCard({
</Link>
</div>
<HStack spacing={0} className="-mr-4">
+ <IconButton
+ aria-label="Highlight job"
+ icon={isHighlighted ? <LuFlashlightOff /> : <LuFlashlight />}
+ variant={"ghost"}
+ onClick={() =>
+ setSelectedGroup?.(isHighlighted ? null : item.title)
+ }
+ />
<IconButton
aria-label="Move item"
icon={<LuGripVertical />}
@@ -192,28 +216,45 @@ export function ItemCard({
Number.isFinite(item?.duration) &&
Number(item?.progress) >= 0 &&
Number(item?.duration) >= 0 && (
+ <HStack>
+ <Progress
+ indicatorClassName={
+ (item.progress ?? 0) > (item.duration ?? 0)
+ ? "bg-destructive"
+ : item.status === "Paused"
+ ? "bg-yellow-500"
+ : ""
+ }
+ numerator={
+ item.progress ? formatDurationMilliseconds(item.progress) : ""
+ }
+ denominator={
+ item.duration ? formatDurationMilliseconds(item.duration) : ""
+ }
+ value={Math.min(
+ item.progress && item.duration
+ ? (item.progress / item.duration) * 100
+ : 0,
+ 100
+ )}
+ />
+ <LuTimer className="text-muted-foreground w-4 h-4" />
+ </HStack>
+ )}
+ {showProgress && item.quantity && (
+ <HStack>
<Progress
- indicatorClassName={
- (item.progress ?? 0) > (item.duration ?? 0)
- ? "bg-destructive"
- : item.status === "Paused"
- ? "bg-yellow-500"
- : ""
- }
- numerator={
- item.progress ? formatDurationMilliseconds(item.progress) : ""
+ numerator={(item.quantityCompleted ?? 0).toString()}
+ denominator={(item.quantity ?? 0).toString()}
+ value={
+ item.quantityCompleted && item.quantity
+ ? (item.quantityCompleted / item.quantity) * 100
+ : 0
}
- denominator={
- item.duration ? formatDurationMilliseconds(item.duration) : ""
- }
- value={Math.min(
- item.progress && item.duration
- ? (item.progress / item.duration) * 100
- : 0,
- 100
- )}
/>
- )}
+ <FaTasks className="text-muted-foreground w-4 h-4" />
+ </HStack>
+ )}
</CardHeader>
<CardContent className="p-3 space-y-2 text-left whitespace-pre-wrap text-sm">
{showThumbnail && item.thumbnailPath && (
@@ -300,10 +341,19 @@ export function ItemCard({
</HStack>
)}
- {showEmployee && item.employeeIds && (
- <HStack className="justify-start space-x-2">
- <LuUsers className="text-muted-foreground" />
- <EmployeeAvatarGroup employeeIds={item.employeeIds} />
+ {showEmployee &&
+ Array.isArray(item.employeeIds) &&
+ item.employeeIds.length > 0 && (
+ <HStack className="justify-start space-x-2">
+ <LuUsers className="text-muted-foreground" />
+ <EmployeeAvatarGroup employeeIds={item.employeeIds} />
+ </HStack>
+ )}
+
+ {showQuantity && Number(item.quantityScrapped) > 0 && (
+ <HStack className="justify-start space-x-2 text-red-500">
+ <LuTrash className="w-4 h-4" />
+ <span className="text-sm">{item.quantityScrapped} Scrapped</span>
</HStack>
)}
</CardContent>
diff --git a/apps/carbon/app/modules/production/ui/Schedule/Kanban/types.ts b/apps/carbon/app/modules/production/ui/Schedule/Kanban/types.ts
index c8629e06eb..db5109a368 100644
--- a/apps/carbon/app/modules/production/ui/Schedule/Kanban/types.ts
+++ b/apps/carbon/app/modules/production/ui/Schedule/Kanban/types.ts
@@ -23,6 +23,7 @@ export type DisplaySettings = {
showDuration: boolean;
showEmployee: boolean;
showProgress: boolean;
+ showQuantity: boolean;
showStatus: boolean;
showSalesOrder: boolean;
showThumbnail: boolean;
@@ -32,7 +33,7 @@ export type DraggableData = ColumnDragData | ItemDragData;
export type Event = Pick<
ProductionEvent,
- "id" | "jobOperationId" | "duration" | "startTime" | "endTime"
+ "id" | "jobOperationId" | "duration" | "startTime" | "endTime" | "employeeId"
>;
const itemValidator = z.object({
@@ -50,6 +51,9 @@ const itemValidator = z.object({
duration: z.number().optional(), // miliseconds
deadlineType: z.enum(deadlineTypes).optional(),
progress: z.number().optional(), // miliseconds
+ quantity: z.number().optional(),
+ quantityCompleted: z.number().optional(),
+ quantityScrapped: z.number().optional(),
status: z.enum(jobOperationStatus).optional(),
salesOrderReadableId: z.string().optional(),
salesOrderId: z.string().optional(),
@@ -71,4 +75,5 @@ export type Progress = {
totalDuration: number;
progress: number;
active: boolean;
+ employees?: Set<string>;
};
diff --git a/apps/carbon/app/routes/x+/schedule+/index.tsx b/apps/carbon/app/routes/x+/schedule+/index.tsx
index 16fd0bbcb2..92cb092661 100644
--- a/apps/carbon/app/routes/x+/schedule+/index.tsx
+++ b/apps/carbon/app/routes/x+/schedule+/index.tsx
@@ -219,6 +219,9 @@ export async function loader({ request }: LoaderFunctionArgs) {
progress: 0, // set in the client
deadlineType: op.jobDeadlineType,
customerId: op.jobCustomerId,
+ quantity: op.operationQuantity,
+ quantityCompleted: op.quantityComplete,
+ quantityScrapped: op.quantityScrapped,
salesOrderReadableId: op.salesOrderReadableId,
salesOrderId: op.salesOrderId,
salesOrderLineId: op.salesOrderLineId,
@@ -248,6 +251,7 @@ const defaultDisplaySettings: DisplaySettings = {
showDueDate: true,
showEmployee: true,
showProgress: true,
+ showQuantity: true,
showStatus: true,
showSalesOrder: true,
showThumbnail: true,
@@ -280,7 +284,7 @@ function KanbanSchedule() {
setItems((prevItems) => sortItems(prevItems));
}, [sortItems]);
- const progressByOperation = useProgressByOperation(
+ const { progressByOperation } = useProgressByOperation(
items,
setItems,
sortItems
@@ -349,100 +353,30 @@ function KanbanSchedule() {
</PopoverTrigger>
<PopoverContent className="w-48">
<VStack>
- <Switch
- variant="small"
- label="Customer"
- checked={displaySettings.showCustomer}
- onCheckedChange={(checked) =>
- setDisplaySettings((prev) => ({
- ...prev,
- showCustomer: checked,
- }))
- }
- />
- <Switch
- variant="small"
- label="Description"
- checked={displaySettings.showDescription}
- onCheckedChange={(checked) =>
- setDisplaySettings((prev) => ({
- ...prev,
- showDescription: checked,
- }))
- }
- />
- <Switch
- variant="small"
- label="Due Date"
- checked={displaySettings.showDueDate}
- onCheckedChange={(checked) =>
- setDisplaySettings((prev) => ({
- ...prev,
- showDueDate: checked,
- }))
- }
- />
- <Switch
- variant="small"
- label="Duration"
- checked={displaySettings.showDuration}
- onCheckedChange={(checked) =>
- setDisplaySettings((prev) => ({
- ...prev,
- showDuration: checked,
- }))
- }
- />
- {/* <Switch
- variant="small"
- label="Employee"
- checked={displaySettings.showEmployee}
- onCheckedChange={(checked) => setDisplaySettings(prev => ({...prev, showEmployee: checked}))}
- /> */}
- <Switch
- variant="small"
- label="Progress"
- checked={displaySettings.showProgress}
- onCheckedChange={(checked) =>
- setDisplaySettings((prev) => ({
- ...prev,
- showProgress: checked,
- }))
- }
- />
- <Switch
- variant="small"
- label="Status"
- checked={displaySettings.showStatus}
- onCheckedChange={(checked) =>
- setDisplaySettings((prev) => ({
- ...prev,
- showStatus: checked,
- }))
- }
- />
- <Switch
- variant="small"
- label="Sales Order"
- checked={displaySettings.showSalesOrder}
- onCheckedChange={(checked) =>
- setDisplaySettings((prev) => ({
- ...prev,
- showSalesOrder: checked,
- }))
- }
- />
- <Switch
- variant="small"
- label="Thumbnail"
- checked={displaySettings.showThumbnail}
- onCheckedChange={(checked) =>
- setDisplaySettings((prev) => ({
- ...prev,
- showThumbnail: checked,
- }))
- }
- />
+ {[
+ { key: "showCustomer", label: "Customer" },
+ { key: "showDescription", label: "Description" },
+ { key: "showDueDate", label: "Due Date" },
+ { key: "showDuration", label: "Duration" },
+ { key: "showProgress", label: "Progress" },
+ { key: "showQuantity", label: "Quantity" },
+ { key: "showStatus", label: "Status" },
+ { key: "showSalesOrder", label: "Sales Order" },
+ { key: "showThumbnail", label: "Thumbnail" },
+ ].map(({ key, label }) => (
+ <Switch
+ key={key}
+ variant="small"
+ label={label}
+ checked={displaySettings[key as keyof typeof displaySettings]}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ [key]: checked,
+ }))
+ }
+ />
+ ))}
</VStack>
</PopoverContent>
</Popover>
@@ -529,7 +463,9 @@ function useProgressByOperation(
const { data, error } = await carbon
.from("productionEvent")
- .select("id, jobOperationId, duration, startTime, endTime, duration")
+ .select(
+ "id, jobOperationId, duration, startTime, endTime, duration, employeeId"
+ )
.eq("companyId", companyId)
.in("jobOperationId", operationIds);
@@ -570,11 +506,17 @@ function useProgressByOperation(
let currentProgress = 0;
let active = false;
+ let employees: Set<string> = new Set();
events.forEach((event) => {
if (event.endTime && event.duration) {
currentProgress += event.duration * 1000;
} else if (event.startTime) {
active = true;
+
+ if (event.employeeId) {
+ employees.add(event.employeeId);
+ }
+
const startTime = toZoned(
parseAbsolute(event.startTime, getLocalTimeZone()),
getLocalTimeZone()
@@ -591,20 +533,24 @@ function useProgressByOperation(
totalDuration,
progress: currentProgress,
active,
+ employees,
};
}
);
- return progress;
+ return { progress };
}, [productionEventsByOperation, items]);
useInterval(() => {
- setProgressByOperation(getProgress());
- }, 1000);
+ const { progress } = getProgress();
+
+ setProgressByOperation(progress);
+ }, 5000);
useEffect(() => {
if (Object.keys(productionEventsByOperation).length > 0) {
- setProgressByOperation(getProgress());
+ const { progress } = getProgress();
+ setProgressByOperation(progress);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [productionEventsByOperation]);
@@ -716,5 +662,5 @@ function useProgressByOperation(
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [accessToken]);
- return progressByOperation;
+ return { progressByOperation };
}
diff --git a/apps/mes/app/components/Kanban/components/ColumnCard.tsx b/apps/mes/app/components/Kanban/components/ColumnCard.tsx
index 873fe5438c..08e35dcf20 100644
--- a/apps/mes/app/components/Kanban/components/ColumnCard.tsx
+++ b/apps/mes/app/components/Kanban/components/ColumnCard.tsx
@@ -64,7 +64,7 @@ export function ColumnCard({
};
const variants = cva(
- "w-[350px] max-w-full bg-primary-foreground flex flex-col flex-shrink-0 snap-center rounded-none from-card/20 via-card/20",
+ "w-[350px] max-w-full flex flex-col flex-shrink-0 snap-center rounded-none from-card/20 via-card/20",
{
variants: {
dragging: {
@@ -91,7 +91,16 @@ export function ColumnCard({
>
<CardHeader 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 />}
+ {column.active ? (
+ <PulsingDot />
+ ) : (
+ <div
+ className={cn(
+ "w-2 h-2 bg-muted rounded-full mt-2",
+ totalDuration > 0 && "bg-red-500"
+ )}
+ />
+ )}
<div className="flex flex-col flex-grow">
<span className="mr-auto truncate"> {column.title}</span>
{totalDuration > 0 ? (
diff --git a/apps/mes/app/routes/x+/operations.tsx b/apps/mes/app/routes/x+/operations.tsx
index aabdf12ec7..22a9c463d6 100644
--- a/apps/mes/app/routes/x+/operations.tsx
+++ b/apps/mes/app/routes/x+/operations.tsx
@@ -210,7 +210,7 @@ export default function ScheduleRoute() {
return (
<ClientOnly
fallback={
- <div className="flex h-screen w-full items-center justify-center">
+ <div className="flex h-screen w-[calc(100dvw-var(--sidebar-width))] items-center justify-center">
<Spinner className="h-8 w-8" />
</div>
}
@@ -279,7 +279,7 @@ function KanbanSchedule() {
}, [processes, workCenters]);
return (
- <div className="flex flex-col h-full w-full">
+ <div className="flex flex-col h-screen w-full">
<header className="sticky top-0 z-10 flex h-[var(--header-height)] shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12 border-b bg-background">
<div className="flex items-center gap-2 px-2">
<SidebarTrigger />
@@ -411,7 +411,7 @@ function KanbanSchedule() {
</HStack>
)}
<div className="flex flex-grow h-full items-stretch overflow-hidden relative">
- <div className="flex flex-1 min-h-0 w-full relative">
+ <div className="flex flex-1 min-h-full w-full relative">
{columns.length > 0 ? (
<Kanban
columns={columns}