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.

fix(documents): keep job traveler BOM header attached to first row across page breaks (#1273)

Brad Barbina706d1f9897a
diff --git a/packages/documents/src/pdf/blocks/jobTraveler/MaterialsBlock.tsx b/packages/documents/src/pdf/blocks/jobTraveler/MaterialsBlock.tsx
index d2f746717c..35656d3f4c 100644
--- a/packages/documents/src/pdf/blocks/jobTraveler/MaterialsBlock.tsx
+++ b/packages/documents/src/pdf/blocks/jobTraveler/MaterialsBlock.tsx
@@ -2,49 +2,82 @@ import { Text, View } from "@react-pdf/renderer";
import { tw } from "./tw";
import type { JobTravelerData } from "./types";
+// Shared column widths so the header and body rows can never drift out of
+// alignment. They sum to 12/12; spacing between columns comes from in-cell
+// right padding (pr-4) rather than a flex gap, which previously pushed the
+// total width past 100% and made long item ids overlap the description.
+const COL_ITEM = "w-5/12 text-left pr-4";
+const COL_DESCRIPTION = "w-5/12 text-left pr-4";
+const COL_QUANTITY = "w-2/12 text-right";
+
/**
- * Opt-in Bill of Materials table (item, description, method type, quantity).
+ * Opt-in Bill of Materials table (item, description, quantity).
* Rendered only when the company setting `includeMaterialsOnTraveler` is on and
* the make method has materials — see JobTravelerPageContent.
+ *
+ * Page breaks: each row is unbreakable (`wrap={false}`), and the table header is
+ * bound to the first row so it can never be orphaned at the bottom of a page.
+ * Remaining rows flow naturally, so a long BOM still expands across pages.
*/
export function MaterialsBlock({ data }: { data: JobTravelerData }) {
const materials = data.materials ?? [];
if (materials.length === 0) return null;
+ const header = (
+ <View
+ style={tw(
+ "flex flex-row justify-between items-center py-3 px-[6px] border-t border-b border-gray-300 font-bold uppercase"
+ )}
+ >
+ <Text style={tw(COL_ITEM)}>Item</Text>
+ <Text style={tw(COL_DESCRIPTION)}>Description</Text>
+ <Text style={tw(COL_QUANTITY)}>Quantity</Text>
+ </View>
+ );
+
return (
<View style={tw("mb-6 text-xs")}>
- <View
- style={tw(
- "flex flex-row justify-between items-center py-3 px-[6px] border-t border-b border-gray-300 font-bold uppercase page-break-inside-avoid gap-x-6"
- )}
- >
- <Text style={tw("w-3/12 text-left")}>Item</Text>
- <Text style={tw("w-5/12 text-left")}>Description</Text>
- <Text style={tw("w-2/12 text-left")}>Method</Text>
- <Text style={tw("w-2/12 text-right")}>Quantity</Text>
- </View>
+ {materials.map((material, index) => {
+ const cells = (
+ <>
+ <Text style={tw(`${COL_ITEM} font-bold`)}>
+ {material.itemReadableId ?? ""}
+ </Text>
+ <Text style={tw(COL_DESCRIPTION)}>{material.description}</Text>
+ <Text style={tw(COL_QUANTITY)}>
+ {material.quantity}
+ {material.unitOfMeasureCode
+ ? ` ${material.unitOfMeasureCode}`
+ : ""}
+ </Text>
+ </>
+ );
+
+ const row = (
+ <View
+ style={tw(
+ "flex flex-row justify-between items-start border-b border-gray-300 py-3 px-[6px]"
+ )}
+ wrap={false}
+ >
+ {cells}
+ </View>
+ );
+
+ // Keep the header attached to the first row so it never lands alone at
+ // the bottom of a page. `minPresenceAhead` pushes the pair to the next
+ // page when there isn't room for it plus a little of the table.
+ if (index === 0) {
+ return (
+ <View key={material.id} wrap={false} minPresenceAhead={80}>
+ {header}
+ {row}
+ </View>
+ );
+ }
- {materials.map((material) => (
- <View
- style={tw(
- "flex flex-row justify-between items-start border-b border-gray-300 py-3 px-[6px] page-break-inside-avoid gap-x-6"
- )}
- key={material.id}
- wrap={false}
- >
- <Text style={tw("w-3/12 text-left font-bold")}>
- {material.itemReadableId ?? ""}
- </Text>
- <Text style={tw("w-5/12 text-left")}>{material.description}</Text>
- <Text style={tw("w-2/12 text-left text-[10px]")}>
- {material.methodType ?? ""}
- </Text>
- <Text style={tw("w-2/12 text-right")}>
- {material.quantity}
- {material.unitOfMeasureCode ? ` ${material.unitOfMeasureCode}` : ""}
- </Text>
- </View>
- ))}
+ return <View key={material.id}>{row}</View>;
+ })}
</View>
);
}