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
fix(settings): repair company org-chart interactivity and list collapse (#1263)
Siddharth Gaikwad969cb49eeee9
diff --git a/apps/erp/app/modules/settings/ui/Companies/CompaniesListView.tsx b/apps/erp/app/modules/settings/ui/Companies/CompaniesListView.tsxindex 8a38c8bd16..9496238d4c 100644--- a/apps/erp/app/modules/settings/ui/Companies/CompaniesListView.tsx+++ b/apps/erp/app/modules/settings/ui/Companies/CompaniesListView.tsx@@ -1,11 +1,13 @@import { CountryFlag } from "@carbon/form";import {+ cn,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuTrigger,IconButton} from "@carbon/react";+import { useState } from "react";import {LuBuilding2,LuChevronRight,@@ -36,6 +38,8 @@ function CompaniesRow({onAddChild: (parentId: string) => void;}) {const children = companies.filter((s) => s.parentCompanyId === company.id);+ const hasChildren = children.length > 0;+ const [expanded, setExpanded] = useState(true);const isElimination = company.isEliminationEntity;const canAddChild = !isElimination;const canDelete = !!company.parentCompanyId;@@ -47,10 +51,23 @@ function CompaniesRow({className="flex items-center gap-3 border-b border-border px-4 py-3 transition-colors hover:bg-accent/50"style={{ paddingLeft: `${depth * 28 + 16}px` }}>- {children.length > 0 ? (- <LuChevronRight className="size-4 text-muted-foreground" />+ {hasChildren ? (+ <button+ type="button"+ onClick={() => setExpanded((prev) => !prev)}+ aria-expanded={expanded}+ aria-label={expanded ? "Collapse" : "Expand"}+ className="flex size-4 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground"+ >+ <LuChevronRight+ className={cn(+ "size-4 transition-transform",+ expanded && "rotate-90"+ )}+ />+ </button>) : (- <div className="size-4" />+ <div className="size-4 shrink-0" />)}<div className="flex size-8 shrink-0 items-center justify-center bg-muted">@@ -110,16 +127,18 @@ function CompaniesRow({)}</div>- {children.map((child) => (- <CompaniesRow- key={child.id}- company={child}- companies={companies}- depth={depth + 1}- onDelete={onDelete}- onAddChild={onAddChild}- />- ))}+ {hasChildren &&+ expanded &&+ children.map((child) => (+ <CompaniesRow+ key={child.id}+ company={child}+ companies={companies}+ depth={depth + 1}+ onDelete={onDelete}+ onAddChild={onAddChild}+ />+ ))}</div>);}diff --git a/apps/erp/app/modules/settings/ui/Companies/CompaniesTreeView.tsx b/apps/erp/app/modules/settings/ui/Companies/CompaniesTreeView.tsxindex f5dc3f8f83..ff772bc726 100644--- a/apps/erp/app/modules/settings/ui/Companies/CompaniesTreeView.tsx+++ b/apps/erp/app/modules/settings/ui/Companies/CompaniesTreeView.tsx@@ -6,9 +6,14 @@ import {type Edge,type Node,type NodeTypes,+ type OnEdgesChange,+ type OnNodesChange,ReactFlow,+ ReactFlowProvider,useEdgesState,- useNodesState+ useNodesInitialized,+ useNodesState,+ useReactFlow} from "@xyflow/react";import { useEffect, useMemo } from "react";import "@xyflow/react/dist/style.css";@@ -20,6 +25,12 @@ const nodeTypes: NodeTypes = {subsidiary: CompanyNode};+const fitViewOptions = {+ padding: 0.3,+ maxZoom: 1.2,+ minZoom: 0.3+};+interface CompaniesTreeViewProps {companies: Company[];onEdit: (id: string) => void;@@ -27,6 +38,64 @@ interface CompaniesTreeViewProps {onAddChild: (parentId: string) => void;}+function CompaniesFlow({+ nodes,+ edges,+ onNodesChange,+ onEdgesChange+}: {+ nodes: Node[];+ edges: Edge[];+ onNodesChange: OnNodesChange;+ onEdgesChange: OnEdgesChange;+}) {+ const { fitView } = useReactFlow();+ const nodesInitialized = useNodesInitialized();++ // `fitView` as a prop only fits once during init, and races the container /+ // node measurement — so the diagram lands off-center on save and on every+ // return to this tab (the tab content unmounts/remounts). `useNodesInitialized`+ // flips to true only after the nodes have real measured dimensions, and re-runs+ // whenever `nodes` changes, so re-fitting here reliably re-centers on mount,+ // on tab switch, and after adding/removing a company.+ useEffect(() => {+ if (!nodesInitialized || nodes.length === 0) return;+ fitView(fitViewOptions);+ }, [nodesInitialized, nodes, fitView]);++ return (+ <ReactFlow+ nodes={nodes}+ edges={edges}+ onNodesChange={onNodesChange}+ onEdgesChange={onEdgesChange}+ nodeTypes={nodeTypes}+ connectionLineType={ConnectionLineType.SmoothStep}+ fitView+ fitViewOptions={fitViewOptions}+ nodesDraggable={false}+ nodesConnectable={false}+ elementsSelectable={false}+ panOnScroll+ zoomOnScroll+ minZoom={0.15}+ maxZoom={2}+ proOptions={{ hideAttribution: true }}+ >+ <Controls+ showInteractive={false}+ className="!bg-card !border-border !shadow-sm [&>button]:!bg-card [&>button]:!border-border [&>button]:!text-foreground [&>button:hover]:!bg-accent"+ />+ <Background+ variant={BackgroundVariant.Dots}+ gap={20}+ size={1}+ color="hsl(var(--border))"+ />+ </ReactFlow>+ );+}+export function CompaniesTreeView({companies,onEdit,@@ -77,39 +146,14 @@ export function CompaniesTreeView({return (<div className="h-[calc(100dvh-(var(--header-height))-61px)] w-full overflow-hidden">- <ReactFlow- nodes={nodes}- edges={edges}- onNodesChange={onNodesChange}- onEdgesChange={onEdgesChange}- nodeTypes={nodeTypes}- connectionLineType={ConnectionLineType.SmoothStep}- fitView- fitViewOptions={{- padding: 0.3,- maxZoom: 1.2,- minZoom: 0.3- }}- nodesDraggable={false}- nodesConnectable={false}- elementsSelectable={false}- panOnScroll- zoomOnScroll- minZoom={0.15}- maxZoom={2}- proOptions={{ hideAttribution: true }}- >- <Controls- showInteractive={false}- className="!bg-card !border-border !shadow-sm [&>button]:!bg-card [&>button]:!border-border [&>button]:!text-foreground [&>button:hover]:!bg-accent"- />- <Background- variant={BackgroundVariant.Dots}- gap={20}- size={1}- color="hsl(var(--border))"+ <ReactFlowProvider>+ <CompaniesFlow+ nodes={nodes}+ edges={edges}+ onNodesChange={onNodesChange}+ onEdgesChange={onEdgesChange}/>- </ReactFlow>+ </ReactFlowProvider></div>);}diff --git a/apps/erp/app/modules/settings/ui/Companies/CompanyNode.tsx b/apps/erp/app/modules/settings/ui/Companies/CompanyNode.tsxindex 42d628f847..7bad504d98 100644--- a/apps/erp/app/modules/settings/ui/Companies/CompanyNode.tsx+++ b/apps/erp/app/modules/settings/ui/Companies/CompanyNode.tsx@@ -27,7 +27,10 @@ function CompanyNodeComponent({ data }: NodeProps & { data: CompanyNodeData }) {const isElimination = company.isEliminationEntity;return (- <div className="group relative">+ // pointer-events-auto: the flow marks non-interactive nodes (not+ // selectable/draggable/connectable) as `pointer-events: none`, which+ // otherwise swallows hover + clicks on the actions menu below.+ <div className="group relative pointer-events-auto"><Handletype="target"position={Position.Top}@@ -40,7 +43,10 @@ function CompanyNodeComponent({ data }: NodeProps & { data: CompanyNodeData }) {transition-shadow hover:shadow-md${isElimination ? "border-dashed border-muted-foreground/30" : "border-border"}`}- style={{ minWidth: isElimination ? 140 : 170, maxWidth: 220 }}+ // Fixed width matches the dimensions dagre lays out with+ // (see layout-utils), so the top/bottom handles sit at the node's+ // true center and edges connect cleanly.+ style={{ width: isElimination ? 160 : 200 }}><div className="flex size-9 shrink-0 items-center justify-center rounded-md bg-muted">{company.countryCode && !isElimination ? (