Files
pruefwerk/compliance-dashboard/src/components/sidebar.rs
T
Sharang ParnerkarandClaude Opus 5.5 be0eb4f12c
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 4m12s
CI / Check (pull_request) Successful in 18m48s
feat(dashboard): components by update impact and ecosystem as clickable charts (#957)
The SBOM page's component tab opens, for one target, with two bar charts
(one hue, no legend; "Tabelle" shows the same numbers as tables):

- "Welches Update entfernt die meisten CVEs": per CVE group of #949 with
  a fix, "openssl 3.0.11 -> 3.0.15" and "-3 CVEs", ranked by the CVEs the
  update fixes, then by the worst severity; top 10, then "Alle anzeigen".
  A bar opens that component's group card in place (breadcrumb
  "Komponenten > openssl 3.0.11", "Zurueck zum Diagramm"). The card is
  #949's own; only its visibility changes.
- "Komponenten nach Oekosystem": per package manager the components and
  how many have a known vulnerability. A bar filters the component table
  below to it and puts it in the URL: the new additive route
  /sbom/ecosystem/:ecosystem?target=<id> renders the same page. The
  package-manager select now shows the active filter.

Agent: GET /api/v1/targets/{id}/sbom-ecosystems counts the target's SBOM
components per package manager in one aggregation (tenant database, org
role gate as every route). The ranking and the filterable managers live
in compliance-core (sbom_ecosystems), shared with /sbom/filters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 15:33:02 +01:00

321 lines
13 KiB
Rust

use compliance_core::models::auth::AuthInfo;
use dioxus::prelude::*;
use dioxus_free_icons::icons::bs_icons::*;
use dioxus_free_icons::Icon;
use crate::app::Route;
use crate::components::lang_toggle::LangToggle;
use crate::components::no_access::use_can_write;
use crate::components::theme_toggle::ThemeToggle;
use crate::i18n::texts::{common, nav};
use crate::i18n::{use_lang, Text};
use crate::infrastructure::platform::use_source_only;
/// Where the legal pages live. Overridable per build; they are the same on
/// staging and production.
const IMPRINT_URL: &str = match option_env!("IMPRINT_URL") {
Some(url) => url,
None => "https://breakpilot.com/impressum",
};
const PRIVACY_URL: &str = match option_env!("PRIVACY_URL") {
Some(url) => url,
None => "https://breakpilot.com/datenschutz",
};
struct NavItem {
label: Text,
route: Route,
icon: Element,
/// Needs a runtime (browser / live target); disabled in source-only mode.
runtime_only: bool,
/// Only for roles that may change things (onboarding a target).
write_only: bool,
}
#[component]
pub fn Sidebar() -> Element {
let current_route = use_route::<Route>();
// Open, like the portal's nav rail; the toggle collapses it.
let mut collapsed = use_signal(|| false);
let source_only = use_source_only();
let lang = use_lang()();
let can_write = use_can_write();
let nav_items = [
NavItem {
label: nav::OVERVIEW,
route: Route::OverviewPage {},
icon: rsx! { Icon { icon: BsSpeedometer2, width: 18, height: 18 } },
runtime_only: false,
write_only: false,
},
NavItem {
label: nav::TARGETS,
route: Route::TargetsPage {},
icon: rsx! { Icon { icon: BsFolder2Open, width: 18, height: 18 } },
runtime_only: false,
write_only: false,
},
NavItem {
label: nav::ONBOARD,
route: Route::OnboardingPage {},
icon: rsx! { Icon { icon: BsPlusCircle, width: 18, height: 18 } },
runtime_only: false,
write_only: true,
},
NavItem {
label: nav::FINDINGS,
route: Route::FindingsPage {
target: String::new(),
},
icon: rsx! { Icon { icon: BsShieldExclamation, width: 18, height: 18 } },
runtime_only: false,
write_only: false,
},
NavItem {
label: nav::SBOM,
route: Route::SbomPage {
target: String::new(),
},
icon: rsx! { Icon { icon: BsBoxSeam, width: 18, height: 18 } },
runtime_only: false,
write_only: false,
},
NavItem {
label: nav::ISSUES,
route: Route::IssuesPage {},
icon: rsx! { Icon { icon: BsListTask, width: 18, height: 18 } },
runtime_only: false,
write_only: false,
},
NavItem {
label: nav::DAST,
route: Route::DastOverviewPage {},
icon: rsx! { Icon { icon: BsBug, width: 18, height: 18 } },
runtime_only: true,
write_only: false,
},
NavItem {
label: nav::PENTEST,
route: Route::PentestDashboardPage {},
icon: rsx! { Icon { icon: BsLightningCharge, width: 18, height: 18 } },
runtime_only: true,
write_only: false,
},
// The MCP endpoint also serves a source-only deployment, where the
// overview's MCP-Server card (and with it the only other link to
// the tokens) is hidden.
NavItem {
label: nav::MCP_TOKENS,
route: Route::McpTokensPage {},
icon: rsx! { Icon { icon: BsKey, width: 18, height: 18 } },
runtime_only: false,
write_only: false,
},
];
// Both links are set per deployment (`DOCS_URL`, `PORTAL_URL`). The
// portal link is hidden when the dashboard has no portal (local
// development).
let AuthInfo {
docs_url,
portal_url,
..
} = use_context::<Signal<AuthInfo>>()();
// On a phone the sidebar is off-canvas: the top bar's menu button slides
// it in, and choosing a page or the backdrop closes it.
let mut mobile_open = use_signal(|| false);
let sidebar_class = match (collapsed(), mobile_open()) {
(true, _) => "sidebar collapsed",
(false, true) => "sidebar open",
(false, false) => "sidebar",
};
rsx! {
div { class: "mobile-bar",
button {
class: "mobile-menu-btn",
"aria-label": if mobile_open() { nav::CLOSE_MENU.get(lang) } else { nav::MENU.get(lang) },
"aria-expanded": if mobile_open() { "true" } else { "false" },
onclick: move |_| mobile_open.set(!mobile_open()),
if mobile_open() {
Icon { icon: BsXLg, width: 18, height: 18 }
} else {
Icon { icon: BsList, width: 20, height: 20 }
}
}
div { class: "mobile-bar-brand", Wordmark { with_name: true } }
}
if mobile_open() {
div { class: "mobile-backdrop", onclick: move |_| mobile_open.set(false) }
}
nav { class: "{sidebar_class}",
// The breakpilot brand, as the portal shows it; Prüfwerk is the
// product within it.
div { class: "sidebar-header",
Wordmark { with_name: !collapsed() }
}
if !portal_url.is_empty() {
a {
href: "{portal_url}",
class: "nav-item portal-link",
title: nav::PORTAL.get(lang),
Icon { icon: BsArrowLeft, width: 18, height: 18 }
if !collapsed() {
span { {nav::PORTAL.get(lang)} }
}
}
}
div { class: "sidebar-nav",
for item in nav_items.into_iter().filter(|i| can_write || !i.write_only) {
{
let is_active = match (&current_route, &item.route) {
(Route::FindingDetailPage { .. } | Route::FindingsPage { .. }, Route::FindingsPage { .. }) => true,
(Route::SbomPage { .. }, Route::SbomPage { .. }) => true,
(Route::SbomEcosystemPage { .. }, Route::SbomPage { .. }) => true,
(Route::CompliancePage { .. }, Route::TargetsPage {}) => true,
(Route::DastTargetsPage {}, Route::DastOverviewPage {}) => true,
(Route::DastFindingsPage {}, Route::DastOverviewPage {}) => true,
(Route::DastFindingDetailPage { .. }, Route::DastOverviewPage {}) => true,
(Route::PentestSessionPage { .. }, Route::PentestDashboardPage {}) => true,
(a, b) => a == b,
};
let disabled = source_only && item.runtime_only;
let class = if disabled {
"nav-item disabled"
} else if is_active {
"nav-item active"
} else {
"nav-item"
};
let label = item.label.get(lang);
if disabled {
// Not a link: a runtime-only page cannot be opened
// here, so it must not look or act like it can.
let title = common::NOT_AVAILABLE_HERE.get(lang);
rsx! {
span {
class: class,
title: "{title}",
aria_disabled: "true",
{item.icon}
if !collapsed() {
span { "{label}" }
span { style: "font-size: 0.7em; opacity: 0.8; margin-left: auto;",
{nav::NOT_AVAILABLE_SHORT.get(lang)}
}
}
}
}
} else {
rsx! {
Link {
to: item.route.clone(),
class: class,
title: "{label}",
onclick: move |_| mobile_open.set(false),
{item.icon}
if !collapsed() {
span { "{label}" }
}
}
}
}
}
}
}
a {
href: "{docs_url}",
target: "_blank",
class: "nav-item",
Icon { icon: BsBook, width: 18, height: 18 }
if !collapsed() {
span { {nav::DOCS.get(lang)} }
}
}
// Spacer pushes footer to the bottom
div { class: "sidebar-spacer" }
LangToggle { collapsed: collapsed() }
ThemeToggle { collapsed: collapsed() }
button {
class: "sidebar-toggle",
onclick: move |_| collapsed.set(!collapsed()),
if collapsed() {
Icon { icon: BsChevronRight, width: 14, height: 14 }
} else {
Icon { icon: BsChevronLeft, width: 14, height: 14 }
}
}
{
let auth_info = use_context::<Signal<AuthInfo>>();
let info = auth_info();
let initials = info.name.chars().next().unwrap_or('U').to_uppercase().to_string();
rsx! {
div { class: "sidebar-user",
div { class: "user-avatar",
if info.avatar_url.is_empty() {
span { class: "avatar-initials", "{initials}" }
} else {
img { src: "{info.avatar_url}", alt: "avatar", class: "avatar-img" }
}
}
if !collapsed() {
div { class: "user-info",
span { class: "user-name", "{info.name}" }
a {
href: "/logout",
class: "logout-link",
{nav::SIGN_OUT.get(lang)}
}
}
}
if collapsed() {
a {
href: "/logout",
class: "logout-btn-icon",
title: nav::SIGN_OUT.get(lang),
Icon { icon: BsBoxArrowRight, width: 14, height: 14 }
}
}
}
if !collapsed() {
div { class: "sidebar-legal",
a { href: PRIVACY_URL, target: "_blank", rel: "noopener", {nav::PRIVACY.get(lang)} }
span { class: "legal-dot", "·" }
a { href: IMPRINT_URL, target: "_blank", rel: "noopener", {nav::IMPRINT.get(lang)} }
}
}
}
}
}
}
}
/// The BreakPilot wordmark, as on breakpilot.com and the portal: the chevron,
/// and unless `with_name` is off, "BreakPilot" with "Prüfwerk" beneath.
#[component]
fn Wordmark(with_name: bool) -> Element {
rsx! {
svg {
class: "brand-chevron",
view_box: "8.75 2.25 46.5 45",
fill: "none",
stroke_linecap: "round",
stroke_linejoin: "round",
"aria-hidden": "true",
path { d: "M12 44 L32 20 L52 44", stroke: "var(--brand-chevron)", stroke_width: "6.5" }
path { d: "M24 13 L32 5 L40 13", stroke: "var(--brand-chevron-top)", stroke_width: "5.5" }
}
if with_name {
div { class: "brand-text",
span { class: "brand-name",
"Break"
span { class: "bp-pilot", "Pilot" }
}
span { class: "brand-sub", "Prüfwerk" }
}
}
}
}