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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
wip: add collapsible sidebar layout for quote
Brad Barbinf9d24d9576d0
diff --git a/apps/carbon/app/components/Layout/Navigation/CollapsibleSidebar.tsx b/apps/carbon/app/components/Layout/Navigation/CollapsibleSidebar.tsxindex 059f53acad..d07057e3d9 100644--- a/apps/carbon/app/components/Layout/Navigation/CollapsibleSidebar.tsx+++ b/apps/carbon/app/components/Layout/Navigation/CollapsibleSidebar.tsx@@ -7,23 +7,28 @@ import {useDisclosure,} from "@carbon/react";import { motion } from "framer-motion";-import type { PropsWithChildren } from "react";+import { useMemo, type PropsWithChildren } from "react";import { TbArrowBarLeft, TbArrowBarRight } from "react-icons/tb";-const variants = {- visible: {- width: 180,- },- hidden: {- width: 4,- },-};--export const CollapsibleSidebar = ({ children }: PropsWithChildren<{}>) => {+export const CollapsibleSidebar = ({+ children,+ width = 180,+}: PropsWithChildren<{ width?: number }>) => {const sidebar = useDisclosure({defaultIsOpen: true,});+ const variants = useMemo(() => {+ return {+ visible: {+ width,+ },+ hidden: {+ width: 4,+ },+ };+ }, [width]);+return (<TooltipProvider><motion.divdiff --git a/apps/carbon/app/modules/parts/ui/Routing/PartsTree.tsx b/apps/carbon/app/modules/parts/ui/Routing/PartsTree.tsxindex 4eed184684..97750c9da2 100644--- a/apps/carbon/app/modules/parts/ui/Routing/PartsTree.tsx+++ b/apps/carbon/app/modules/parts/ui/Routing/PartsTree.tsx@@ -16,11 +16,11 @@ const data: PartsTreeNode[] = [children: [{id: "F505555",- type: "folder",+ type: "file",},{id: "F505556",- type: "folder",+ type: "file",},],},diff --git a/apps/carbon/app/modules/sales/types.ts b/apps/carbon/app/modules/sales/types.tsindex e8e7d82c2e..89973fc9e6 100644--- a/apps/carbon/app/modules/sales/types.ts+++ b/apps/carbon/app/modules/sales/types.ts@@ -47,4 +47,4 @@ export type QuotationLine = NonNullable<Awaited<ReturnType<typeof getQuoteLines>>["data"]>[number];-export type QuotationStatus = Database["public"]["Enums"]["quoteStatus"];+export type QuotationStatusType = Database["public"]["Enums"]["quoteStatus"];diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsxindex 7e69d42e05..dba3768674 100644--- a/apps/carbon/app/routes/x+/quote+/$id.tsx+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx@@ -1,23 +1,41 @@+import {+ Button,+ HStack,+ Heading,+ IconButton,+ Input,+ Menubar,+ MenubarItem,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+ VStack,+ useMount,+} from "@carbon/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";import { json, redirect } from "@remix-run/node";-import { Outlet, useLoaderData } from "@remix-run/react";-import { useEffect } from "react";+import { useLoaderData } from "@remix-run/react";+import { useEffect, useState } from "react";+import { IoMdAdd } from "react-icons/io";+import { CollapsibleSidebar } from "~/components/Layout/Navigation/CollapsibleSidebar";import { getLocationsList } from "~/modules/resources";import {- QuotationHeader,- QuotationSidebar,+ QuotationStatus,getQuote,getQuoteExternalDocuments,getQuoteInternalDocuments,getQuoteLines,useQuotationTotals,} from "~/modules/sales";+import { requirePermissions } from "~/services/auth";import { flash } from "~/services/session.server";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";import { error } from "~/utils/result";+import { RxChevronDown } from "react-icons/rx";+export const handle: Handle = {breadcrumb: "Quotations",to: path.to.quotes,@@ -85,12 +103,149 @@ export default function QuotationRoute() {}, [quotationLines, setQuotationTotals]);return (- <>- <QuotationHeader />+ <div className="grid grid-cols-1 md:grid-cols-[auto_1fr] w-full">+ <CollapsibleSidebar width={260}>+ <VStack className="border-b border-border p-4" spacing={0}>+ <Heading size="h3" noOfLines={1}>+ QUO000001+ </Heading>+ <QuotationStatus status="Draft" />+ </VStack>+ <VStack className="border-b border-border p-2" spacing={0}>+ <HStack className="w-full justify-between">+ <Input className="flex-1" placeholder="Search" size="sm" />+ <Tooltip>+ <TooltipTrigger>+ <IconButton+ aria-label="Add Quote Line"+ variant="secondary"+ icon={<IoMdAdd />}+ />+ </TooltipTrigger>+ <TooltipContent>Add Quote Line</TooltipContent>+ </Tooltip>+ </HStack>+ </VStack>+ <VStack className="p-2 w-full">+ <BillOfMaterialExplorer />+ </VStack>+ </CollapsibleSidebar>+ <div className="p-4">+ <Menubar>+ <MenubarItem asChild>+ <a+ target="_blank"+ href={path.to.file.quote("TODO")}+ rel="noreferrer"+ >+ Preview+ </a>+ </MenubarItem>+ </Menubar>+ </div>+ {/* <QuotationHeader /><div className="grid grid-cols-1 md:grid-cols-[1fr_4fr] h-full w-full gap-4"><QuotationSidebar /><Outlet />- </div>- </>+ </div> */}+ </div>);}++type BillOfMaterialNode = {+ id: string;+ type: "folder" | "file";+ children?: BillOfMaterialNode[];+};++const data: BillOfMaterialNode[] = [+ {+ id: "QUO000001",+ type: "folder",+ children: [+ {+ id: "F505555",+ type: "folder",+ },+ {+ id: "F505556",+ type: "folder",+ },+ ],+ },+];++const BillOfMaterialExplorer = () => {+ const [expandedNodes, setExpandedNodes] = useState<Record<string, boolean>>(+ {}+ );++ useMount(() => {+ const map: Record<string, boolean> = {};+ const traverse = (node: BillOfMaterialNode[]) => {+ node.forEach((n) => {+ map[n.id] = true; // open all nodes by default;+ if (n.children) {+ traverse(n.children);+ }+ });+ };++ traverse(data);+ setExpandedNodes(map);+ });++ const toggleNode = (id: string) => {+ setExpandedNodes((prev) => ({+ ...prev,+ [id]: !prev[id],+ }));+ };++ const renderBillOfMaterial = (+ data: BillOfMaterialNode[],+ level: number = 0+ ) => {+ return data.map((node) => {+ return (+ <div className="w-full" role="group" key={node.id}>+ <HStack+ className="items-stretch w-full"+ spacing={0}+ style={{+ paddingLeft: `calc(${0.5 * level}rem)`,+ }}+ >+ <IconButton+ aria-label={expandedNodes[node.id] ? "Collapse" : "Expand"}+ onClick={() => toggleNode(node.id)}+ isDisabled={!node.children}+ icon={<RxChevronDown />}+ style={{+ transition: "transform .25s ease",+ transform:+ expandedNodes[node.id] || !node.children+ ? undefined+ : "rotate(-0.25turn)",+ }}+ variant="ghost"+ />++ <Button variant="ghost" className="flex-1 justify-start">+ {node.id}+ </Button>+ </HStack>+ {node.children &&+ expandedNodes[node.id] &&+ renderBillOfMaterial(node.children, level + 1)}+ </div>+ );+ });+ };++ return (+ <div className="w-full h-full overflow-auto" role="tree">+ {renderBillOfMaterial(data)}+ </div>+ );+};diff --git a/apps/carbon/app/routes/x+/quote+/_layout.tsx b/apps/carbon/app/routes/x+/quote+/_layout.tsxindex a858b9c21f..223df510cc 100644--- a/apps/carbon/app/routes/x+/quote+/_layout.tsx+++ b/apps/carbon/app/routes/x+/quote+/_layout.tsx@@ -16,7 +16,7 @@ export const handle: Handle = {export default function QuotationRoute() {return (- <VStack spacing={4} className="h-full p-4">+ <VStack spacing={4} className="h-full"><Outlet /></VStack>);diff --git a/packages/react/src/Menubar.tsx b/packages/react/src/Menubar.tsxindex 7c6e580327..e8451c62d3 100644--- a/packages/react/src/Menubar.tsx+++ b/packages/react/src/Menubar.tsx@@ -8,7 +8,7 @@ const Menubar = forwardRef<HTMLDivElement, ComponentProps<"div">>(return (<div{...props}- className="flex items-center bg-card border border-border rounded-md shadow-sm justify-start p-1 w-full space-x-1"+ className="flex items-center bg-card border border-border rounded-lg shadow-sm justify-start p-1 w-full space-x-1">{children}</div>