From f06a347dd7afaf6cd72a7df8ed42377da5d28a97 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Thu, 19 Nov 2026 10:57:55 +0000 Subject: [PATCH] feat(dashboard): fold the Lieferkette's components in no product (#1050) (#1060) --- compliance-dashboard/assets/main.css | 31 ++++ compliance-dashboard/src/i18n/texts.rs | 19 +++ .../src/pages/supply_chain.rs | 154 ++++++++++++++++-- docs/guide/lieferkette.md | 7 + 4 files changed, 199 insertions(+), 12 deletions(-) diff --git a/compliance-dashboard/assets/main.css b/compliance-dashboard/assets/main.css index 731a0f2..b1d62ec 100644 --- a/compliance-dashboard/assets/main.css +++ b/compliance-dashboard/assets/main.css @@ -8943,3 +8943,34 @@ span.repo-crumb-name { color: var(--accent); text-decoration: none; } +.chain-fold { + position: absolute; + box-sizing: border-box; + display: flex; + align-items: center; + gap: 12px; + padding: 10px 12px; + font: inherit; + text-align: left; + color: var(--text-primary); + background: var(--bg-elevated); + border: 1px solid var(--border-bright); + border-radius: 14px; + cursor: pointer; +} +.chain-fold:hover { border-color: var(--border-accent); } +.chain-fold-count { + flex: none; + min-width: 34px; + height: 34px; + padding: 0 6px; + box-sizing: border-box; + border-radius: 9px; + display: inline-flex; + align-items: center; + justify-content: center; + font-size: 13px; + font-weight: 700; + color: var(--bg-card); + background: var(--text-tertiary); +} diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 50a0bcd..d2e1801 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -7799,6 +7799,25 @@ pub mod supply_chain { de: "Upload-Link aktiv", en: "Upload link active", }; + pub const UNFOLD: Text = Text { + de: "aufklappen", + en: "show them", + }; + pub const FOLD: Text = Text { + de: "einklappen", + en: "fold them away", + }; + + /// "26 Prüfobjekte ohne Produkt". + pub fn folded(n: usize, lang: Lang) -> String { + match (lang, n) { + (Lang::De, 1) => "1 Prüfobjekt ohne Produkt".to_string(), + (Lang::De, n) => format!("{n} Prüfobjekte ohne Produkt"), + (Lang::En, 1) => "1 target in no product".to_string(), + (Lang::En, n) => format!("{n} targets in no product"), + } + } + pub const DOCUMENTS: Text = Text { de: "Unterlagen", en: "Documents", diff --git a/compliance-dashboard/src/pages/supply_chain.rs b/compliance-dashboard/src/pages/supply_chain.rs index fe910b0..f65cc27 100644 --- a/compliance-dashboard/src/pages/supply_chain.rs +++ b/compliance-dashboard/src/pages/supply_chain.rs @@ -247,6 +247,11 @@ fn delivery_label( Some((class, text)) } +/// Where the box of the components in no product sits: the components' +/// column, and its size. +const FOLD_X: i32 = 420; +const FOLD_SIZE: (i32, i32) = (210, 64); + /// Up to how many components the graph offers its next steps as ghost /// boxes: the first-component state (#1050). const EARLY_COMPONENTS: usize = 2; @@ -353,6 +358,60 @@ fn ghost_boxes( ghosts } +/// The boxes folded away while the workspace has a product: its components +/// in no product, and the suppliers that supply only those. Nothing folds +/// without a product, as there would be nothing left to show. +fn folded_keys(chain: &SupplyChainDto) -> HashSet { + if !chain.nodes.iter().any(|n| n.kind == NodeKind::Project) { + return HashSet::new(); + } + let in_product: HashSet<&str> = chain + .edges + .iter() + .filter(|e| e.kind == EdgeKind::PartOf) + .map(|e| e.from.as_str()) + .collect(); + let mut folded: HashSet = chain + .nodes + .iter() + .filter(|n| n.kind == NodeKind::Target && !in_product.contains(n.key.as_str())) + .map(|n| n.key.clone()) + .collect(); + let suppliers: Vec = chain + .nodes + .iter() + .filter(|n| n.kind == NodeKind::Supplier) + .filter(|n| { + chain + .edges + .iter() + .filter(|e| e.from == n.key) + .all(|e| folded.contains(&e.to)) + }) + .map(|n| n.key.clone()) + .collect(); + folded.extend(suppliers); + folded +} + +/// `chain` without the boxes `keys` and their edges. +fn without(chain: &SupplyChainDto, keys: &HashSet) -> SupplyChainDto { + SupplyChainDto { + nodes: chain + .nodes + .iter() + .filter(|n| !keys.contains(&n.key)) + .cloned() + .collect(), + edges: chain + .edges + .iter() + .filter(|e| !keys.contains(&e.from) && !keys.contains(&e.to)) + .cloned() + .collect(), + } +} + /// A drag in progress: the box, where the pointer started and where the box was. #[derive(Debug, Clone, Copy, PartialEq)] struct Drag { @@ -404,16 +463,16 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element { let can_write = use_can_write(); let portal_url = use_context::>().read().portal_url.clone(); let mut toasts = use_context::(); - let defaults = use_hook(|| default_positions(&chain)); + // The boxes someone placed; every other box takes its computed place, so + // unfolding or a new box never freezes the columns around it. let mut pos = use_signal(|| { - let mut p = defaults.clone(); - for saved in &layout.positions { - if let Some(slot) = p.get_mut(&saved.key) { - *slot = (saved.x, saved.y); - } - } - p + layout + .positions + .iter() + .map(|p| (p.key.clone(), (p.x, p.y))) + .collect::>() }); + let mut unfolded = use_signal(|| false); let first = chain .nodes .iter() @@ -442,8 +501,20 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element { }; let now = chrono::Utc::now(); + let folded = folded_keys(&chain); + let loose = folded.iter().filter(|k| k.starts_with("target:")).count(); + let chain = if unfolded() { + chain.clone() + } else { + without(&chain, &folded) + }; let rel = related(&chain, &selected.read()); - let p = pos.read().clone(); + let mut p = default_positions(&chain); + for (key, at) in pos.read().iter() { + if let Some(slot) = p.get_mut(key) { + *slot = *at; + } + } let by_key: HashMap<&str, &NodeDto> = chain.nodes.iter().map(|n| (n.key.as_str(), n)).collect(); // Read-only roles add nothing, so they see no next steps. let ghosts = if can_write { @@ -451,11 +522,23 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element { } else { Vec::new() }; + // The folded box sits last in the components' column. + let fold_at = (loose > 0).then(|| { + let bottom = chain + .nodes + .iter() + .filter(|n| n.kind == NodeKind::Target) + .filter_map(|n| p.get(&n.key).map(|(_, y)| y + size(n).1)) + .chain(ghosts.iter().filter(|g| g.x == FOLD_X).map(|g| g.y + g.h)) + .max(); + (FOLD_X, bottom.map_or(TOP, |b| b + GAP)) + }); let boxes = chain .nodes .iter() .map(|n| (p.get(&n.key).copied().unwrap_or((0, 0)), size(n))) - .chain(ghosts.iter().map(|g| ((g.x, g.y), (g.w, g.h)))); + .chain(ghosts.iter().map(|g| ((g.x, g.y), (g.w, g.h)))) + .chain(fold_at.map(|at| (at, FOLD_SIZE))); let (width, height) = boxes.fold((0, 0), |(w, h), ((x, y), (nw, nh))| { (w.max(x + nw + MARGIN), h.max(y + nh + MARGIN)) }); @@ -498,7 +581,6 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element { let sel = selected.read().clone(); let picked = by_key.get(sel.as_str()).copied(); - let reset_chain = chain.clone(); rsx! { div { class: "chain-toolbar", @@ -513,7 +595,7 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element { class: "btn btn-secondary", r#type: "button", onclick: move |_| { - pos.set(default_positions(&reset_chain)); + pos.set(HashMap::new()); spawn(async move { if reset_supply_chain_layout().await.is_err() { toasts.push(ToastType::Error, tx::SAVE_FAILED.get(lang).to_string()); @@ -581,6 +663,22 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element { } } } + if let Some((fx, fy)) = fold_at { + button { + class: "chain-fold", + r#type: "button", + style: "left: {fx}px; top: {fy}px; width: {FOLD_SIZE.0}px; height: {FOLD_SIZE.1}px;", + "aria-expanded": if unfolded() { "true" } else { "false" }, + onclick: move |_| unfolded.set(!unfolded()), + span { class: "chain-fold-count", "{loose}" } + span { class: "chain-node-text", + span { class: "chain-node-name", {tx::folded(loose, lang)} } + span { class: "chain-node-sub", + if unfolded() { {tx::FOLD.get(lang)} } else { {tx::UNFOLD.get(lang)} } + } + } + } + } for g in ghosts.iter().cloned() { { let style = format!("left: {}px; top: {}px; width: {}px; height: {}px;", g.x, g.y, g.w, g.h); @@ -1006,6 +1104,38 @@ mod tests { ); } + #[test] + fn components_in_no_product_fold_with_their_own_suppliers() { + use EdgeKind::Supplies; + let mut c = chain(); + c.nodes.push(node("target:loose", NodeKind::Target, None)); + c.nodes.push(node("target:loose2", NodeKind::Target, None)); + c.nodes.push(node("supplier:C", NodeKind::Supplier, None)); + c.edges.push(edge("supplier:C", "target:loose", Supplies)); + // A supplies a component in a product and a loose one: it stays. + c.edges.push(edge("supplier:A", "target:loose2", Supplies)); + + let folded = folded_keys(&c); + + let expected: HashSet = ["target:loose", "target:loose2", "supplier:C"] + .map(String::from) + .into(); + assert_eq!(folded, expected); + let shown = without(&c, &folded); + assert!(shown.nodes.iter().any(|n| n.key == "supplier:A")); + assert!(!shown.edges.iter().any(|e| e.to == "target:loose2")); + assert_eq!(shown.edges.len(), c.edges.len() - 2); + } + + #[test] + fn nothing_folds_without_a_product() { + let c = SupplyChainDto { + nodes: vec![node("target:a", NodeKind::Target, None)], + edges: Vec::new(), + }; + assert!(folded_keys(&c).is_empty()); + } + #[test] fn a_file_size_reads_in_the_language() { assert_eq!(size_text(1_258_291, Lang::De), "1,2 MB"); diff --git a/docs/guide/lieferkette.md b/docs/guide/lieferkette.md index 1af2a6d..7ad5227 100644 --- a/docs/guide/lieferkette.md +++ b/docs/guide/lieferkette.md @@ -35,6 +35,13 @@ Die Linie vom Zulieferer zur Komponente sagt, wie deren SBOM ankommt: SBOM hochgeladen. - **noch keine SBOM** (gestrichelt). +## Prüfobjekte ohne Produkt + +Sobald Ihr Workspace ein Produkt hat, sind Prüfobjekte, die zu keinem +Produkt gehören, in einem Kasten am Ende der Komponenten zusammengefasst +(„26 Prüfobjekte ohne Produkt“), mit den Zulieferern, die nur sie +beliefern. Ein Klick klappt sie auf und wieder ein. + ## Anordnen Ziehen Sie die Kästen mit der Maus, oder wählen Sie einen Kasten mit der