correzione 2 a eliminazione degli articoli dal macchina/parte/gruppo
This commit is contained in:
parent
b23f7d9da5
commit
c0ee27c5a9
1 changed files with 35 additions and 3 deletions
|
|
@ -585,10 +585,42 @@ export default function MacchineTree() {
|
||||||
macchinaStabilimentoId={showArticlesModal.macchinaStabilimentoId}
|
macchinaStabilimentoId={showArticlesModal.macchinaStabilimentoId}
|
||||||
articoli={showArticlesModal.articoli}
|
articoli={showArticlesModal.articoli}
|
||||||
onClose={() => setShowArticlesModal(null)}
|
onClose={() => setShowArticlesModal(null)}
|
||||||
onArticoloRimosso={() => {
|
onArticoloRimosso={async () => {
|
||||||
fetchArticoliPerMacchina();
|
await fetchArticoliPerMacchina();
|
||||||
window.dispatchEvent(new CustomEvent("articoli-updated"));
|
window.dispatchEvent(new CustomEvent("articoli-updated"));
|
||||||
|
// Aggiorna gli articoli nella modale invece di chiuderla
|
||||||
|
const macchina = nodes.find((n) => n.id === showArticlesModal.macchinaId);
|
||||||
|
if (macchina) {
|
||||||
|
// Ricarica gli articoli per questa macchina
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/art-macchine-parti");
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
const newArticlesByMacchina = data.articoliPerMacchina || {};
|
||||||
|
|
||||||
|
const getDescendantArticles = (id: number): ArticoloAssegnatoMacchina[] => {
|
||||||
|
const children = nodes.filter((n) => n.id_padre === id);
|
||||||
|
let result: ArticoloAssegnatoMacchina[] = [];
|
||||||
|
for (const child of children) {
|
||||||
|
const childArticles = newArticlesByMacchina[child.id] || [];
|
||||||
|
result = [...result, ...childArticles, ...getDescendantArticles(child.id)];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const articoliNodo = newArticlesByMacchina[showArticlesModal.macchinaId] || [];
|
||||||
|
const allArticoli = [...articoliNodo, ...getDescendantArticles(showArticlesModal.macchinaId)];
|
||||||
|
|
||||||
|
setShowArticlesModal({
|
||||||
|
...showArticlesModal,
|
||||||
|
articoli: allArticoli,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Errore ricarica articoli:", err);
|
||||||
setShowArticlesModal(null);
|
setShowArticlesModal(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue