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: used in panel in item master

Brad Barbin706724f3a45d
diff --git a/apps/erp/app/components/Hyperlink.tsx b/apps/erp/app/components/Hyperlink.tsx
index 19f1d126ee..943c6593aa 100644
--- a/apps/erp/app/components/Hyperlink.tsx
+++ b/apps/erp/app/components/Hyperlink.tsx
@@ -21,14 +21,16 @@ const Hyperlink = ({
{...props}
>
<span className="flex flex-row items-center gap-1">{children}</span>
- <Button
- leftIcon={<LuSquareArrowOutUpRight />}
- variant="secondary"
- className="flex-shrink-0 opacity-0 transition-opacity duration-200 group-hover/hyperlink:opacity-100 no-underline"
- size="sm"
- >
- Open
- </Button>
+ {props.to && props.to !== "#" && (
+ <Button
+ leftIcon={<LuSquareArrowOutUpRight />}
+ variant="secondary"
+ className="flex-shrink-0 opacity-0 transition-opacity duration-200 group-hover/hyperlink:opacity-100 no-underline"
+ size="sm"
+ >
+ Open
+ </Button>
+ )}
</Link>
) : (
<span className={cn("text-foreground", className)} {...props}>
diff --git a/apps/erp/app/components/TreeView/TreeView.tsx b/apps/erp/app/components/TreeView/TreeView.tsx
index ac32c2416e..fffc773ec2 100644
--- a/apps/erp/app/components/TreeView/TreeView.tsx
+++ b/apps/erp/app/components/TreeView/TreeView.tsx
@@ -622,16 +622,19 @@ export function createTreeFromFlatItems<TData>(
export function LevelLine({
isError = false,
isSelected,
+ className,
}: {
isError?: boolean;
isSelected: boolean;
+ className?: string;
}) {
return (
<div
className={cn(
"h-8 w-3 border-r border-border",
isError && "border-destructive",
- isSelected && "border-foreground/60"
+ isSelected && "border-foreground/60",
+ className
)}
/>
);
diff --git a/apps/erp/app/modules/inventory/ui/Receipts/ReceiptLines.tsx b/apps/erp/app/modules/inventory/ui/Receipts/ReceiptLines.tsx
index 991dbec6e9..4ecfae2e7f 100644
--- a/apps/erp/app/modules/inventory/ui/Receipts/ReceiptLines.tsx
+++ b/apps/erp/app/modules/inventory/ui/Receipts/ReceiptLines.tsx
@@ -96,20 +96,18 @@ const ReceiptLines = () => {
return receiptLines.reduce(
(acc, line) => ({
...acc,
- [line.id]: Array(line.receivedQuantity)
- .fill(null)
- .map((_, index) => {
- const serialNumber = routeData?.receiptLineTracking.find(
- (t) =>
- t.receiptLineId === line.id &&
- t.serialNumber !== null &&
- t.index === index
- )?.serialNumber;
- return {
- index,
- number: serialNumber?.number ?? "",
- };
- }),
+ [line.id]: Array.from({ length: line.receivedQuantity }, (_, index) => {
+ const serialNumber = routeData?.receiptLineTracking.find(
+ (t) =>
+ t.receiptLineId === line.id &&
+ t.serialNumber !== null &&
+ t.index === index
+ )?.serialNumber;
+ return {
+ index,
+ number: serialNumber?.number ?? "",
+ };
+ }),
}),
{}
);
@@ -120,9 +118,9 @@ const ReceiptLines = () => {
receiptLines.reduce(
(acc, line) => ({
...acc,
- [line.id]: Array(line.receivedQuantity)
- .fill(null)
- .map((_, index) => {
+ [line.id]: Array.from(
+ { length: line.receivedQuantity },
+ (_, index) => {
const serialNumber = routeData?.receiptLineTracking.find(
(t) =>
t.receiptLineId === line.id &&
@@ -133,7 +131,8 @@ const ReceiptLines = () => {
index,
number: serialNumber?.number ?? "",
};
- }),
+ }
+ ),
}),
{}
)
@@ -322,7 +321,13 @@ function ReceiptLineItem({
if (value > serialNumbers.length) {
onSerialNumbersChange([
...serialNumbers,
- ...Array(value - serialNumbers.length).fill(""),
+ ...Array.from(
+ { length: value - serialNumbers.length },
+ () => ({
+ index: serialNumbers.length,
+ number: "",
+ })
+ ),
]);
} else if (value < serialNumbers.length) {
onSerialNumbersChange(serialNumbers.slice(0, value));
diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.ts
index d7283f684f..3e5e0d4af6 100644
--- a/apps/erp/app/modules/items/items.service.ts
+++ b/apps/erp/app/modules/items/items.service.ts
@@ -425,29 +425,29 @@ export async function getItemPlanning(
.maybeSingle();
}
-export async function getItemReplenishment(
+export async function getItemQuantities(
client: SupabaseClient<Database>,
itemId: string,
- companyId: string
+ companyId: string,
+ locationId: string
) {
return client
- .from("itemReplenishment")
- .select("*")
+ .rpc("get_item_quantities", { location_id: locationId })
.eq("itemId", itemId)
- .eq("companyId", companyId)
- .single();
+ .maybeSingle();
}
-export async function getItemQuantities(
+export async function getItemReplenishment(
client: SupabaseClient<Database>,
itemId: string,
- companyId: string,
- locationId: string
+ companyId: string
) {
return client
- .rpc("get_item_quantities", { location_id: locationId })
+ .from("itemReplenishment")
+ .select("*")
.eq("itemId", itemId)
- .maybeSingle();
+ .eq("companyId", companyId)
+ .single();
}
export async function getItemShelfQuantities(
@@ -477,6 +477,139 @@ export async function getItemUnitSalePrice(
.single();
}
+export async function getMaterialUsedIn(
+ client: SupabaseClient<Database>,
+ itemId: string,
+ companyId: string
+) {
+ const [
+ jobMaterials,
+ methodMaterials,
+ purchaseOrderLines,
+ receiptLines,
+ quoteMaterials,
+ ] = await Promise.all([
+ client
+ .from("jobMaterial")
+ .select("id, methodType, ...job(documentReadableId:jobId, documentId:id)")
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("methodMaterial")
+ .select(
+ "id, methodType, ...makeMethod!makeMethodId(...item(documentReadableId:readableId, documentId:id, itemType:type))"
+ )
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("purchaseOrderLine")
+ .select(
+ "id, ...purchaseOrder(documentReadableId:purchaseOrderId, documentId:id)"
+ )
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("receiptLine")
+ .select("id, ...receipt(documentReadableId:receiptId, documentId:id)")
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("quoteMaterial")
+ .select(
+ "id, methodType, documentParentId:quoteId, documentId:quoteLineId, ...quoteLine(documentReadableId:itemReadableId)"
+ )
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ ]);
+
+ return {
+ jobMaterials: jobMaterials.data ?? [],
+ methodMaterials: methodMaterials.data ?? [],
+ purchaseOrderLines: purchaseOrderLines.data ?? [],
+ receiptLines: receiptLines.data ?? [],
+ quoteMaterials: quoteMaterials.data ?? [],
+ };
+}
+
+export async function getPartUsedIn(
+ client: SupabaseClient<Database>,
+ itemId: string,
+ companyId: string
+) {
+ const [
+ jobMaterials,
+ jobs,
+ methodMaterials,
+ purchaseOrderLines,
+ receiptLines,
+ quoteLines,
+ quoteMaterials,
+ salesOrderLines,
+ ] = await Promise.all([
+ client
+ .from("jobMaterial")
+ .select("id, methodType, ...job(documentReadableId:jobId, documentId:id)")
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("job")
+ .select("id, documentReadableId:jobId")
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("methodMaterial")
+ .select(
+ "id, methodType, ...makeMethod!makeMethodId(...item(documentReadableId:readableId, documentId:id, itemType:type))"
+ )
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("purchaseOrderLine")
+ .select(
+ "id, ...purchaseOrder(documentReadableId:purchaseOrderId, documentId:id)"
+ )
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("receiptLine")
+ .select("id, ...receipt(documentReadableId:receiptId, documentId:id)")
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("quoteLine")
+ .select(
+ "id, methodType, ...quote(documentReadableId:quoteId, documentId:id)"
+ )
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("quoteMaterial")
+ .select(
+ "id, methodType, documentParentId:quoteId, documentId:quoteLineId, ...quoteLine(documentReadableId:itemReadableId)"
+ )
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ client
+ .from("salesOrderLine")
+ .select(
+ "id, methodType, ...salesOrder(documentReadableId:salesOrderId, documentId:id)"
+ )
+ .eq("itemId", itemId)
+ .eq("companyId", companyId),
+ ]);
+
+ return {
+ jobMaterials: jobMaterials.data ?? [],
+ jobs: jobs.data ?? [],
+ methodMaterials: methodMaterials.data ?? [],
+ purchaseOrderLines: purchaseOrderLines.data ?? [],
+ receiptLines: receiptLines.data ?? [],
+ quoteLines: quoteLines.data ?? [],
+ quoteMaterials: quoteMaterials.data ?? [],
+ salesOrderLines: salesOrderLines.data ?? [],
+ };
+}
+
export async function getMakeMethod(
client: SupabaseClient<Database>,
itemId: string,
diff --git a/apps/erp/app/modules/items/ui/Item/ItemForm.tsx b/apps/erp/app/modules/items/ui/Item/ItemForm.tsx
index 01f89c4adc..a825525829 100644
--- a/apps/erp/app/modules/items/ui/Item/ItemForm.tsx
+++ b/apps/erp/app/modules/items/ui/Item/ItemForm.tsx
@@ -100,11 +100,11 @@ const ItemForm = ({ initialValues, type }: ItemFormProps) => {
>
<HStack className="w-full justify-between">
<CardHeader>
- <CardTitle className="flex items-center gap-2">
+ <CardTitle className="line-clamp-2">{initialValues.name}</CardTitle>
+ <CardDescription className="flex items-center gap-2">
{initialValues.readableId}
<Copy text={initialValues.readableId ?? ""} />
- </CardTitle>
- <CardDescription>{initialValues.name}</CardDescription>
+ </CardDescription>
</CardHeader>
<CardAction>
<DropdownMenu>
diff --git a/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx b/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx
index f76c91d019..0839206bc0 100644
--- a/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx
+++ b/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx
@@ -31,7 +31,7 @@ import { usePermissions } from "~/hooks";
import type { MethodItemType } from "~/modules/shared";
import { path } from "~/utils/path";
import { getMethodValidator } from "../../items.models";
-import { getLinkToItemManufacturing } from "./ItemForm";
+import { getLinkToItemDetails } from "./ItemForm";
type MakeMethodToolsProps = {
itemId: string;
@@ -58,8 +58,7 @@ const MakeMethodTools = ({ itemId, type }: MakeMethodToolsProps) => {
const getMethodModal = useDisclosure();
const saveMethodModal = useDisclosure();
- const itemLink =
- type && itemId ? getLinkToItemManufacturing(type, itemId) : null;
+ const itemLink = type && itemId ? getLinkToItemDetails(type, itemId) : null;
return (
<>
diff --git a/apps/erp/app/modules/items/ui/Item/UsedIn.tsx b/apps/erp/app/modules/items/ui/Item/UsedIn.tsx
new file mode 100644
index 0000000000..b988604155
--- /dev/null
+++ b/apps/erp/app/modules/items/ui/Item/UsedIn.tsx
@@ -0,0 +1,198 @@
+import {
+ Skeleton,
+ VStack,
+ HStack,
+ Input,
+ InputGroup,
+ InputLeftElement,
+ cn,
+ Count,
+} from "@carbon/react";
+import { useState } from "react";
+import { LuSearch, LuChevronRight } from "react-icons/lu";
+import { MethodIcon, Hyperlink } from "~/components";
+import { LevelLine } from "~/components/TreeView";
+import { usePermissions } from "~/hooks";
+import { MethodItemType } from "~/modules/shared";
+import { path } from "~/utils/path";
+import { getLinkToItemManufacturing } from "./ItemForm";
+
+export function UsedInSkeleton() {
+ return (
+ <div className="flex flex-col gap-1 w-full">
+ <Skeleton className="h-7 w-full" />
+ <Skeleton className="h-7 w-full" />
+ <Skeleton className="h-7 w-3/4" />
+ <Skeleton className="h-7 w-1/2" />
+ </div>
+ );
+}
+
+export type UsedInKey =
+ | "jobMaterials"
+ | "jobs"
+ | "methodMaterials"
+ | "purchaseOrderLines"
+ | "receiptLines"
+ | "quoteLines"
+ | "quoteMaterials"
+ | "salesOrderLines";
+
+export type UsedInNode = {
+ key: UsedInKey;
+ name: string;
+ module: string;
+ children: {
+ id: string;
+ documentReadableId: string;
+ documentId?: string;
+ documentParentId?: string;
+ itemType?: MethodItemType;
+ methodType?: string;
+ }[];
+};
+
+export function UsedInTree({
+ tree,
+ itemReadableId,
+}: {
+ tree: UsedInNode[];
+ itemReadableId: string;
+}) {
+ const [filterText, setFilterText] = useState("");
+
+ return (
+ <VStack>
+ <HStack className="w-full py">
+ <InputGroup size="sm" className="flex flex-grow">
+ <InputLeftElement>
+ <LuSearch className="h-4 w-4" />
+ </InputLeftElement>
+ <Input
+ placeholder="Search..."
+ value={filterText}
+ onChange={(e) => setFilterText(e.target.value)}
+ />
+ </InputGroup>
+ </HStack>
+ <VStack spacing={0}>
+ {tree.map((node) => (
+ <UsedInItem
+ key={node.key}
+ filterText={filterText}
+ node={node}
+ itemReadableId={itemReadableId}
+ />
+ ))}
+ </VStack>
+ </VStack>
+ );
+}
+
+export function UsedInItem({
+ node,
+ itemReadableId,
+ filterText,
+}: {
+ node: UsedInNode;
+ itemReadableId: string;
+ filterText: string;
+}) {
+ const [isExpanded, setIsExpanded] = useState(
+ node.children.length > 0 && node.children.length < 10
+ );
+ const permissions = usePermissions();
+
+ if (!permissions.can("view", node.module)) {
+ return null;
+ }
+
+ const filteredChildren = node.children.filter((child) =>
+ child.documentReadableId.toLowerCase().includes(filterText.toLowerCase())
+ );
+
+ return (
+ <>
+ <button
+ className="flex h-8 cursor-pointer items-center overflow-hidden rounded-sm px-2 gap-2 text-sm hover:bg-muted/90 w-full font-medium"
+ onClick={(e) => {
+ e.stopPropagation();
+ setIsExpanded(!isExpanded);
+ }}
+ >
+ <div className="h-8 w-4 flex items-center justify-center">
+ <LuChevronRight className={cn("size-4", isExpanded && "rotate-90")} />
+ </div>
+ <div className="flex flex-grow items-center justify-between gap-2">
+ <span>{node.name}</span>
+ {filteredChildren.length > 0 && (
+ <Count count={filteredChildren.length} />
+ )}
+ </div>
+ </button>
+ {isExpanded && (
+ <div className="flex flex-col w-full">
+ {node.children.length === 0 ? (
+ <div className="flex h-8 items-center overflow-hidden rounded-sm px-2 gap-4">
+ <LevelLine isSelected={false} />
+ <div className="text-xs text-muted-foreground">
+ No {node.name.toLowerCase()} found
+ </div>
+ </div>
+ ) : (
+ filteredChildren.map((child, index) => (
+ <Hyperlink
+ key={index}
+ to={getUseInLink(child, node.key, itemReadableId)}
+ className="flex h-8 cursor-pointer items-center overflow-hidden rounded-sm px-1 gap-4 text-sm hover:bg-muted/90 w-full font-medium"
+ >
+ <LevelLine isSelected={false} className="mr-2" />
+ <MethodIcon
+ type={child.methodType ?? "Method"}
+ className="mr-2"
+ />
+ {child.documentReadableId}
+ </Hyperlink>
+ ))
+ )}
+ </div>
+ )}
+ </>
+ );
+}
+
+function getUseInLink(
+ child: UsedInNode["children"][number],
+ key: UsedInKey,
+ itemReadableId: string
+) {
+ switch (key) {
+ case "jobs":
+ return path.to.job(child.id);
+ case "jobMaterials":
+ if (!child.documentId) return "#";
+ return `${path.to.jobMaterials(
+ child.documentId
+ )}?filter=itemReadableId:eq:${itemReadableId}`;
+ case "methodMaterials":
+ if (!child.documentId || !child.itemType) return "#";
+ return getLinkToItemManufacturing(child.itemType, child.documentId);
+ case "purchaseOrderLines":
+ if (!child.documentId) return "#";
+ return path.to.purchaseOrder(child.documentId);
+ case "receiptLines":
+ if (!child.documentId) return "#";
+ return path.to.receipt(child.documentId);
+ case "quoteLines":
+ if (!child.documentId) return "#";
+ return path.to.quote(child.documentId);
+ case "quoteMaterials":
+ if (!child.documentId || !child.documentParentId) return "#";
+ return path.to.quoteLine(child.documentParentId, child.documentId);
+ case "salesOrderLines":
+ if (!child.documentId) return "#";
+ return path.to.salesOrder(child.documentId);
+ default:
+ return "#";
+ }
+}
diff --git a/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx b/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx
index fe9cbe3099..b8cc75720c 100644
--- a/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx
@@ -28,7 +28,6 @@ import {
import { z } from "zod";
import { zfd } from "zod-form-data";
import { MethodBadge, MethodIcon, TrackingTypeIcon } from "~/components";
-import { Enumerable } from "~/components/Enumerable";
import { Boolean, Tags, UnitOfMeasure } from "~/components/Form";
import CustomFormInlineFields from "~/components/Form/CustomFormInlineFields";
import { ItemThumbnailUpload } from "~/components/ItemThumnailUpload";
@@ -50,6 +49,7 @@ import type {
SupplierPart,
} from "../../types";
import { FileBadge } from "../Item";
+import { ReplenishmentSystemIcon } from "~/components/Icons";
const PartProperties = () => {
const { itemId } = useParams();
@@ -330,9 +330,13 @@ const PartProperties = () => {
<h3 className="text-xs text-muted-foreground">Replenishment</h3>
<DropdownMenu>
<DropdownMenuTrigger>
- <Enumerable
- value={routeData?.partSummary?.replenishmentSystem ?? null}
- />
+ <Badge variant="secondary">
+ <ReplenishmentSystemIcon
+ type={routeData?.partSummary?.replenishmentSystem!}
+ className="mr-2"
+ />
+ <span>{routeData?.partSummary?.replenishmentSystem!}</span>
+ </Badge>
</DropdownMenuTrigger>
<DropdownMenuContent>
{itemReplenishmentSystems.map((system) => (
@@ -340,7 +344,10 @@ const PartProperties = () => {
key={system}
onClick={() => onUpdate("replenishmentSystem", system)}
>
- <Enumerable value={system} />
+ <DropdownMenuIcon
+ icon={<ReplenishmentSystemIcon type={system} />}
+ />
+ <span>{system}</span>
</DropdownMenuItem>
))}
</DropdownMenuContent>
diff --git a/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx b/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
index 01cea5674e..514d7fb68a 100644
--- a/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
@@ -39,6 +39,7 @@ import {
} from "../../items.models";
import type { ItemFile, PickMethod, SupplierPart, Tool } from "../../types";
import { FileBadge } from "../Item";
+import { ReplenishmentSystemIcon } from "~/components/Icons";
const ToolProperties = () => {
const { itemId } = useParams();
@@ -308,9 +309,13 @@ const ToolProperties = () => {
<h3 className="text-xs text-muted-foreground">Replenishment</h3>
<DropdownMenu>
<DropdownMenuTrigger>
- <Enumerable
- value={routeData?.toolSummary?.replenishmentSystem ?? null}
- />
+ <Badge variant="secondary">
+ <ReplenishmentSystemIcon
+ type={routeData?.toolSummary?.replenishmentSystem!}
+ className="mr-2"
+ />
+ <span>{routeData?.toolSummary?.replenishmentSystem!}</span>
+ </Badge>
</DropdownMenuTrigger>
<DropdownMenuContent>
{itemReplenishmentSystems.map((system) => (
@@ -318,7 +323,10 @@ const ToolProperties = () => {
key={system}
onClick={() => onUpdate("replenishmentSystem", system)}
>
- <Enumerable value={system} />
+ <DropdownMenuIcon
+ icon={<ReplenishmentSystemIcon type={system} />}
+ />
+ <span>{system}</span>
</DropdownMenuItem>
))}
</DropdownMenuContent>
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
index ad13aa8031..506c44494a 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
@@ -55,7 +55,7 @@ import type {
ConfigurationParameter,
ConfigurationParameterGroup,
} from "~/modules/items";
-import { getLinkToItemManufacturing } from "~/modules/items/ui/Item/ItemForm";
+import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";
import type { MethodItemType } from "~/modules/shared/types";
import { path } from "~/utils/path";
import { getJobMethodValidator } from "../../production.models";
@@ -86,7 +86,7 @@ const JobBreadcrumbs = () => {
const itemLink =
itemType && itemId
- ? getLinkToItemManufacturing(itemType as MethodItemType, itemId)
+ ? getLinkToItemDetails(itemType as MethodItemType, itemId)
: null;
const isDisabled = ["Completed", "Cancelled", "In Progress"].includes(
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMaterialForm.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMaterialForm.tsx
index 9573443e8d..77cb263065 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobMaterialForm.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobMaterialForm.tsx
@@ -1,6 +1,7 @@
import {
Card,
CardContent,
+ CardDescription,
CardFooter,
CardHeader,
CardTitle,
@@ -186,9 +187,10 @@ const JobMaterialForm = ({
validator={jobMaterialValidator}
>
<CardHeader>
- <CardTitle className="flex items-center gap-2">
+ <CardTitle className="line-clamp-2">{itemData.description}</CardTitle>
+ <CardDescription className="flex items-center gap-2">
{itemData.itemReadableId} <Copy text={itemData.itemReadableId} />
- </CardTitle>
+ </CardDescription>
</CardHeader>
<CardContent>
<Hidden name="jobMakeMethodId" />
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx
index f8d96e13cc..bc99991a41 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx
@@ -41,6 +41,7 @@ import { usePermissions, useRouteData, useUser } from "~/hooks";
import { methodType } from "~/modules/shared";
import { path } from "~/utils/path";
import type { Job, JobMaterial } from "../../types";
+import { useParts } from "~/stores";
type JobMaterialsTableProps = {
data: JobMaterial[];
@@ -57,12 +58,13 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {
const fetcher = useFetcher<{}>();
const unitsOfMeasure = useUnitOfMeasure();
const locations = useLocations();
+ const parts = useParts();
const columns = useMemo<ColumnDef<JobMaterial>[]>(() => {
return [
{
- accessorKey: "readableId",
- header: "Item ID",
+ accessorKey: "itemReadableId",
+ header: "Item",
cell: ({ row }) => (
<HStack className="py-1">
<ItemThumbnail
@@ -91,6 +93,13 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {
),
meta: {
icon: <LuBookMarked />,
+ filter: {
+ type: "static",
+ options: parts.map((part) => ({
+ value: part.readableId,
+ label: part.readableId,
+ })),
+ },
},
},
{
@@ -229,7 +238,7 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {
},
},
];
- }, [jobId, locations, routeData?.job.locationId, unitsOfMeasure]);
+ }, [jobId, locations, parts, routeData?.job.locationId, unitsOfMeasure]);
const permissions = usePermissions();
const { carbon } = useCarbon();
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
index 4d7182a8dc..07d7fd7ad2 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
@@ -43,7 +43,7 @@ import type {
ConfigurationParameter,
ConfigurationParameterGroup,
} from "~/modules/items";
-import { getLinkToItemManufacturing } from "~/modules/items/ui/Item/ItemForm";
+import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";
import type { MethodItemType } from "~/modules/shared/types";
import { path } from "~/utils/path";
import { getLineMethodValidator, getMethodValidator } from "../../sales.models";
@@ -74,7 +74,7 @@ const QuoteMakeMethodTools = () => {
const itemLink =
itemType && itemId
- ? getLinkToItemManufacturing(itemType as MethodItemType, itemId)
+ ? getLinkToItemDetails(itemType as MethodItemType, itemId)
: null;
const lineData = useRouteData<{
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
index 406a1751e8..4f239b995b 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
@@ -1,6 +1,7 @@
import {
Card,
CardContent,
+ CardDescription,
CardFooter,
CardHeader,
CardTitle,
@@ -179,9 +180,10 @@ const QuoteMaterialForm = ({
validator={quoteMaterialValidator}
>
<CardHeader>
- <CardTitle className="flex items-center gap-2">
+ <CardTitle className="line-clamp-2">{itemData.description}</CardTitle>
+ <CardDescription className="flex items-center gap-2">
{itemData.itemReadableId} <Copy text={itemData.itemReadableId} />
- </CardTitle>
+ </CardDescription>
</CardHeader>
<CardContent>
<Hidden name="quoteMakeMethodId" />
diff --git a/apps/erp/app/routes/x+/consumable+/$itemId.details.tsx b/apps/erp/app/routes/x+/consumable+/$itemId.details.tsx
index 1ab9f42e2a..4a1dd1f596 100644
--- a/apps/erp/app/routes/x+/consumable+/$itemId.details.tsx
+++ b/apps/erp/app/routes/x+/consumable+/$itemId.details.tsx
@@ -3,19 +3,47 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import type { JSONContent } from "@carbon/react";
-import { Spinner, VStack } from "@carbon/react";
-import { Await, useParams } from "@remix-run/react";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
+import {
+ Spinner,
+ VStack,
+ ScrollArea,
+ ResizablePanel,
+ ResizablePanelGroup,
+ ResizableHandle,
+} from "@carbon/react";
+import { Await, useLoaderData, useParams } from "@remix-run/react";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { redirect, defer } from "@vercel/remix";
import { Suspense } from "react";
import { usePermissions, useRouteData } from "~/hooks";
import type { Consumable, ItemFile } from "~/modules/items";
-import { consumableValidator, upsertConsumable } from "~/modules/items";
+import {
+ getMaterialUsedIn,
+ consumableValidator,
+ upsertConsumable,
+} from "~/modules/items";
import { ItemDocuments, ItemNotes } from "~/modules/items/ui/Item";
+import {
+ UsedInSkeleton,
+ UsedInItem,
+ UsedInTree,
+} from "~/modules/items/ui/Item/UsedIn";
import { setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "parts",
+ bypassRls: true,
+ });
+
+ const { itemId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+
+ return defer({ usedIn: getMaterialUsedIn(client, itemId, companyId) });
+}
+
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
@@ -55,6 +83,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function ConsumableDetailsRoute() {
+ const { usedIn } = useLoaderData<typeof loader>();
const permissions = usePermissions();
const { itemId } = useParams();
@@ -67,32 +96,117 @@ export default function ConsumableDetailsRoute() {
if (!consumableData) throw new Error("Could not find consumable data");
return (
- <VStack spacing={2} className="w-full h-full p-2">
- <ItemNotes
- id={consumableData.consumableSummary?.itemId ?? null}
- title={consumableData.consumableSummary?.id ?? ""}
- subTitle={consumableData.consumableSummary?.name ?? ""}
- notes={consumableData.consumableSummary?.notes as JSONContent}
- />
- {permissions.is("employee") && (
- <Suspense
- fallback={
- <div className="flex w-full h-[full] rounded bg-gradient-to-tr from-background to-card items-center justify-center">
- <Spinner className="h-10 w-10" />
- </div>
- }
+ <div className="flex flex-grow overflow-hidden">
+ <ResizablePanelGroup direction="horizontal">
+ <ResizablePanel
+ order={1}
+ minSize={10}
+ defaultSize={20}
+ className="bg-card"
>
- <Await resolve={consumableData?.files}>
- {(files) => (
- <ItemDocuments
- files={files ?? []}
- itemId={itemId}
- type="Consumable"
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <div className="grid h-full overflow-hidden p-2">
+ <Suspense fallback={<UsedInSkeleton />}>
+ <Await resolve={usedIn}>
+ {(resolvedUsedIn) => {
+ const {
+ jobMaterials,
+ methodMaterials,
+ purchaseOrderLines,
+ receiptLines,
+ quoteMaterials,
+ } = resolvedUsedIn;
+
+ const tree: UsedInItem[] = [
+ {
+ key: "jobMaterials",
+ name: "Job Materials",
+ module: "production",
+ children: jobMaterials,
+ },
+ {
+ key: "methodMaterials",
+ name: "Method Materials",
+ module: "parts",
+ // @ts-expect-error
+ children: methodMaterials,
+ },
+ {
+ key: "purchaseOrderLines",
+ name: "Purchase Orders",
+ module: "purchasing",
+ children: purchaseOrderLines.map((po) => ({
+ ...po,
+ methodType: "Buy",
+ })),
+ },
+ {
+ key: "receiptLines",
+ name: "Receipts",
+ module: "inventory",
+ children: receiptLines.map((receipt) => ({
+ ...receipt,
+ methodType: "Pick",
+ })),
+ },
+ {
+ key: "quoteMaterials",
+ name: "Quote Materials",
+ module: "sales",
+ children: quoteMaterials?.map((qm) => ({
+ ...qm,
+ documentReadableId: qm.documentReadableId ?? "",
+ })),
+ },
+ ];
+
+ return (
+ <UsedInTree
+ tree={tree}
+ itemReadableId={
+ consumableData.consumableSummary?.id ?? ""
+ }
+ />
+ );
+ }}
+ </Await>
+ </Suspense>
+ </div>
+ </ScrollArea>
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel order={2} minSize={40} defaultSize={60}>
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <VStack spacing={2} className="p-2">
+ <ItemNotes
+ id={consumableData.consumableSummary?.itemId ?? null}
+ title={consumableData.consumableSummary?.name ?? ""}
+ subTitle={consumableData.consumableSummary?.id ?? ""}
+ notes={consumableData.consumableSummary?.notes as JSONContent}
/>
- )}
- </Await>
- </Suspense>
- )}
- </VStack>
+ {permissions.is("employee") && (
+ <Suspense
+ fallback={
+ <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">
+ <Spinner className="h-10 w-10" />
+ </div>
+ }
+ >
+ <Await resolve={consumableData?.files}>
+ {(files) => (
+ <ItemDocuments
+ files={files ?? []}
+ itemId={itemId}
+ type="Consumable"
+ />
+ )}
+ </Await>
+ </Suspense>
+ )}
+ </VStack>
+ </ScrollArea>
+ </ResizablePanel>
+ </ResizablePanelGroup>
+ </div>
);
}
diff --git a/apps/erp/app/routes/x+/consumable+/$itemId.tsx b/apps/erp/app/routes/x+/consumable+/$itemId.tsx
index 85cd22f374..3bed450586 100644
--- a/apps/erp/app/routes/x+/consumable+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/consumable+/$itemId.tsx
@@ -66,7 +66,7 @@ export default function ConsumableRoute() {
<div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full">
<ConsumableHeader />
<div className="flex h-[calc(100dvh-99px)] w-full">
- <div className="flex h-full w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
+ <div className="flex h-full w-full overflow-y-auto scrollbar-hide">
<Outlet />
</div>
<ConsumableProperties />
diff --git a/apps/erp/app/routes/x+/job+/$jobId.buy.$methodId.$materialId.tsx b/apps/erp/app/routes/x+/job+/$jobId.buy.$methodId.$materialId.tsx
index c69d7628b2..c046cc0606 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.buy.$methodId.$materialId.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.buy.$methodId.$materialId.tsx
@@ -1,4 +1,4 @@
-import { VStack } from "@carbon/react";
+import { useMount, VStack } from "@carbon/react";
import { json, redirect, useLoaderData, useParams } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
@@ -12,6 +12,7 @@ import {
import { JobMaterialForm } from "~/modules/production/ui/Jobs";
import JobMakeMethodTools from "~/modules/production/ui/Jobs/JobMakeMethodTools";
import { path } from "~/utils/path";
+import { usePanels } from "~/components/Layout";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
@@ -71,6 +72,14 @@ export default function JobMaterialBuyPage() {
const { materialId } = useParams();
if (!materialId) throw new Error("Could not find materialId");
+ const { setIsExplorerCollapsed, isExplorerCollapsed } = usePanels();
+
+ useMount(() => {
+ if (isExplorerCollapsed) {
+ setIsExplorerCollapsed(false);
+ }
+ });
+
return (
<VStack spacing={2} className="p-2">
<JobMakeMethodTools />
diff --git a/apps/erp/app/routes/x+/job+/$jobId.details.tsx b/apps/erp/app/routes/x+/job+/$jobId.details.tsx
index f09e71ca2a..4505e0863e 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.details.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.details.tsx
@@ -126,7 +126,7 @@ export default function JobDetailsRoute() {
useRealtime("modelUpload", `modelPath=eq.(${jobData?.job.modelPath})`);
return (
- <VStack spacing={4} className="p-4 h-full">
+ <VStack spacing={2} className="p-2 h-full">
<JobNotes
id={jobId}
title={jobData?.job.jobId ?? ""}
diff --git a/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx b/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx
index 6838261dc5..0bff0cd77b 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.make.$methodId.$materialId.tsx
@@ -1,5 +1,5 @@
import type { JSONContent } from "@carbon/react";
-import { Spinner, VStack } from "@carbon/react";
+import { Spinner, useMount, VStack } from "@carbon/react";
import {
Await,
defer,
@@ -31,6 +31,7 @@ import {
import JobMakeMethodTools from "~/modules/production/ui/Jobs/JobMakeMethodTools";
import { getModelByItemId, getTagsList } from "~/modules/shared";
import { path } from "~/utils/path";
+import { usePanels } from "~/components/Layout";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
@@ -128,6 +129,14 @@ export default function JobMakeMethodRoute() {
const loaderData = useLoaderData<typeof loader>();
const { material, materials, operations, productionData, tags } = loaderData;
+ const { setIsExplorerCollapsed, isExplorerCollapsed } = usePanels();
+
+ useMount(() => {
+ if (isExplorerCollapsed) {
+ setIsExplorerCollapsed(false);
+ }
+ });
+
return (
<VStack spacing={2} className="p-2">
<JobMakeMethodTools />
diff --git a/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx b/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx
index c60dd917ec..6f85dce072 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx
@@ -1,5 +1,5 @@
import type { JSONContent } from "@carbon/react";
-import { Spinner, VStack } from "@carbon/react";
+import { Spinner, useMount, VStack } from "@carbon/react";
import {
Await,
defer,
@@ -29,6 +29,7 @@ import {
import JobMakeMethodTools from "~/modules/production/ui/Jobs/JobMakeMethodTools";
import { getTagsList } from "~/modules/shared";
import { path } from "~/utils/path";
+import { usePanels } from "~/components/Layout";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
@@ -102,6 +103,14 @@ export default function JobMakeMethodRoute() {
const loaderData = useLoaderData<typeof loader>();
const { materials, operations, productionData, tags } = loaderData;
+ const { setIsExplorerCollapsed, isExplorerCollapsed } = usePanels();
+
+ useMount(() => {
+ if (isExplorerCollapsed) {
+ setIsExplorerCollapsed(false);
+ }
+ });
+
return (
<div className="h-[calc(100dvh-49px)] w-full items-start overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
<VStack spacing={2} className="p-2">
diff --git a/apps/erp/app/routes/x+/job+/$jobId.pick.$methodId.$materialId.tsx b/apps/erp/app/routes/x+/job+/$jobId.pick.$methodId.$materialId.tsx
index 02de693eea..14eeab44b9 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.pick.$methodId.$materialId.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.pick.$methodId.$materialId.tsx
@@ -1,4 +1,4 @@
-import { VStack } from "@carbon/react";
+import { useMount, VStack } from "@carbon/react";
import { json, redirect, useLoaderData, useParams } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
@@ -12,6 +12,7 @@ import {
import { JobMaterialForm } from "~/modules/production/ui/Jobs";
import JobMakeMethodTools from "~/modules/production/ui/Jobs/JobMakeMethodTools";
import { path } from "~/utils/path";
+import { usePanels } from "~/components/Layout";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
@@ -68,6 +69,14 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export default function JobMaterialPickPage() {
const { material, operations } = useLoaderData<typeof loader>();
+ const { setIsExplorerCollapsed, isExplorerCollapsed } = usePanels();
+
+ useMount(() => {
+ if (isExplorerCollapsed) {
+ setIsExplorerCollapsed(false);
+ }
+ });
+
const { materialId } = useParams();
if (!materialId) throw new Error("Could not find materialId");
diff --git a/apps/erp/app/routes/x+/material+/$itemId.details.tsx b/apps/erp/app/routes/x+/material+/$itemId.details.tsx
index 3b8ad229b3..f97641a5be 100644
--- a/apps/erp/app/routes/x+/material+/$itemId.details.tsx
+++ b/apps/erp/app/routes/x+/material+/$itemId.details.tsx
@@ -3,19 +3,47 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import type { JSONContent } from "@carbon/react";
-import { Spinner, VStack } from "@carbon/react";
-import { Await, useParams } from "@remix-run/react";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
+import {
+ Spinner,
+ VStack,
+ ScrollArea,
+ ResizablePanel,
+ ResizablePanelGroup,
+ ResizableHandle,
+} from "@carbon/react";
+import { Await, useLoaderData, useParams } from "@remix-run/react";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { redirect, defer } from "@vercel/remix";
import { Suspense } from "react";
import { usePermissions, useRouteData } from "~/hooks";
import type { ItemFile, Material } from "~/modules/items";
-import { materialValidator, upsertMaterial } from "~/modules/items";
+import {
+ getMaterialUsedIn,
+ materialValidator,
+ upsertMaterial,
+} from "~/modules/items";
import { ItemDocuments, ItemNotes } from "~/modules/items/ui/Item";
+import {
+ UsedInSkeleton,
+ UsedInItem,
+ UsedInTree,
+} from "~/modules/items/ui/Item/UsedIn";
import { setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "parts",
+ bypassRls: true,
+ });
+
+ const { itemId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+
+ return defer({ usedIn: getMaterialUsedIn(client, itemId, companyId) });
+}
+
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
@@ -55,6 +83,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function MaterialDetailsRoute() {
+ const { usedIn } = useLoaderData<typeof loader>();
const permissions = usePermissions();
const { itemId } = useParams();
@@ -67,32 +96,115 @@ export default function MaterialDetailsRoute() {
if (!materialData) throw new Error("Could not find material data");
return (
- <VStack spacing={2} className="w-full h-full p-2">
- <ItemNotes
- id={materialData.materialSummary?.itemId ?? null}
- title={materialData.materialSummary?.id ?? ""}
- subTitle={materialData.materialSummary?.name ?? ""}
- notes={materialData.materialSummary?.notes as JSONContent}
- />
- {permissions.is("employee") && (
- <Suspense
- fallback={
- <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">
- <Spinner className="h-10 w-10" />
- </div>
- }
+ <div className="flex flex-grow overflow-hidden">
+ <ResizablePanelGroup direction="horizontal">
+ <ResizablePanel
+ order={1}
+ minSize={10}
+ defaultSize={20}
+ className="bg-card"
>
- <Await resolve={materialData?.files}>
- {(files) => (
- <ItemDocuments
- files={files ?? []}
- itemId={itemId}
- type="Material"
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <div className="grid h-full overflow-hidden p-2">
+ <Suspense fallback={<UsedInSkeleton />}>
+ <Await resolve={usedIn}>
+ {(resolvedUsedIn) => {
+ const {
+ jobMaterials,
+ methodMaterials,
+ purchaseOrderLines,
+ receiptLines,
+ quoteMaterials,
+ } = resolvedUsedIn;
+
+ const tree: UsedInItem[] = [
+ {
+ key: "jobMaterials",
+ name: "Job Materials",
+ module: "production",
+ children: jobMaterials,
+ },
+ {
+ key: "methodMaterials",
+ name: "Method Materials",
+ module: "parts",
+ // @ts-expect-error
+ children: methodMaterials,
+ },
+ {
+ key: "purchaseOrderLines",
+ name: "Purchase Orders",
+ module: "purchasing",
+ children: purchaseOrderLines.map((po) => ({
+ ...po,
+ methodType: "Buy",
+ })),
+ },
+ {
+ key: "receiptLines",
+ name: "Receipts",
+ module: "inventory",
+ children: receiptLines.map((receipt) => ({
+ ...receipt,
+ methodType: "Pick",
+ })),
+ },
+ {
+ key: "quoteMaterials",
+ name: "Quote Materials",
+ module: "sales",
+ children: quoteMaterials?.map((qm) => ({
+ ...qm,
+ documentReadableId: qm.documentReadableId ?? "",
+ })),
+ },
+ ];
+
+ return (
+ <UsedInTree
+ tree={tree}
+ itemReadableId={materialData.materialSummary?.id ?? ""}
+ />
+ );
+ }}
+ </Await>
+ </Suspense>
+ </div>
+ </ScrollArea>
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel order={2} minSize={40} defaultSize={60}>
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <VStack spacing={2} className="p-2">
+ <ItemNotes
+ id={materialData.materialSummary?.itemId ?? null}
+ title={materialData.materialSummary?.name ?? ""}
+ subTitle={materialData.materialSummary?.id ?? ""}
+ notes={materialData.materialSummary?.notes as JSONContent}
/>
- )}
- </Await>
- </Suspense>
- )}
- </VStack>
+ {permissions.is("employee") && (
+ <Suspense
+ fallback={
+ <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">
+ <Spinner className="h-10 w-10" />
+ </div>
+ }
+ >
+ <Await resolve={materialData?.files}>
+ {(files) => (
+ <ItemDocuments
+ files={files ?? []}
+ itemId={itemId}
+ type="Material"
+ />
+ )}
+ </Await>
+ </Suspense>
+ )}
+ </VStack>
+ </ScrollArea>
+ </ResizablePanel>
+ </ResizablePanelGroup>
+ </div>
);
}
diff --git a/apps/erp/app/routes/x+/material+/$itemId.tsx b/apps/erp/app/routes/x+/material+/$itemId.tsx
index 8a2812ecc4..ec9989c520 100644
--- a/apps/erp/app/routes/x+/material+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/material+/$itemId.tsx
@@ -67,7 +67,7 @@ export default function MaterialRoute() {
<div className="flex flex-col h-[calc(100dvh-49px)] w-full">
<MaterialHeader />
<div className="flex h-[calc(100dvh-99px)] w-full">
- <div className="flex h-full w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
+ <div className="flex h-full w-full overflow-y-auto scrollbar-hide">
<Outlet />
</div>
<MaterialProperties />
diff --git a/apps/erp/app/routes/x+/part+/$itemId.details.tsx b/apps/erp/app/routes/x+/part+/$itemId.details.tsx
index 42ef4e4cb7..9fd47de85a 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.details.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.details.tsx
@@ -3,19 +3,44 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import type { JSONContent } from "@carbon/react";
-import { Spinner, VStack } from "@carbon/react";
-import { Await, useParams } from "@remix-run/react";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
+import {
+ ClientOnly,
+ ResizableHandle,
+ ResizablePanel,
+ ResizablePanelGroup,
+ ScrollArea,
+ Spinner,
+ VStack,
+} from "@carbon/react";
+import { Await, useLoaderData, useParams } from "@remix-run/react";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { defer, redirect } from "@vercel/remix";
import { Suspense } from "react";
import { CadModel } from "~/components";
import { usePermissions, useRouteData } from "~/hooks";
import type { ItemFile, PartSummary } from "~/modules/items";
-import { partValidator, upsertPart } from "~/modules/items";
+import { getPartUsedIn, partValidator, upsertPart } from "~/modules/items";
import { ItemDocuments, ItemNotes } from "~/modules/items/ui/Item";
import { setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+import {
+ UsedInSkeleton,
+ UsedInItem,
+ UsedInTree,
+} from "~/modules/items/ui/Item/UsedIn";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "parts",
+ bypassRls: true,
+ });
+
+ const { itemId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+
+ return defer({ usedIn: getPartUsedIn(client, itemId, companyId) });
+}
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
@@ -53,6 +78,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function PartDetailsRoute() {
+ const { usedIn } = useLoaderData<typeof loader>();
+
const { itemId } = useParams();
if (!itemId) throw new Error("Could not find itemId");
@@ -65,42 +92,153 @@ export default function PartDetailsRoute() {
const permissions = usePermissions();
return (
- <VStack spacing={2} className="p-2">
- <ItemNotes
- id={partData.partSummary?.itemId ?? null}
- title={partData.partSummary?.id ?? ""}
- subTitle={partData.partSummary?.name ?? ""}
- notes={partData.partSummary?.notes as JSONContent}
- />
- {permissions.is("employee") && (
- <div className="grid grid-cols-1 2xl:grid-cols-2 w-full flex-grow gap-2">
- <Suspense
- fallback={
- <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">
- <Spinner className="h-10 w-10" />
- </div>
- }
- >
- <Await resolve={partData?.files}>
- {(resolvedFiles) => (
- <ItemDocuments
- files={resolvedFiles}
- itemId={itemId}
- modelUpload={partData.partSummary ?? undefined}
- type="Part"
- />
- )}
- </Await>
- </Suspense>
-
- <CadModel
- isReadOnly={!permissions.can("update", "parts")}
- metadata={{ itemId }}
- modelPath={partData?.partSummary?.modelPath ?? null}
- title="CAD Model"
- />
- </div>
- )}
- </VStack>
+ <div className="flex flex-grow overflow-hidden">
+ <ClientOnly fallback={null}>
+ {() => (
+ <ResizablePanelGroup direction="horizontal">
+ <ResizablePanel
+ order={1}
+ minSize={10}
+ defaultSize={20}
+ className="bg-card"
+ >
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <div className="grid h-full overflow-hidden p-2">
+ <Suspense fallback={<UsedInSkeleton />}>
+ <Await resolve={usedIn}>
+ {(resolvedUsedIn) => {
+ const {
+ jobMaterials,
+ jobs,
+ methodMaterials,
+ purchaseOrderLines,
+ receiptLines,
+ quoteLines,
+ quoteMaterials,
+ salesOrderLines,
+ } = resolvedUsedIn;
+
+ const tree: UsedInItem[] = [
+ {
+ key: "jobs",
+ name: "Jobs",
+ module: "production",
+ children: jobs.map((job) => ({
+ ...job,
+ methodType: "Make",
+ })),
+ },
+ {
+ key: "jobMaterials",
+ name: "Job Materials",
+ module: "production",
+ children: jobMaterials,
+ },
+ {
+ key: "methodMaterials",
+ name: "Method Materials",
+ module: "parts",
+ // @ts-expect-error
+ children: methodMaterials,
+ },
+ {
+ key: "purchaseOrderLines",
+ name: "Purchase Orders",
+ module: "purchasing",
+ children: purchaseOrderLines.map((po) => ({
+ ...po,
+ methodType: "Buy",
+ })),
+ },
+ {
+ key: "receiptLines",
+ name: "Receipts",
+ module: "inventory",
+ children: receiptLines.map((receipt) => ({
+ ...receipt,
+ methodType: "Pick",
+ })),
+ },
+ {
+ key: "quoteLines",
+ name: "Quotes",
+ module: "sales",
+ children: quoteLines,
+ },
+ {
+ key: "quoteMaterials",
+ name: "Quote Materials",
+ module: "sales",
+ children: quoteMaterials?.map((qm) => ({
+ ...qm,
+ documentReadableId: qm.documentReadableId ?? "",
+ })),
+ },
+ {
+ key: "salesOrderLines",
+ name: "Sales Orders",
+ module: "sales",
+ children: salesOrderLines,
+ },
+ ];
+
+ return (
+ <UsedInTree
+ tree={tree}
+ itemReadableId={partData.partSummary?.id ?? ""}
+ />
+ );
+ }}
+ </Await>
+ </Suspense>
+ </div>
+ </ScrollArea>
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel order={2} minSize={40} defaultSize={60}>
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <VStack spacing={2} className="p-2">
+ <ItemNotes
+ id={partData.partSummary?.itemId ?? null}
+ title={partData.partSummary?.name ?? ""}
+ subTitle={partData.partSummary?.id ?? ""}
+ notes={partData.partSummary?.notes as JSONContent}
+ />
+ {permissions.is("employee") && (
+ <>
+ <Suspense
+ fallback={
+ <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">
+ <Spinner className="h-10 w-10" />
+ </div>
+ }
+ >
+ <Await resolve={partData?.files}>
+ {(resolvedFiles) => (
+ <ItemDocuments
+ files={resolvedFiles}
+ itemId={itemId}
+ modelUpload={partData.partSummary ?? undefined}
+ type="Part"
+ />
+ )}
+ </Await>
+ </Suspense>
+
+ <CadModel
+ isReadOnly={!permissions.can("update", "parts")}
+ metadata={{ itemId }}
+ modelPath={partData?.partSummary?.modelPath ?? null}
+ title="CAD Model"
+ />
+ </>
+ )}
+ </VStack>
+ </ScrollArea>
+ </ResizablePanel>
+ </ResizablePanelGroup>
+ )}
+ </ClientOnly>
+ </div>
);
}
diff --git a/apps/erp/app/routes/x+/part+/$itemId.tsx b/apps/erp/app/routes/x+/part+/$itemId.tsx
index e44e61461c..2bf0f985de 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.tsx
@@ -61,7 +61,7 @@ export default function PartRoute() {
<div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full">
<PartHeader />
<div className="flex h-[calc(100dvh-99px)] w-full">
- <div className="flex h-full w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
+ <div className="flex h-full w-full overflow-y-auto scrollbar-hide">
<Outlet />
</div>
<PartProperties />
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.details.tsx b/apps/erp/app/routes/x+/tool+/$itemId.details.tsx
index b008102304..935e251ce1 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.details.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.details.tsx
@@ -3,17 +3,41 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import type { JSONContent } from "@carbon/react";
-import { Spinner, VStack } from "@carbon/react";
-import { Await, useParams } from "@remix-run/react";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
+import {
+ ResizableHandle,
+ ResizablePanel,
+ ResizablePanelGroup,
+ ScrollArea,
+ Spinner,
+ VStack,
+} from "@carbon/react";
+import { Await, useLoaderData, useParams } from "@remix-run/react";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { defer, redirect } from "@vercel/remix";
import { Suspense } from "react";
import { usePermissions, useRouteData } from "~/hooks";
import type { ItemFile, ToolSummary } from "~/modules/items";
-import { toolValidator, upsertTool } from "~/modules/items";
+import { getPartUsedIn, toolValidator, upsertTool } from "~/modules/items";
import { ItemDocuments, ItemNotes } from "~/modules/items/ui/Item";
import { setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+import {
+ UsedInSkeleton,
+ UsedInItem,
+ UsedInTree,
+} from "~/modules/items/ui/Item/UsedIn";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "parts",
+ bypassRls: true,
+ });
+
+ const { itemId } = params;
+ if (!itemId) throw new Error("Could not find itemId");
+
+ return defer({ usedIn: getPartUsedIn(client, itemId, companyId) });
+}
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
@@ -51,7 +75,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function ToolDetailsRoute() {
- const permissions = usePermissions();
+ const { usedIn } = useLoaderData<typeof loader>();
const { itemId } = useParams();
if (!itemId) throw new Error("Could not find itemId");
@@ -61,30 +85,128 @@ export default function ToolDetailsRoute() {
files: Promise<ItemFile[]>;
}>(path.to.tool(itemId));
if (!toolData) throw new Error("Could not find tool data");
+ const permissions = usePermissions();
return (
- <VStack spacing={2} className="w-full h-full p-2">
- <ItemNotes
- id={toolData.toolSummary?.itemId ?? null}
- title={toolData.toolSummary?.id ?? ""}
- subTitle={toolData.toolSummary?.name ?? ""}
- notes={toolData.toolSummary?.notes as JSONContent}
- />
- {permissions.is("employee") && (
- <Suspense
- fallback={
- <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">
- <Spinner className="h-10 w-10" />
- </div>
- }
+ <div className="flex flex-grow overflow-hidden">
+ <ResizablePanelGroup direction="horizontal">
+ <ResizablePanel
+ order={1}
+ minSize={10}
+ defaultSize={20}
+ className="bg-card"
>
- <Await resolve={toolData?.files}>
- {(files) => (
- <ItemDocuments files={files ?? []} itemId={itemId} type="Tool" />
- )}
- </Await>
- </Suspense>
- )}
- </VStack>
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <div className="grid h-full overflow-hidden p-2">
+ <Suspense fallback={<UsedInSkeleton />}>
+ <Await resolve={usedIn}>
+ {(resolvedUsedIn) => {
+ const {
+ jobMaterials,
+ jobs,
+ methodMaterials,
+ purchaseOrderLines,
+ receiptLines,
+ quoteMaterials,
+ } = resolvedUsedIn;
+
+ const tree: UsedInItem[] = [
+ {
+ key: "jobs",
+ name: "Jobs",
+ module: "production",
+ children: jobs.map((job) => ({
+ ...job,
+ methodType: "Make",
+ })),
+ },
+ {
+ key: "jobMaterials",
+ name: "Job Materials",
+ module: "production",
+ children: jobMaterials,
+ },
+ {
+ key: "methodMaterials",
+ name: "Method Materials",
+ module: "parts",
+ // @ts-expect-error
+ children: methodMaterials,
+ },
+ {
+ key: "purchaseOrderLines",
+ name: "Purchase Orders",
+ module: "purchasing",
+ children: purchaseOrderLines.map((po) => ({
+ ...po,
+ methodType: "Buy",
+ })),
+ },
+ {
+ key: "receiptLines",
+ name: "Receipts",
+ module: "inventory",
+ children: receiptLines.map((receipt) => ({
+ ...receipt,
+ methodType: "Pick",
+ })),
+ },
+ {
+ key: "quoteMaterials",
+ name: "Quote Materials",
+ module: "sales",
+ children: quoteMaterials?.map((qm) => ({
+ ...qm,
+ documentReadableId: qm.documentReadableId ?? "",
+ })),
+ },
+ ];
+
+ return (
+ <UsedInTree
+ tree={tree}
+ itemReadableId={toolData.toolSummary?.id ?? ""}
+ />
+ );
+ }}
+ </Await>
+ </Suspense>
+ </div>
+ </ScrollArea>
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel order={2} minSize={40} defaultSize={60}>
+ <ScrollArea className="h-[calc(100dvh-99px)]">
+ <VStack spacing={2} className="p-2">
+ <ItemNotes
+ id={toolData.toolSummary?.itemId ?? null}
+ title={toolData.toolSummary?.id ?? ""}
+ subTitle={toolData.toolSummary?.name ?? ""}
+ notes={toolData.toolSummary?.notes as JSONContent}
+ />
+ {permissions.is("employee") && (
+ <Suspense
+ fallback={
+ <div className="flex w-full h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">
+ <Spinner className="h-10 w-10" />
+ </div>
+ }
+ >
+ <Await resolve={toolData?.files}>
+ {(files) => (
+ <ItemDocuments
+ files={files ?? []}
+ itemId={itemId}
+ type="Tool"
+ />
+ )}
+ </Await>
+ </Suspense>
+ )}
+ </VStack>
+ </ScrollArea>
+ </ResizablePanel>
+ </ResizablePanelGroup>
+ </div>
);
}
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.tsx b/apps/erp/app/routes/x+/tool+/$itemId.tsx
index b725e673ca..832487c350 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.tsx
@@ -61,7 +61,7 @@ export default function ToolRoute() {
<div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full">
<ToolHeader />
<div className="flex h-[calc(100dvh-99px)] w-full">
- <div className="flex h-full w-full overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
+ <div className="flex h-full w-full overflow-y-auto scrollbar-hide">
<Outlet />
</div>
<ToolProperties />
diff --git a/packages/react/src/Card.tsx b/packages/react/src/Card.tsx
index cf819e4e1f..f1f1983044 100644
--- a/packages/react/src/Card.tsx
+++ b/packages/react/src/Card.tsx
@@ -165,7 +165,7 @@ const CardTitle = forwardRef<
<h3
ref={ref}
className={cn(
- "text-xl font-semibold leading-none tracking-tight text-foreground",
+ "text-xl font-semibold leading-none tracking-tight text-foreground line-clamp-2",
className
)}
{...props}
diff --git a/packages/react/src/Count.tsx b/packages/react/src/Count.tsx
index 991fdbb9bf..09edba8968 100644
--- a/packages/react/src/Count.tsx
+++ b/packages/react/src/Count.tsx
@@ -1,16 +1,12 @@
import type { ComponentProps } from "react";
-export interface CountProps extends ComponentProps<"div"> {
+import { Badge } from "./Badge";
+export interface CountProps extends ComponentProps<typeof Badge> {
count: number;
}
const Count = ({ count, ...props }: CountProps) => {
const c = count > 99 ? "99+" : count;
- return (
- <div
- className="text-foreground font-mono font-semibold text-sm flex items-center justify-center"
- {...props}
- >{`${c}`}</div>
- );
+ return <Badge variant="gray" {...props}>{`${c}`}</Badge>;
};
export { Count };