Files
pruefwerk/compliance-dashboard/src/app.rs
T
Sharang ParnerkarandClaude Opus 5.5 bb0a1d8aea
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 5m9s
CI / Check (pull_request) Successful in 21m47s
feat(dashboard): the Lieferkette page (#1053)
The supply chain as a graph the customer arranges (#1050), from the
approved mockup:

- a "Lieferkette" entry after the overview; columns for suppliers,
  components, assemblies and products, curved edges with the delivery on a
  supplier's (upload link with version and age, upload, no SBOM yet), the
  open CVEs on every box, in-house components marked violet, products with
  a picture slot;
- the default layout keeps a supplier beside its components and a project
  beside its parts, orders components by where their projects land (two
  barycentre passes) and leaves room for the labels between columns;
- boxes drag with the pointer or move with the arrow keys (20 px); the
  arrangement is saved on release and kept per workspace; "Anordnung
  zurücksetzen" goes back to the columns; read-only roles cannot move;
- a click highlights everything upstream and downstream; the panel shows
  the box, its CVEs, what it is made of or part of, and a link to the
  target or product;
- the graph scrolls inside its box on a phone (`.main-content` now has
  `min-width: 0`, so wide content no longer widens the page);
- docs: guide/lieferkette.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
2026-11-19 10:23:29 +01:00

338 lines
12 KiB
Rust

use dioxus::prelude::*;
use compliance_core::models::inbox::Bucket;
use crate::components::app_shell::AppShell;
use crate::pages::target_views::RepoView;
use crate::pages::*;
#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
#[allow(clippy::enum_variant_names)]
pub enum Route {
#[layout(AppShell)]
// The landing page: the open decisions (#950). `?target=<id>` opens
// one target's, `&bucket=` one bucket (`today`, `this_week`, ...).
#[route("/?:target&:bucket")]
HeutePage { target: String, bucket: String },
#[route("/overview")]
OverviewPage {},
// The supply chain as a graph the customer arranges (#1050).
#[route("/supply-chain")]
SupplyChainPage {},
#[route("/targets")]
TargetsPage {},
#[route("/targets/:id")]
TargetPage { id: String },
// The target's views (#957), one tab each (`findings`, `cves`,
// `components`, `licences`, `cra`, `history`; see `RepoView`). On the
// CVE tab `?cve_severity=high&cve_vex=open` opens the CVE list
// narrowed to that cell of the grid (`all` leaves a side open,
// neither shows the grid); on the CRA tab `?control=cra-ai-3` one
// requirement; on the history tab `?scan=<run id>` one scan.
#[route("/targets/:id/views/:view?:cve_severity&:cve_vex&:control&:scan")]
TargetViewsPage {
id: String,
view: String,
cve_severity: Option<String>,
cve_vex: Option<String>,
control: Option<String>,
scan: Option<String>,
},
#[route("/targets/:id/compliance")]
CompliancePage { id: String },
// A machine (#1026): a product project and its targets; `?tab=`
// `parts` (the default), `cves` or `history`.
#[route("/projects/:id?:tab")]
MachinePage { id: String, tab: String },
#[route("/onboard")]
OnboardingPage {},
// `?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
// that is set, so a link without a chart filter keeps its old form.
// (The macro wants the fields in the order of the arguments.)
#[route("/findings?:scan_type&:severity&:path&:target")]
FindingsPage {
scan_type: Option<String>,
severity: Option<String>,
path: Option<String>,
target: String,
},
#[route("/findings/:id")]
FindingDetailPage { id: String },
// `?target=<id>` opens the list filtered to one target.
#[route("/sbom?:target")]
SbomPage { target: String },
// The SBOM page with its component table filtered to one ecosystem,
// opened from the components view (#957).
#[route("/sbom/ecosystem/:ecosystem?:target", SbomPage)]
SbomEcosystemPage { ecosystem: String, target: String },
#[route("/issues")]
IssuesPage {},
// The code graph opens from its card on the target page.
#[redirect("/graph", || Route::TargetsPage {})]
#[route("/graph/:repo_id")]
GraphExplorerPage { repo_id: String },
#[route("/graph/:repo_id/impact/:finding_id")]
ImpactAnalysisPage { repo_id: String, finding_id: String },
#[route("/chat")]
ChatIndexPage {},
#[route("/chat/:repo_id")]
ChatPage { repo_id: String },
#[route("/dast")]
DastOverviewPage {},
#[route("/dast/targets")]
DastTargetsPage {},
#[route("/dast/findings")]
DastFindingsPage {},
#[route("/dast/findings/:id")]
DastFindingDetailPage { id: String },
#[route("/pentest")]
PentestDashboardPage {},
#[route("/pentest/:session_id")]
PentestSessionPage { session_id: String },
#[route("/mcp-servers")]
McpServersPage {},
#[route("/mcp-tokens")]
McpTokensPage {},
}
impl Route {
/// The page (the dashboard) of target `id`.
pub fn target(id: String) -> Self {
Self::TargetPage { id }
}
/// The tab `view` of target `id`'s views; the CVE tab shows its grid.
pub fn target_view(id: String, view: RepoView) -> Self {
Self::TargetViewsPage {
id,
view: view.slug().to_string(),
cve_severity: None,
cve_vex: None,
control: None,
scan: None,
}
}
/// Heute for target `target` (every target when empty), opened on
/// `bucket` (the most urgent one when `None`).
pub fn heute(target: String, bucket: Option<Bucket>) -> Self {
Self::HeutePage {
target,
bucket: bucket.map(|b| b.as_str().to_string()).unwrap_or_default(),
}
}
/// The findings list of target `target` (of all targets when empty),
/// without a chart's filters.
pub fn findings(target: String) -> Self {
Self::FindingsPage {
target,
scan_type: None,
severity: None,
path: None,
}
}
}
const MAIN_CSS: Asset = asset!("/assets/main.css");
const TAILWIND_CSS: Asset = asset!("/assets/tailwind.css");
const VIS_NETWORK_JS: Asset = asset!("/assets/vis-network.min.js");
const GRAPH_VIZ_JS: Asset = asset!("/assets/graph-viz.js");
#[component]
pub fn App() -> Element {
rsx! {
// Also sent as the X-Robots-Tag header; in the markup it is visible
// in the page source and honoured by crawlers that read only HTML.
document::Meta { name: "robots", content: "noindex, nofollow" }
// The BreakPilot chevron, at a fixed path (served by the server).
document::Link { rel: "icon", r#type: "image/svg+xml", href: "/favicon.svg" }
document::Link { rel: "stylesheet", href: TAILWIND_CSS }
document::Link { rel: "stylesheet", href: MAIN_CSS }
document::Script { src: VIS_NETWORK_JS }
document::Script { src: GRAPH_VIZ_JS }
Router::<Route> {}
}
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
use compliance_core::models::inbox::Bucket;
use super::Route;
use crate::pages::target_views::RepoView;
#[test]
fn heute_is_the_landing_page_and_the_overview_stays_reachable() {
assert_eq!(
Route::from_str("/").ok(),
Some(Route::heute(String::new(), None))
);
let one = Route::heute("t1".to_string(), Some(Bucket::ThisWeek));
assert_eq!(one.to_string(), "/?target=t1&bucket=this_week");
assert_eq!(Route::from_str(&one.to_string()).ok(), Some(one));
assert!(matches!(
Route::from_str("/overview"),
Ok(Route::OverviewPage {})
));
assert_eq!(Route::OverviewPage {}.to_string(), "/overview");
}
#[test]
fn the_sbom_page_carries_its_target_in_the_query() {
let filtered = Route::SbomPage {
target: "665f1c2ab0c4d1e2f3a4b5c6".to_string(),
};
assert_eq!(
filtered.to_string(),
"/sbom?target=665f1c2ab0c4d1e2f3a4b5c6"
);
assert!(matches!(
Route::from_str("/sbom?target=665f1c2ab0c4d1e2f3a4b5c6"),
Ok(Route::SbomPage { target }) if target == "665f1c2ab0c4d1e2f3a4b5c6"
));
assert!(matches!(
Route::from_str("/sbom"),
Ok(Route::SbomPage { target }) if target.is_empty()
));
}
#[test]
fn an_ecosystem_of_the_sbom_page_is_in_its_url() {
let filtered = Route::SbomEcosystemPage {
ecosystem: "npm".to_string(),
target: "665f1c2ab0c4d1e2f3a4b5c6".to_string(),
};
assert_eq!(
filtered.to_string(),
"/sbom/ecosystem/npm?target=665f1c2ab0c4d1e2f3a4b5c6"
);
assert!(matches!(
Route::from_str("/sbom/ecosystem/cargo?target=665f"),
Ok(Route::SbomEcosystemPage { ecosystem, target })
if ecosystem == "cargo" && target == "665f"
));
}
#[test]
fn a_target_view_carries_its_tab_and_the_cve_cell_in_the_url() {
let cell = Route::TargetViewsPage {
id: "t1".to_string(),
view: "cves".to_string(),
cve_severity: Some("high".to_string()),
cve_vex: Some("open".to_string()),
control: None,
scan: None,
};
// The router writes a `&` after each argument that is set.
assert_eq!(
cell.to_string(),
"/targets/t1/views/cves?cve_severity=high&cve_vex=open&"
);
assert_eq!(Route::from_str(&cell.to_string()).ok(), Some(cell));
// A CRA requirement and a scan read back the same way.
for (view, control, scan) in [
("cra", Some("cra-ai-3"), None),
("history", None, Some("665f1c2ab0c4d1e2f3a4b5c6")),
] {
let route = Route::TargetViewsPage {
id: "t1".to_string(),
view: view.to_string(),
cve_severity: None,
cve_vex: None,
control: control.map(String::from),
scan: scan.map(String::from),
};
assert_eq!(Route::from_str(&route.to_string()).ok(), Some(route));
}
let column = Route::TargetViewsPage {
id: "t1".to_string(),
view: "cves".to_string(),
cve_severity: None,
cve_vex: Some("open".to_string()),
control: None,
scan: None,
};
assert_eq!(Route::from_str(&column.to_string()).ok(), Some(column));
// The router writes the `?` of a two-argument query even when both
// are absent; harmless, and it reads back as the grid.
let grid = Route::target_view("t1".to_string(), RepoView::Cves);
assert_eq!(grid.to_string(), "/targets/t1/views/cves?");
assert_eq!(Route::from_str("/targets/t1/views/cves").ok(), Some(grid));
assert_eq!(Route::target("t1".to_string()).to_string(), "/targets/t1");
assert_eq!(
Route::from_str("/targets/t1").ok(),
Some(Route::target("t1".to_string()))
);
assert!(matches!(
Route::from_str("/targets/t1/compliance"),
Ok(Route::CompliancePage { id }) if id == "t1"
));
}
#[test]
fn the_findings_page_carries_the_chart_filters_in_the_query() {
let id = "665f1c2ab0c4d1e2f3a4b5c6";
// Without a chart filter the link stays what it was.
assert_eq!(
Route::findings(id.to_string()).to_string(),
format!("/findings?target={id}")
);
let segment = Route::FindingsPage {
target: id.to_string(),
scan_type: Some("gdpr".to_string()),
severity: Some("medium".to_string()),
path: None,
};
let url = segment.to_string();
assert_eq!(
url,
format!("/findings?scan_type=gdpr&severity=medium&target={id}")
);
assert_eq!(Route::from_str(&url).ok(), Some(segment.clone()));
// The order of the arguments does not matter.
assert_eq!(
Route::from_str(&format!(
"/findings?target={id}&severity=medium&scan_type=gdpr"
))
.ok(),
Some(segment)
);
let folder = Route::FindingsPage {
target: id.to_string(),
scan_type: None,
severity: None,
path: Some("src/*".to_string()),
};
assert_eq!(
folder.to_string(),
format!("/findings?path=src/*&target={id}")
);
assert_eq!(Route::from_str(&folder.to_string()).ok(), Some(folder));
let root = Route::FindingsPage {
target: id.to_string(),
scan_type: None,
severity: None,
path: Some("/".to_string()),
};
assert_eq!(Route::from_str(&root.to_string()).ok(), Some(root));
// Old links and the bare list still parse.
assert_eq!(
Route::from_str(&format!("/findings?target={id}")).ok(),
Some(Route::findings(id.to_string()))
);
assert_eq!(
Route::from_str("/findings").ok(),
Some(Route::findings(String::new()))
);
}
}