import streamlit as st def ajouter_produit(G): st.markdown("## Ajouter un nouveau produit final") new_prod = st.text_input("Nom du nouveau produit (unique)", key="new_prod") if new_prod: ops_dispo = sorted([ n for n, d in G.nodes(data=True) if d.get("niveau") == "10" and any(G.has_edge(p, n) and G.nodes[p].get("niveau") == "0" for p in G.predecessors(n)) ]) sel_new_op = st.selectbox("Opération d'assemblage (optionnelle)", ["-- Aucune --"] + ops_dispo, index=0) niveau1 = sorted([n for n, d in G.nodes(data=True) if d.get("niveau") == "1"]) sel_comps = st.multiselect("Composants à lier", options=niveau1) if st.button("Créer le produit"): G.add_node(new_prod, niveau="0", personnalisation="oui", label=new_prod) if sel_new_op != "-- Aucune --": G.add_edge(new_prod, sel_new_op) for comp in sel_comps: G.add_edge(new_prod, comp) st.success(f"{new_prod} ajouté.") return G