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: get method materials

Brad Barbinbe013a099fab
diff --git a/apps/carbon/app/components/SortableList.tsx b/apps/carbon/app/components/SortableList.tsx
index dbf73bac26..a34a3bc0e3 100644
--- a/apps/carbon/app/components/SortableList.tsx
+++ b/apps/carbon/app/components/SortableList.tsx
@@ -117,9 +117,7 @@ function SortableListItem<T>({
<h4
className={cn(
"flex tracking-tighter text-base md:text-lg truncate",
- item.checked
- ? "text-red-400"
- : "text-foreground dark:text-foreground/70"
+ item.checked ? "text-red-400" : "text-foreground"
)}
>
{item.title}
diff --git a/apps/carbon/app/modules/items/items.service.ts b/apps/carbon/app/modules/items/items.service.ts
index 06b0080c86..15d96027f9 100644
--- a/apps/carbon/app/modules/items/items.service.ts
+++ b/apps/carbon/app/modules/items/items.service.ts
@@ -1,6 +1,7 @@
import type { Database, Json } from "@carbon/database";
import { getLocalTimeZone, today } from "@internationalized/date";
import type { SupabaseClient } from "@supabase/supabase-js";
+import { nanoid } from "nanoid";
import { type z } from "zod";
import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
@@ -570,7 +571,7 @@ export async function getMethodTreeArray(
function getMethodTreeArrayToTree(items: Method[]): MethodTreeItem[] {
function traverseAndRenameIds(node: MethodTreeItem) {
const clone = structuredClone(node);
- clone.id = `node-${Math.random().toString(16).slice(2)}`;
+ clone.id = nanoid();
clone.children = clone.children.map((n) => traverseAndRenameIds(n));
return clone;
}
diff --git a/apps/carbon/app/modules/items/ui/Parts/usePartNavigation.tsx b/apps/carbon/app/modules/items/ui/Parts/usePartNavigation.tsx
index 954035af14..558591b5e7 100644
--- a/apps/carbon/app/modules/items/ui/Parts/usePartNavigation.tsx
+++ b/apps/carbon/app/modules/items/ui/Parts/usePartNavigation.tsx
@@ -72,7 +72,7 @@ export function usePartNavigation() {
shortcut: "Command+Shift+p",
},
{
- name: "Sale Price",
+ name: "Sales",
to: path.to.partSalePrice(itemId),
role: ["employee", "customer"],
icon: LuReceipt,
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBreadcrumbs.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBreadcrumbs.tsx
index 5e6ac1f046..46eb07bcce 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBreadcrumbs.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBreadcrumbs.tsx
@@ -1,39 +1,76 @@
-import { Button } from "@carbon/react";
-import { Link, useParams } from "@remix-run/react";
+import { Button, HStack, Menubar, MenubarItem } from "@carbon/react";
+import { Link, useFetcher, useLocation, useParams } from "@remix-run/react";
+import { LuDownload, LuUpload } from "react-icons/lu";
import { RiProgress4Line } from "react-icons/ri";
import { BreadcrumbItem, Breadcrumbs } from "~/components";
-import { useRouteData } from "~/hooks";
+import { usePermissions, useRouteData } from "~/hooks";
import { path } from "~/utils/path";
import type { Quotation, QuotationLine } from "../../types";
const QuoteBreadcrumbs = () => {
+ const permissions = usePermissions();
const { quoteId, lineId, makeMethodId } = useParams();
if (!quoteId) throw new Error("quoteId not found");
+ const fetcher = useFetcher<{ error: null | { message: string } }>();
const routeData = useRouteData<{ quote: Quotation; lines: QuotationLine[] }>(
path.to.quote(quoteId)
);
const line = routeData?.lines.find((line) => line.id === lineId);
+ const { pathname } = useLocation();
+
+ const getMethod = async (itemId: string, quoteLineId: string) => {
+ const formData = new FormData();
+ formData.append("itemId", itemId);
+ formData.append("quoteId", quoteId);
+ formData.append("quoteLineId", quoteLineId);
+
+ fetcher.submit(formData, {
+ method: "post",
+ action: path.to.quoteMethodGet,
+ });
+ };
return (
- <Breadcrumbs className="my-1">
- <BreadcrumbItem>
- <Button leftIcon={<RiProgress4Line />} variant="ghost" asChild>
- <Link to={path.to.quoteDetails(quoteId)}>
- {routeData?.quote?.quoteId}
- </Link>
- </Button>
- </BreadcrumbItem>
- {line && (
- <BreadcrumbItem>
- <Button variant="ghost" asChild>
- <Link to={path.to.quoteLine(quoteId, line.id!)}>
- {line.itemReadableId}
- </Link>
- </Button>
- </BreadcrumbItem>
- )}
- </Breadcrumbs>
+ <Menubar>
+ <HStack className="w-full justify-between">
+ <Breadcrumbs>
+ <BreadcrumbItem>
+ <Button leftIcon={<RiProgress4Line />} variant="ghost" asChild>
+ <Link to={path.to.quoteDetails(quoteId)}>
+ {routeData?.quote?.quoteId}
+ </Link>
+ </Button>
+ </BreadcrumbItem>
+ {line && (
+ <BreadcrumbItem>
+ <Button variant="ghost" asChild>
+ <Link to={path.to.quoteLine(quoteId, line.id!)}>
+ {line.itemReadableId}
+ </Link>
+ </Button>
+ </BreadcrumbItem>
+ )}
+ </Breadcrumbs>
+ {line &&
+ permissions.can("update", "sales") &&
+ pathname === path.to.quoteLine(quoteId, lineId!) && (
+ <HStack spacing={0}>
+ <MenubarItem
+ leftIcon={<LuDownload />}
+ isLoading={
+ fetcher.state !== "idle" &&
+ fetcher.formAction === path.to.quoteMethodGet
+ }
+ onClick={() => getMethod(line.itemId!, line.id!)}
+ >
+ Get Method
+ </MenubarItem>
+ <MenubarItem leftIcon={<LuUpload />}>Save Method</MenubarItem>
+ </HStack>
+ )}
+ </HStack>
+ </Menubar>
);
};
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
index ff19a64bc1..046199ec46 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
@@ -23,7 +23,7 @@ import { ValidatedForm } from "@carbon/remix-validated-form";
import { useParams } from "@remix-run/react";
import { useState } from "react";
import { BsThreeDotsVertical } from "react-icons/bs";
-import { LuDownload, LuTrash, LuUpload } from "react-icons/lu";
+import { LuTrash } from "react-icons/lu";
import type { z } from "zod";
import {
ArrayNumeric,
@@ -163,18 +163,6 @@ const QuoteLineForm = ({
<DropdownMenuIcon icon={<LuTrash />} />
Delete Line
</DropdownMenuItem>
- <DropdownMenuItem
- disabled={itemData.methodType !== "Make"}
- >
- <DropdownMenuIcon icon={<LuDownload />} />
- Get Method
- </DropdownMenuItem>
- <DropdownMenuItem
- disabled={itemData.methodType !== "Make"}
- >
- <DropdownMenuIcon icon={<LuUpload />} />
- Save Method
- </DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</CardAction>
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.buy.$materialId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.buy.$materialId.tsx
index dc2eab65b3..f385a7a161 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.buy.$materialId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.buy.$materialId.tsx
@@ -56,7 +56,7 @@ export default function QuoteMaterialBuyPage() {
if (!materialId) throw new Error("Could not find materialId");
return (
- <VStack spacing={2} className="p-2">
+ <VStack spacing={2}>
<QuoteMaterialForm
key={materialId}
initialValues={material}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx
index e7037c866a..b945eb0c49 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.make.$methodId.$materialId.tsx
@@ -103,7 +103,7 @@ export default function QuoteMakeMethodRoute() {
const { material, materials, operations } = useLoaderData<typeof loader>();
return (
- <VStack spacing={2} className="p-2">
+ <VStack spacing={2}>
<QuoteMaterialForm
key={material.id}
initialValues={material}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx
index 218203ba11..461fa1eba3 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx
@@ -68,13 +68,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}
export default function QuoteMakeMethodRoute() {
- const { methodId } = useParams();
+ const { quoteId, lineId, methodId } = useParams();
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
if (!methodId) throw new Error("Could not find methodId");
const { materials, operations } = useLoaderData<typeof loader>();
return (
- <VStack spacing={2} className="p-2">
+ <VStack spacing={2}>
<QuoteBillOfProcess
key={`bop:${methodId}`}
quoteMakeMethodId={methodId}
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.pick.$materialId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.pick.$materialId.tsx
index 35bc764caf..fff1178f93 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.pick.$materialId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.pick.$materialId.tsx
@@ -56,7 +56,7 @@ export default function QuoteMaterialPickPage() {
if (!materialId) throw new Error("Could not find materialId");
return (
- <VStack spacing={2} className="p-2">
+ <VStack spacing={2}>
<QuoteMaterialForm
key={materialId}
initialValues={material}
diff --git a/apps/carbon/app/routes/x+/quote+/methods.get.tsx b/apps/carbon/app/routes/x+/quote+/methods.get.tsx
new file mode 100644
index 0000000000..ba71708513
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/methods.get.tsx
@@ -0,0 +1,36 @@
+import { type ActionFunctionArgs } from "@remix-run/node";
+import { getSupabaseServiceRole } from "~/lib/supabase";
+import { requirePermissions } from "~/services/auth/auth.server";
+
+export async function action({ request }: ActionFunctionArgs) {
+ const { companyId, userId } = await requirePermissions(request, {
+ update: "sales",
+ });
+
+ const formData = await request.formData();
+ const itemId = formData.get("itemId") as string;
+ const quoteId = formData.get("quoteId") as string;
+ const quoteLineId = formData.get("quoteLineId") as string;
+
+ if (!itemId || !quoteId || !quoteLineId) {
+ throw new Error("Missing required fields");
+ }
+
+ const supabaseServiceRole = getSupabaseServiceRole();
+ const { data, error } = await supabaseServiceRole.functions.invoke(
+ "get-method",
+ {
+ body: {
+ type: "quote",
+ sourceId: itemId,
+ targetId: `${quoteId}:${quoteLineId}`,
+ companyId,
+ userId,
+ },
+ }
+ );
+
+ console.log({ data, error });
+
+ return null;
+}
diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx
index f122206819..a70924d123 100644
--- a/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx
+++ b/apps/carbon/app/routes/x+/resources+/work-cells.$typeId.tsx
@@ -89,7 +89,8 @@ export default function EditAttributeCategoryRoute() {
quotingRate: workCellType?.quotingRate ?? 0,
laborRate: workCellType?.laborRate ?? 0,
overheadRate: workCellType?.overheadRate ?? 0,
- defaultStandardFactor: workCellType?.defaultStandardFactor ?? "Total Hours",
+ defaultStandardFactor:
+ workCellType?.defaultStandardFactor ?? "Minutes/Piece",
...getCustomFields(workCellType?.customFields),
};
diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx
index cf792fb221..e8f4ce9037 100644
--- a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx
+++ b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx
@@ -62,7 +62,7 @@ export default function NewWorkCellTypeRoute() {
quotingRate: 0,
laborRate: 0,
overheadRate: 0,
- defaultStandardFactor: "Total Hours" as "Total Hours",
+ defaultStandardFactor: "Minutes/Piece" as "Minutes/Piece",
};
return <WorkCellTypeForm onClose={onClose} initialValues={initialValues} />;
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 9f733ca0a2..a343a0d4f8 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -580,7 +580,7 @@ export const path = {
quoteMaterial: (quoteId: string, lineId: string, id: string) =>
generatePath(`${x}/quote/methods/${quoteId}/${lineId}/material/${id}`),
quoteMaterialsOrder: `${x}/quote/methods/material/order`,
-
+ quoteMethodGet: `${x}/quote/methods/get`,
quoteOperation: (quoteId: string, lineId: string, id: string) =>
generatePath(`${x}/quote/methods/${quoteId}/${lineId}/operation/${id}`),
quoteOperationsOrder: `${x}/quote/methods/operation/order`,
diff --git a/packages/database/supabase/functions/get-method/index.ts b/packages/database/supabase/functions/get-method/index.ts
new file mode 100644
index 0000000000..975893913d
--- /dev/null
+++ b/packages/database/supabase/functions/get-method/index.ts
@@ -0,0 +1,315 @@
+import { serve } from "https://deno.land/[email protected]/http/server.ts";
+import { nanoid } from "https://deno.land/x/[email protected]/mod.ts";
+import { z } from "https://deno.land/x/[email protected]/mod.ts";
+
+import type {
+ PostgrestError,
+ SupabaseClient,
+} from "https://esm.sh/@supabase/[email protected]";
+
+import { DB, getConnectionPool, getDatabaseClient } from "../lib/database.ts";
+import type { Database } from "../lib/types.ts";
+
+import { corsHeaders } from "../lib/headers.ts";
+import { getSupabaseServiceRole } from "../lib/supabase.ts";
+
+const pool = getConnectionPool(1);
+const db = getDatabaseClient<DB>(pool);
+
+const payloadValidator = z.object({
+ type: z.string(),
+ sourceId: z.string(),
+ targetId: z.string(),
+ companyId: z.string(),
+ userId: z.string(),
+});
+
+serve(async (req: Request) => {
+ if (req.method === "OPTIONS") {
+ return new Response("ok", { headers: corsHeaders });
+ }
+ const payload = await req.json();
+
+ try {
+ const { type, sourceId, targetId, companyId, userId } =
+ payloadValidator.parse(payload);
+
+ const client = getSupabaseServiceRole(req.headers.get("Authorization"));
+
+ switch (type) {
+ case "quote": {
+ const [quoteId, quoteLineId] = (targetId as string).split(":");
+ if (!quoteId || !quoteLineId) {
+ throw new Error("Invalid targetId");
+ }
+ const itemId = sourceId;
+
+ const [makeMethod, quoteMakeMethod] = await Promise.all([
+ client.from("makeMethod").select("*").eq("itemId", itemId).single(),
+ client
+ .from("quoteMakeMethod")
+ .select("*")
+ .eq("quoteLineId", quoteLineId)
+ .is("parentMaterialId", null)
+ .single(),
+ ]);
+
+ if (makeMethod.error) {
+ throw new Error("Failed to get make method");
+ }
+
+ if (quoteMakeMethod.error) {
+ throw new Error("Failed to get quote make method");
+ }
+
+ const [methodTrees] = await Promise.all([
+ getMethodTree(client, makeMethod.data.id),
+ ]);
+
+ if (methodTrees.error) {
+ throw new Error("Failed to get method tree");
+ }
+
+ const methodTree = methodTrees.data?.[0] as MethodTreeItem;
+ if (!methodTree) throw new Error("Method tree not found");
+
+ await db.transaction().execute(async (trx) => {
+ // Delete existing quoteMakeMethod, quoteMakeMethodOperation, quoteMakeMethodMaterial
+ await Promise.all([
+ trx
+ .deleteFrom("quoteMakeMethod")
+ .where((eb) =>
+ eb.and([
+ eb("quoteLineId", "=", quoteLineId),
+ eb("parentMaterialId", "is not", null),
+ ])
+ )
+ .execute(),
+ trx
+ .deleteFrom("quoteMaterial")
+ .where("quoteLineId", "=", quoteLineId)
+ .execute(),
+ trx
+ .deleteFrom("quoteOperation")
+ .where("quoteLineId", "=", quoteLineId)
+ .execute(),
+ ]);
+
+ // traverse method tree and create:
+ // - quoteMakeMethod
+ // - quoteMakeMethodOperation
+ // - quoteMakeMethodMaterial
+ async function traverseMethodToQuote(
+ node: MethodTreeItem,
+ parentQuoteMakeMethodId: string | null
+ ) {
+ const madeChildren = node.children.filter(
+ (child) => child.data.methodType === "Make"
+ );
+ const unmadeChildren = node.children.filter(
+ (child) => child.data.methodType !== "Make"
+ );
+
+ // const relatedOperations = await client
+ // .from("methodOperation")
+ // .select("*")
+ // .eq("makeMethodId", node.data.makeMethodId);
+
+ // const quoteOperations =
+ // relatedOperations?.data?.map((op) => ({
+ // quoteId,
+ // quoteLineId,
+ // quoteMakeMethodId: parentQuoteMakeMethodId!,
+ // workCellTypeId: op.workCellTypeId,
+ // equipmentTypeId: op.equipmentTypeId,
+ // description: op.description,
+ // setupHours: op.setupHours,
+ // standardFactor: op.standardFactor,
+ // productionStandard: op.productionStandard,
+ // quotingRate: 0, // TODO
+ // laborRate: 0, // TODO
+ // overheadRate: 0, // TODO
+ // order: op.order,
+ // operationOrder: op.operationOrder,
+ // companyId,
+ // createdBy: userId,
+ // customFields: {},
+ // })) ?? [];
+
+ // let methodOperationsToQuoteOperations: Record<string, string> = {};
+ // if (quoteOperations?.length > 0) {
+ // const operationIds = await trx
+ // .insertInto("quoteOperation")
+ // .values(quoteOperations)
+ // .returning(["id"])
+ // .execute();
+
+ // methodOperationsToQuoteOperations =
+ // relatedOperations.data?.reduce<Record<string, string>>(
+ // (acc, op, index) => {
+ // if (operationIds[index].id) {
+ // acc[op.id!] = operationIds[index].id!;
+ // }
+ // return acc;
+ // },
+ // {}
+ // ) ?? {};
+ // }
+
+ const mapMethodMaterialToQuoteMaterial = (
+ child: MethodTreeItem
+ ) => ({
+ quoteId,
+ quoteLineId,
+ quoteMakeMethodId: parentQuoteMakeMethodId!,
+ itemId: child.data.itemId,
+ itemReadableId: child.data.itemReadableId,
+ itemType: child.data.itemType,
+ methodType: child.data.methodType,
+ // operation: methodOperationsToQuoteOperations[child.data.operationId], // TODO
+ order: child.data.order,
+ description: "", // TODO
+ quantity: child.data.quantity,
+ unitOfMeasureCode: "EA", // TODO
+ unitCost: 0, // TODO
+ companyId,
+ createdBy: userId,
+ customFields: {},
+ });
+
+ const madeMaterials = madeChildren.map(
+ mapMethodMaterialToQuoteMaterial
+ );
+ const pickedOrBoughtMaterials = unmadeChildren.map(
+ mapMethodMaterialToQuoteMaterial
+ );
+ if (madeMaterials.length > 0) {
+ const madeMaterialIds = await trx
+ .insertInto("quoteMaterial")
+ .values(madeMaterials)
+ .returning(["id"])
+ .execute();
+
+ const quoteMakeMethods = await trx
+ .selectFrom("quoteMakeMethod")
+ .select(["id"])
+ .where(
+ "parentMaterialId",
+ "in",
+ madeMaterialIds.map((m) => m.id)
+ )
+ .execute();
+
+ for (const [index, child] of madeChildren.entries()) {
+ // insert quoteMakeMethod for child
+ const makeMethodId = quoteMakeMethods[index].id ?? null;
+ await traverseMethodToQuote(child, makeMethodId);
+ }
+ }
+
+ if (pickedOrBoughtMaterials.length > 0) {
+ await trx
+ .insertInto("quoteMaterial")
+ .values(pickedOrBoughtMaterials)
+ .execute();
+ }
+ }
+
+ await traverseMethodToQuote(methodTree, quoteMakeMethod.data.id);
+ });
+
+ break;
+ }
+ default:
+ throw new Error(`Invalid type ${type}`);
+ }
+
+ return new Response(
+ JSON.stringify({
+ success: true,
+ }),
+ {
+ headers: { ...corsHeaders, "Content-Type": "application/json" },
+ status: 200,
+ }
+ );
+ } catch (err) {
+ console.error(err);
+ return new Response(JSON.stringify(err), {
+ headers: { ...corsHeaders, "Content-Type": "application/json" },
+ status: 500,
+ });
+ }
+});
+
+type Method = NonNullable<
+ Awaited<ReturnType<typeof getMethodTreeArray>>["data"]
+>[number];
+type MethodTreeItem = {
+ id: string;
+ data: Method;
+ children: MethodTreeItem[];
+};
+
+export async function getMethodTree(
+ client: SupabaseClient<Database>,
+ makeMethodId: string
+): Promise<{ data: MethodTreeItem[] | null; error: PostgrestError | null }> {
+ const items = await getMethodTreeArray(client, makeMethodId);
+ if (items.error) return items;
+
+ const tree = getMethodTreeArrayToTree(items.data);
+
+ return {
+ data: tree,
+ error: null,
+ };
+}
+
+export function getMethodTreeArray(
+ client: SupabaseClient<Database>,
+ makeMethodId: string
+) {
+ return client.rpc("get_method_tree", {
+ uid: makeMethodId,
+ });
+}
+
+function getMethodTreeArrayToTree(items: Method[]): MethodTreeItem[] {
+ function traverseAndRenameIds(node: MethodTreeItem) {
+ const clone = structuredClone(node);
+ clone.id = nanoid(20);
+ clone.children = clone.children.map((n) => traverseAndRenameIds(n));
+ return clone;
+ }
+
+ const rootItems: MethodTreeItem[] = [];
+ const lookup: { [id: string]: MethodTreeItem } = {};
+
+ for (const item of items) {
+ const itemId = item.methodMaterialId;
+ const parentId = item.parentMaterialId;
+
+ if (!Object.prototype.hasOwnProperty.call(lookup, itemId)) {
+ // @ts-ignore - we add data on the next line
+ lookup[itemId] = { id: itemId, children: [] };
+ }
+
+ lookup[itemId]["data"] = item;
+
+ const treeItem = lookup[itemId];
+
+ if (parentId === null || parentId === undefined) {
+ rootItems.push(treeItem);
+ } else {
+ if (!Object.prototype.hasOwnProperty.call(lookup, parentId)) {
+ // @ts-ignore - we don't add data here
+ lookup[parentId] = { id: parentId, children: [] };
+ }
+
+ lookup[parentId]["children"].push(treeItem);
+ }
+ }
+
+ return rootItems.map((item) => traverseAndRenameIds(item));
+}
diff --git a/packages/react/src/Menubar.tsx b/packages/react/src/Menubar.tsx
index f2291e134c..7866643136 100644
--- a/packages/react/src/Menubar.tsx
+++ b/packages/react/src/Menubar.tsx
@@ -2,13 +2,17 @@ import type { ComponentProps } from "react";
import { forwardRef } from "react";
import type { ButtonProps } from "./Button";
import { Button } from "./Button";
+import { cn } from "./utils/cn";
const Menubar = forwardRef<HTMLDivElement, ComponentProps<"div">>(
- ({ children, ...props }, ref) => {
+ ({ children, className, ...props }, ref) => {
return (
<div
{...props}
- className="min-h-[2.5rem] flex items-center bg-card border border-border rounded-lg shadow-sm justify-start p-1 w-full space-x-1 overflow-x-scroll scrollbar-hide"
+ className={cn(
+ "min-h-[2.5rem] flex items-center bg-card border border-border rounded-lg shadow-sm justify-start p-1 w-full space-x-1 overflow-x-scroll scrollbar-hide",
+ className
+ )}
>
{children}
</div>
@@ -20,7 +24,7 @@ Menubar.displayName = "Menubar";
const MenubarItem = forwardRef<HTMLButtonElement, ButtonProps>(
({ children, ...props }, ref) => {
return (
- <Button ref={ref} variant="ghost" {...props}>
+ <Button className="rounded-sm" ref={ref} variant="ghost" {...props}>
{children}
</Button>
);