feat(dashboard): the Lieferkette's first steps as ghost boxes (#1050) (#1058)
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Agent (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Dashboard (push) Successful in 5m1s
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Agent (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Dashboard (push) Successful in 5m1s
This commit was merged in pull request #1058.
This commit is contained in:
1 parent
d979fc1644
commit
40fb69072e
8 files changed
+296
-21
No files matched your search
@@ -8783,7 +8783,8 @@ span.repo-crumb-name {
|
||||
.chain-node.assembly {
|
||||
width: 200px;
|
||||
height: 72px;
|
||||
background: var(--accent-muted);
|
||||
/* Opaque, so an edge passing behind it does not show through. */
|
||||
background: color-mix(in srgb, var(--accent) 9%, var(--bg-card));
|
||||
border: 1.5px solid var(--border-accent);
|
||||
}
|
||||
.chain-node.product {
|
||||
@@ -8883,3 +8884,26 @@ span.repo-crumb-name {
|
||||
border-radius: 18px;
|
||||
}
|
||||
.chain-empty p { margin: 0; color: var(--text-secondary); max-width: 60ch; }
|
||||
.chain-edge.ghost { stroke: var(--border-strong); stroke-width: 2; stroke-dasharray: 5 6; }
|
||||
.chain-ghost {
|
||||
position: absolute;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 14px;
|
||||
text-decoration: none;
|
||||
color: var(--accent);
|
||||
background: var(--bg-primary);
|
||||
border: 1.5px dashed var(--border-accent);
|
||||
border-radius: 14px;
|
||||
}
|
||||
.chain-ghost:hover { background: var(--accent-muted); }
|
||||
.chain-ghost.own { color: var(--brand-chevron-top); border-color: var(--border-bright); }
|
||||
.chain-ghost .chain-node-name { color: inherit; }
|
||||
.chain-ghost-plus {
|
||||
flex: none;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
line-height: 1;
|
||||
}
|
||||
@@ -45,8 +45,10 @@ pub enum Route {
|
||||
// `parts` (the default), `cves` or `history`.
|
||||
#[route("/projects/:id?:tab")]
|
||||
MachinePage { id: String, tab: String },
|
||||
#[route("/onboard")]
|
||||
OnboardingPage {},
|
||||
// `?origin=bought` opens the wizard for a component bought in from a
|
||||
// supplier, `own` (or nothing) for the workspace's own.
|
||||
#[route("/onboard?:origin")]
|
||||
OnboardingPage { origin: String },
|
||||
// `?target=<id>` opens the list filtered to one target; a chart of
|
||||
// the findings view (#957) adds its type, severity or folder. The
|
||||
// target comes last: the router writes a `&` after each argument
|
||||
@@ -125,6 +127,14 @@ impl Route {
|
||||
}
|
||||
}
|
||||
|
||||
/// The onboarding wizard; `origin` `bought` preselects a component
|
||||
/// bought in from a supplier.
|
||||
pub fn onboarding(origin: &str) -> Self {
|
||||
Self::OnboardingPage {
|
||||
origin: origin.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The findings list of target `target` (of all targets when empty),
|
||||
/// without a chart's filters.
|
||||
pub fn findings(target: String) -> Self {
|
||||
@@ -180,6 +190,15 @@ mod tests {
|
||||
Ok(Route::OverviewPage {})
|
||||
));
|
||||
assert_eq!(Route::OverviewPage {}.to_string(), "/overview");
|
||||
// The wizard opens for a bought-in component with `?origin=bought`.
|
||||
assert_eq!(
|
||||
Route::from_str("/onboard?origin=bought").ok(),
|
||||
Some(Route::onboarding("bought"))
|
||||
);
|
||||
assert_eq!(
|
||||
Route::from_str("/onboard").ok(),
|
||||
Some(Route::onboarding(""))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -65,7 +65,7 @@ pub fn Sidebar() -> Element {
|
||||
},
|
||||
NavItem {
|
||||
label: nav::ONBOARD,
|
||||
route: Route::OnboardingPage {},
|
||||
route: Route::onboarding(""),
|
||||
icon: rsx! { Icon { icon: BsPlusCircle, width: 18, height: 18 } },
|
||||
runtime_only: false,
|
||||
write_only: true,
|
||||
|
||||
@@ -7799,6 +7799,30 @@ pub mod supply_chain {
|
||||
de: "Upload-Link aktiv",
|
||||
en: "Upload link active",
|
||||
};
|
||||
pub const GHOST_BOUGHT: Text = Text {
|
||||
de: "Zugekaufte Komponente",
|
||||
en: "Bought-in component",
|
||||
};
|
||||
pub const GHOST_BOUGHT_HINT: Text = Text {
|
||||
de: "mit SBOM des Zulieferers",
|
||||
en: "with its supplier's SBOM",
|
||||
};
|
||||
pub const GHOST_OWN: Text = Text {
|
||||
de: "Eigene Software",
|
||||
en: "Your own software",
|
||||
};
|
||||
pub const GHOST_OWN_HINT: Text = Text {
|
||||
de: "Git, Archiv oder SPS-Projekt",
|
||||
en: "Git, archive or PLC project",
|
||||
};
|
||||
pub const GHOST_INVITE: Text = Text {
|
||||
de: "Zulieferer einladen",
|
||||
en: "Invite a supplier",
|
||||
};
|
||||
pub const GHOST_INVITE_HINT: Text = Text {
|
||||
de: "Versionen kommen von selbst",
|
||||
en: "versions arrive by themselves",
|
||||
};
|
||||
pub const SELECTED: Text = Text {
|
||||
de: "Ausgewählter Kasten",
|
||||
en: "Selected box",
|
||||
|
||||
@@ -97,7 +97,7 @@ enum FirstScan {
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn OnboardingPage() -> Element {
|
||||
pub fn OnboardingPage(origin: String) -> Element {
|
||||
let lang = use_lang()();
|
||||
let can_write = use_can_write();
|
||||
let mut step = use_signal(|| 0usize);
|
||||
@@ -106,7 +106,16 @@ pub fn OnboardingPage() -> Element {
|
||||
let mut artifacts = use_signal(Vec::<ArtifactInputDto>::new);
|
||||
|
||||
// "Add artifact" mini-form.
|
||||
let mut new_kind = use_signal(|| "git_repo".to_string());
|
||||
// A component bought in brings its supplier's SBOM (`?origin=bought`).
|
||||
let from_supplier = origin == "bought";
|
||||
let mut new_kind = use_signal(move || {
|
||||
if from_supplier {
|
||||
"supplier_sbom"
|
||||
} else {
|
||||
"git_repo"
|
||||
}
|
||||
.to_string()
|
||||
});
|
||||
let mut new_source = use_signal(String::new);
|
||||
let mut new_branch = use_signal(|| "main".to_string());
|
||||
let mut new_token = use_signal(String::new);
|
||||
@@ -117,7 +126,7 @@ pub fn OnboardingPage() -> Element {
|
||||
let mut pending_files = use_signal(Vec::<PendingFile>::new);
|
||||
let mut staged_count = use_signal(|| 0usize);
|
||||
// A bought-in component and its supplier (#1025).
|
||||
let mut bought = use_signal(|| false);
|
||||
let mut bought = use_signal(move || from_supplier);
|
||||
let mut sup_name = use_signal(String::new);
|
||||
let mut sup_product = use_signal(String::new);
|
||||
let mut sup_version = use_signal(String::new);
|
||||
|
||||
@@ -218,7 +218,7 @@ pub fn OverviewPage() -> Element {
|
||||
h3 { {overview::EMPTY_TITLE.get(lang)} }
|
||||
p { {overview::EMPTY_BODY.get(lang)} }
|
||||
if can_write {
|
||||
Link { to: Route::OnboardingPage {}, class: "btn btn-primary",
|
||||
Link { to: Route::onboarding(""), class: "btn btn-primary",
|
||||
{overview::EMPTY_ACTION.get(lang)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ use dioxus::prelude::*;
|
||||
use compliance_core::cve_groups::SeverityCounts;
|
||||
use compliance_core::models::{ProjectLevel, TargetType};
|
||||
|
||||
use compliance_core::models::auth::AuthInfo;
|
||||
|
||||
use crate::app::Route;
|
||||
use crate::components::no_access::use_can_write;
|
||||
use crate::components::toast::{ToastType, Toasts};
|
||||
@@ -245,6 +247,112 @@ fn delivery_label(
|
||||
Some((class, text))
|
||||
}
|
||||
|
||||
/// Up to how many components the graph offers its next steps as ghost
|
||||
/// boxes: the first-component state (#1050).
|
||||
const EARLY_COMPONENTS: usize = 2;
|
||||
|
||||
/// Where a ghost box leads.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum GhostTo {
|
||||
/// The onboarding wizard, with this origin preselected.
|
||||
Onboard(&'static str),
|
||||
/// The portal, where suppliers are invited.
|
||||
Portal,
|
||||
}
|
||||
|
||||
/// A next step offered as a dashed box beside the real ones.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
struct Ghost {
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: i32,
|
||||
h: i32,
|
||||
to: GhostTo,
|
||||
/// The dashed line from it, if it joins a real box.
|
||||
edge: Option<String>,
|
||||
}
|
||||
|
||||
/// The path of an edge from the right middle of one box to the left middle
|
||||
/// of another.
|
||||
fn curve((x1, y1): (i32, i32), (x2, y2): (i32, i32)) -> String {
|
||||
let dx = ((x2 - x1).abs() / 2).max(50);
|
||||
format!(
|
||||
"M {x1} {y1} C {} {y1}, {} {y2}, {x2} {y2}",
|
||||
x1 + dx,
|
||||
x2 - dx
|
||||
)
|
||||
}
|
||||
|
||||
/// The ghost boxes of the first-component state: while the workspace has at
|
||||
/// most [`EARLY_COMPONENTS`] components, a bought-in component and software
|
||||
/// of its own to add, below the components and joined to the first product;
|
||||
/// and, where the portal can invite one (`portal`) and no supplier uploads
|
||||
/// through a link yet, a supplier to invite, joined to a bought component.
|
||||
fn ghost_boxes(
|
||||
chain: &SupplyChainDto,
|
||||
at: &HashMap<String, (i32, i32)>,
|
||||
portal: bool,
|
||||
) -> Vec<Ghost> {
|
||||
let targets: Vec<&NodeDto> = chain
|
||||
.nodes
|
||||
.iter()
|
||||
.filter(|n| n.kind == NodeKind::Target)
|
||||
.collect();
|
||||
if targets.len() > EARLY_COMPONENTS {
|
||||
return Vec::new();
|
||||
}
|
||||
let bottom = |kind: NodeKind| {
|
||||
chain
|
||||
.nodes
|
||||
.iter()
|
||||
.filter(|n| n.kind == kind)
|
||||
.filter_map(|n| at.get(&n.key).map(|(_, y)| y + size(n).1))
|
||||
.max()
|
||||
.map_or(TOP, |b| b + GAP)
|
||||
};
|
||||
let product = chain
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|n| n.kind == NodeKind::Project && n.level != Some(ProjectLevel::Component))
|
||||
.and_then(|n| at.get(&n.key).map(|(x, y)| (x - 6, y + size(n).1 / 2)));
|
||||
let (tx, (tw, th)) = (420, (210, 84));
|
||||
let mut ghosts = Vec::new();
|
||||
let mut y = bottom(NodeKind::Target);
|
||||
for origin in ["bought", "own"] {
|
||||
ghosts.push(Ghost {
|
||||
x: tx,
|
||||
y,
|
||||
w: tw,
|
||||
h: th,
|
||||
to: GhostTo::Onboard(origin),
|
||||
edge: product.map(|to| curve((tx + tw, y + th / 2), to)),
|
||||
});
|
||||
y += th + GAP;
|
||||
}
|
||||
let invited = chain.edges.iter().any(|e| {
|
||||
e.delivery
|
||||
.as_ref()
|
||||
.is_some_and(|d| d.how == DeliveryKind::Invite)
|
||||
});
|
||||
if portal && !invited {
|
||||
let (sx, (sw, sh)) = (32, (190, 76));
|
||||
let sy = bottom(NodeKind::Supplier);
|
||||
let bought = targets
|
||||
.iter()
|
||||
.find(|t| t.bought)
|
||||
.and_then(|t| at.get(&t.key).map(|(x, y)| (x - 6, y + size(t).1 / 2)));
|
||||
ghosts.push(Ghost {
|
||||
x: sx,
|
||||
y: sy,
|
||||
w: sw,
|
||||
h: sh,
|
||||
to: GhostTo::Portal,
|
||||
edge: bought.map(|to| curve((sx + sw, sy + sh / 2), to)),
|
||||
});
|
||||
}
|
||||
ghosts
|
||||
}
|
||||
|
||||
/// A drag in progress: the box, where the pointer started and where the box was.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
struct Drag {
|
||||
@@ -276,7 +384,7 @@ pub fn SupplyChainPage() -> Element {
|
||||
} else {
|
||||
div { class: "chain-empty",
|
||||
p { {tx::EMPTY.get(lang)} }
|
||||
Link { class: "btn btn-primary", to: Route::OnboardingPage {}, {tx::ADD.get(lang)} }
|
||||
Link { class: "btn btn-primary", to: Route::onboarding(""), {tx::ADD.get(lang)} }
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -294,6 +402,7 @@ pub fn SupplyChainPage() -> Element {
|
||||
fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element {
|
||||
let lang = use_lang()();
|
||||
let can_write = use_can_write();
|
||||
let portal_url = use_context::<Signal<AuthInfo>>().read().portal_url.clone();
|
||||
let mut toasts = use_context::<Toasts>();
|
||||
let defaults = use_hook(|| default_positions(&chain));
|
||||
let mut pos = use_signal(|| {
|
||||
@@ -336,9 +445,18 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element {
|
||||
let rel = related(&chain, &selected.read());
|
||||
let p = pos.read().clone();
|
||||
let by_key: HashMap<&str, &NodeDto> = chain.nodes.iter().map(|n| (n.key.as_str(), n)).collect();
|
||||
let (width, height) = chain.nodes.iter().fold((0, 0), |(w, h), n| {
|
||||
let (x, y) = p.get(&n.key).copied().unwrap_or((0, 0));
|
||||
let (nw, nh) = size(n);
|
||||
// Read-only roles add nothing, so they see no next steps.
|
||||
let ghosts = if can_write {
|
||||
ghost_boxes(&chain, &p, !portal_url.is_empty())
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
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))));
|
||||
let (width, height) = boxes.fold((0, 0), |(w, h), ((x, y), (nw, nh))| {
|
||||
(w.max(x + nw + MARGIN), h.max(y + nh + MARGIN))
|
||||
});
|
||||
|
||||
@@ -356,7 +474,6 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element {
|
||||
let ((ax, ay), (bx, by)) = (p.get(&e.from)?, p.get(&e.to)?);
|
||||
let (x1, y1) = (ax + size(a).0, ay + size(a).1 / 2);
|
||||
let (x2, y2) = (bx - 6, by + size(b).1 / 2);
|
||||
let dx = ((x2 - x1).abs() / 2).max(50);
|
||||
let on = rel.contains(&e.from) && rel.contains(&e.to);
|
||||
let (class, marker) = match (e.kind, e.delivery.as_ref().map(|d| d.how), on) {
|
||||
(EdgeKind::Supplies, Some(DeliveryKind::Invite), _) => {
|
||||
@@ -370,11 +487,7 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element {
|
||||
(EdgeKind::PartOf, _, false) => ("chain-edge part", "url(#chain-head-grey)"),
|
||||
};
|
||||
Some(Line {
|
||||
d: format!(
|
||||
"M {x1} {y1} C {} {y1}, {} {y2}, {x2} {y2}",
|
||||
x1 + dx,
|
||||
x2 - dx
|
||||
),
|
||||
d: curve((x1, y1), (x2, y2)),
|
||||
class: if on { class } else { "chain-edge dim" },
|
||||
marker,
|
||||
label: delivery_label(e, &now, lang)
|
||||
@@ -409,7 +522,7 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element {
|
||||
},
|
||||
{tx::RESET.get(lang)}
|
||||
}
|
||||
Link { class: "btn btn-primary", to: Route::OnboardingPage {}, {tx::ADD.get(lang)} }
|
||||
Link { class: "btn btn-primary", to: Route::onboarding(""), {tx::ADD.get(lang)} }
|
||||
}
|
||||
}
|
||||
div { class: "chain-body",
|
||||
@@ -462,6 +575,36 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element {
|
||||
for line in lines.iter() {
|
||||
path { d: "{line.d}", class: "{line.class}", "marker-end": "{line.marker}" }
|
||||
}
|
||||
for g in ghosts.iter() {
|
||||
if let Some(d) = g.edge.clone() {
|
||||
path { d: "{d}", class: "chain-edge ghost", "marker-end": "url(#chain-head-faint)" }
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
let (title, hint, class) = match g.to {
|
||||
GhostTo::Onboard("bought") => (tx::GHOST_BOUGHT, tx::GHOST_BOUGHT_HINT, "chain-ghost"),
|
||||
GhostTo::Onboard(_) => (tx::GHOST_OWN, tx::GHOST_OWN_HINT, "chain-ghost own"),
|
||||
GhostTo::Portal => (tx::GHOST_INVITE, tx::GHOST_INVITE_HINT, "chain-ghost"),
|
||||
};
|
||||
let body = rsx! {
|
||||
span { class: "chain-ghost-plus", "aria-hidden": "true", "+" }
|
||||
span { class: "chain-node-text",
|
||||
span { class: "chain-node-name", {title.get(lang)} }
|
||||
span { class: "chain-node-sub", {hint.get(lang)} }
|
||||
}
|
||||
};
|
||||
match g.to {
|
||||
GhostTo::Onboard(origin) => rsx! {
|
||||
Link { class: "{class}", style: "{style}", to: Route::onboarding(origin), {body} }
|
||||
},
|
||||
GhostTo::Portal => rsx! {
|
||||
a { class: "{class}", style: "{style}", href: "{portal_url}", {body} }
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
for line in lines.iter() {
|
||||
if let Some((class, text, x, y)) = line.label.clone() {
|
||||
@@ -719,6 +862,62 @@ mod tests {
|
||||
assert!(rel.contains("project:p1") && !rel.contains("supplier:B"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_first_component_offers_the_next_steps() {
|
||||
use EdgeKind::{PartOf, Supplies};
|
||||
let mut drive = node("target:drive", NodeKind::Target, None);
|
||||
drive.bought = true;
|
||||
let first = SupplyChainDto {
|
||||
nodes: vec![
|
||||
node("supplier:A", NodeKind::Supplier, None),
|
||||
drive,
|
||||
node("project:p1", NodeKind::Project, Some(ProjectLevel::Product)),
|
||||
],
|
||||
edges: vec![
|
||||
edge("supplier:A", "target:drive", Supplies),
|
||||
edge("target:drive", "project:p1", PartOf),
|
||||
],
|
||||
};
|
||||
let at = default_positions(&first);
|
||||
|
||||
let ghosts = ghost_boxes(&first, &at, true);
|
||||
|
||||
let to: Vec<GhostTo> = ghosts.iter().map(|g| g.to).collect();
|
||||
assert_eq!(
|
||||
to,
|
||||
[
|
||||
GhostTo::Onboard("bought"),
|
||||
GhostTo::Onboard("own"),
|
||||
GhostTo::Portal
|
||||
]
|
||||
);
|
||||
let drive_bottom = at["target:drive"].1 + 84;
|
||||
assert!(ghosts[0].y >= drive_bottom + GAP, "below the component");
|
||||
assert!(ghosts[1].y >= ghosts[0].y + ghosts[0].h + GAP);
|
||||
assert!(ghosts[0].edge.is_some(), "joined to the product");
|
||||
assert!(ghosts[2].edge.is_some(), "joined to the bought component");
|
||||
assert!(
|
||||
ghosts[2].y >= at["supplier:A"].1 + 64 + GAP,
|
||||
"below the supplier"
|
||||
);
|
||||
|
||||
// Without a portal there is nowhere to invite from.
|
||||
assert_eq!(ghost_boxes(&first, &at, false).len(), 2);
|
||||
// A supplier already uploading through a link needs no invite.
|
||||
let mut linked = first.clone();
|
||||
linked.edges[0].delivery.as_mut().unwrap().how = DeliveryKind::Invite;
|
||||
assert_eq!(ghost_boxes(&linked, &at, true).len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_grown_supply_chain_offers_no_ghosts() {
|
||||
let c = chain();
|
||||
assert!(
|
||||
ghost_boxes(&c, &default_positions(&c), true).is_empty(),
|
||||
"three components"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_cve_state_names_the_worst() {
|
||||
let counts = |critical, high| SeverityCounts {
|
||||
|
||||
@@ -137,7 +137,7 @@ pub fn TargetsPage() -> Element {
|
||||
|
||||
div { class: "page-actions",
|
||||
if can_write {
|
||||
Link { to: Route::OnboardingPage {}, class: "btn btn-primary",
|
||||
Link { to: Route::onboarding(""), class: "btn btn-primary",
|
||||
{tx::ADD.get(lang)}
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,7 @@ pub fn TargetsPage() -> Element {
|
||||
p { {tx::EMPTY.get(lang)} }
|
||||
div { class: "targets-empty-actions",
|
||||
if can_write {
|
||||
Link { to: Route::OnboardingPage {}, class: "btn btn-primary",
|
||||
Link { to: Route::onboarding(""), class: "btn btn-primary",
|
||||
{tx::EMPTY_ACTION.get(lang)}
|
||||
}
|
||||
DemoTargetsButton {
|
||||
|
||||
Reference in new issue
Block a user