From 50c18f0913ce794ffd95a2177f5663efcfbab5c1 Mon Sep 17 00:00:00 2001 From: AV77web Date: Fri, 29 May 2026 15:59:54 +0200 Subject: [PATCH] inserito filtro stabilimento per MacchineTree.tsx --- src/components/MacchineTree.tsx | 72 +++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/src/components/MacchineTree.tsx b/src/components/MacchineTree.tsx index bf6691a..773df16 100644 --- a/src/components/MacchineTree.tsx +++ b/src/components/MacchineTree.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useEffect, useCallback } from "react"; +import { useState, useEffect, useCallback, useMemo } from "react"; import type { MacchinaWithDetails, ArticoliPerMacchina } from "@/src/types/macchina"; import type { Stabilimento } from "@/src/types/stabilimento"; import TreeNode from "./TreeNode"; @@ -13,6 +13,8 @@ export default function MacchineTree() { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [selectedStabilimento, setSelectedStabilimento] = useState(null); + const [copiedNodeId, setCopiedNodeId] = useState(null); const [isCloning, setIsCloning] = useState(false); @@ -66,7 +68,10 @@ export default function MacchineTree() { const handleAddMachine = () => { setEditingMacchina(null); - setParentInfo({ parentId: null, parentStabilimento: null }); + setParentInfo({ + parentId: null, + parentStabilimento: selectedStabilimento?.id || null + }); setShowModal(true); }; @@ -198,7 +203,15 @@ export default function MacchineTree() { console.log("Drop article on machine:", macchinaId, article); }; - const rootNodes = nodes.filter((n) => n.id_padre === null); + const filteredNodes = useMemo(() => { + if (!selectedStabilimento) return nodes; + return nodes.filter((n) => n.id_stabilimento === selectedStabilimento.id); + }, [nodes, selectedStabilimento]); + + const rootNodes = filteredNodes.filter((n) => n.id_padre === null); + + const filteredCount = filteredNodes.length; + const totalCount = nodes.length; return (
@@ -207,7 +220,10 @@ export default function MacchineTree() {

Macchine

- {nodes.length} elementi nell'albero + {selectedStabilimento + ? `${filteredCount} di ${totalCount} elementi` + : `${totalCount} elementi nell'albero` + }

+ {/* Filtro Stabilimento */} +
+ +
+ + {stabilimenti.map((stab) => ( + + ))} +
+
+ {/* Indicatore clonazione */} {isCloning && (
@@ -270,9 +320,17 @@ export default function MacchineTree() { -

Nessuna macchina presente

+

+ {selectedStabilimento + ? `Nessuna macchina in "${selectedStabilimento.descrizione}"` + : "Nessuna macchina presente" + } +

- Clicca sul pulsante + per aggiungere la prima macchina + {selectedStabilimento + ? "Seleziona un altro stabilimento o aggiungi una nuova macchina" + : "Clicca sul pulsante + per aggiungere la prima macchina" + }