From 782d6270f8c58d3317728c81e6765027135877d9 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Tue, 10 Nov 2026 20:28:45 +0100 Subject: [PATCH] feat(dashboard): repo views as tabs, Heute per repo, bucket counts on repo cards (#957) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mockup's repo pages, which the earlier PRs left out: - The repo dashboard gets the breadcrumb (Überblick › project › repo), "Alle Ansichten →" and the blue "N heute zu entscheiden →". Scan, evidence pack, edit and delete move to a row below. - "Alle Ansichten" opens /targets/{id}/views/{view}: six tabs with their figures (Befunde, CVEs & VEX, Komponenten, Lizenzen, CRA Annex I, Verlauf), each starting with its chart. The CVE grid moves here from the dashboard; Lizenzen lists a group's licences after a click. CRA and Verlauf show the bar and the scan list until their charts are built. - Heute reads ?target= and ?bucket= from the URL, so a repo's button opens its decisions. - The overview's repo cards show the four Heute buckets, each a link to Heute for that repo and bucket; the inbox API gives the counts per target and bucket. Co-Authored-By: Claude Opus 5.5 --- compliance-core/src/models/inbox.rs | 43 +- compliance-dashboard/assets/main.css | 179 +++++++++ compliance-dashboard/src/app.rs | 87 ++-- .../src/components/cve_matrix.rs | 13 +- .../src/components/sidebar.rs | 4 +- compliance-dashboard/src/i18n/texts.rs | 115 ++++++ compliance-dashboard/src/pages/inbox.rs | 15 +- compliance-dashboard/src/pages/mod.rs | 2 + compliance-dashboard/src/pages/overview.rs | 68 +++- compliance-dashboard/src/pages/target.rs | 111 +++--- .../src/pages/target_views.rs | 376 ++++++++++++++++++ 11 files changed, 905 insertions(+), 108 deletions(-) create mode 100644 compliance-dashboard/src/pages/target_views.rs diff --git a/compliance-core/src/models/inbox.rs b/compliance-core/src/models/inbox.rs index ff03ef5..bbdae31 100644 --- a/compliance-core/src/models/inbox.rs +++ b/compliance-core/src/models/inbox.rs @@ -719,16 +719,21 @@ impl InboxCounts { /// The counts of `cards`. pub fn of<'a>(cards: impl IntoIterator) -> Self { cards.into_iter().fold(Self::default(), |mut counts, card| { - *match card.bucket { - Bucket::Today => &mut counts.today, - Bucket::ThisWeek => &mut counts.this_week, - Bucket::Later => &mut counts.later, - Bucket::LikelyFalsePositive => &mut counts.likely_false_positive, - } += 1; + counts.add(card.bucket); counts }) } + /// Count one more card in `bucket`. + pub fn add(&mut self, bucket: Bucket) { + *match bucket { + Bucket::Today => &mut self.today, + Bucket::ThisWeek => &mut self.this_week, + Bucket::Later => &mut self.later, + Bucket::LikelyFalsePositive => &mut self.likely_false_positive, + } += 1; + } + /// Every bucket's cards together. pub const fn total(&self) -> u64 { self.today + self.this_week + self.later + self.likely_false_positive @@ -764,8 +769,10 @@ impl Progress { pub struct InboxTarget { pub id: String, pub name: String, - /// Its cards in all buckets. - pub cards: u64, + /// Its cards per bucket, for the target chips and the overview's repo + /// cards. + #[serde(default)] + pub counts: InboxCounts, } /// `GET /api/v1/inbox`: the counts, the Erstbewertung, the targets with cards @@ -818,19 +825,27 @@ pub fn view( progress: Progress, request: ViewRequest<'_>, ) -> InboxView { - let mut per_target: HashMap<&str, u64> = HashMap::new(); + let mut per_target: HashMap<&str, InboxCounts> = HashMap::new(); for card in &cards { - *per_target.entry(card.target_id.as_str()).or_default() += 1; + per_target + .entry(card.target_id.as_str()) + .or_default() + .add(card.bucket); } let mut targets: Vec = per_target .into_iter() - .map(|(id, count)| InboxTarget { + .map(|(id, counts)| InboxTarget { id: id.to_string(), name: names.get(id).cloned().unwrap_or_else(|| id.to_string()), - cards: count, + counts, }) .collect(); - targets.sort_by(|a, b| b.cards.cmp(&a.cards).then_with(|| a.name.cmp(&b.name))); + targets.sort_by(|a, b| { + b.counts + .total() + .cmp(&a.counts.total()) + .then_with(|| a.name.cmp(&b.name)) + }); let in_scope: Vec = cards .into_iter() .filter(|c| request.target.is_none_or(|t| c.target_id == t)) @@ -1431,7 +1446,7 @@ mod tests { "most severe first" ); assert_eq!(all.targets[0].name, "Pumpe"); - assert_eq!(all.targets[0].cards, 2); + assert_eq!(all.targets[0].counts.total(), 2); assert_eq!( all.targets[1].name, "t2", "a target without a name shows its id" diff --git a/compliance-dashboard/assets/main.css b/compliance-dashboard/assets/main.css index 6e2a811..60c0ea8 100644 --- a/compliance-dashboard/assets/main.css +++ b/compliance-dashboard/assets/main.css @@ -7688,3 +7688,182 @@ input[type="file"] { } .lo-back { margin-left: auto; } + +/* ── A target's dashboard and views (#957): breadcrumb, Heute, tabs ── */ +.repo-crumbs { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 6px; + margin-bottom: 12px; + font-size: 13px; + color: var(--text-secondary); +} + +.repo-crumbs a { + color: var(--accent); + text-decoration: none; +} + +.repo-crumbs a:hover { + color: var(--accent-hover); + text-decoration: underline; +} + +.repo-crumb-sep { + color: var(--text-faint); +} + +.repo-crumb-name { + font-family: var(--font-mono); +} + +span.repo-crumb-name { + color: var(--text-primary); +} + +.repo-head { + display: flex; + flex-wrap: wrap; + align-items: flex-end; + justify-content: space-between; + gap: 12px; + margin-bottom: 16px; +} + +.repo-head-text { + display: grid; + gap: 6px; + min-width: 0; +} + +.repo-head-name { + font-family: var(--font-mono); + font-size: 22px; + font-weight: 600; + letter-spacing: -0.02em; + overflow-wrap: anywhere; +} + +.repo-head-sub { + color: var(--text-secondary); + font-size: 14px; +} + +.repo-head .btn, +.target-head-actions .btn { + min-height: 40px; +} + +.target-head-tools { + display: flex; + flex-wrap: wrap; + gap: 6px; + margin: -8px 0 20px; +} + +.target-head-tools .btn { + display: inline-flex; + align-items: center; + gap: 6px; +} + +.repo-tabs { + display: flex; + gap: 4px; + margin-bottom: 20px; + border-bottom: 1px solid var(--border-bright); + overflow-x: auto; + scrollbar-width: thin; +} + +.repo-tab { + display: inline-flex; + align-items: center; + gap: 6px; + flex: none; + min-height: 44px; + padding: 0 16px; + margin-bottom: -1px; + border-bottom: 2px solid transparent; + color: var(--text-secondary); + font-size: 14px; + text-decoration: none; + white-space: nowrap; +} + +.repo-tab:hover { + color: var(--text-primary); +} + +.repo-tab.is-active { + border-bottom-color: var(--accent); + color: var(--accent); + font-weight: 600; +} + +.repo-tab-figure { + color: var(--text-tertiary); + font-size: 12px; + font-weight: 400; +} + +.repo-view { + display: grid; + gap: 16px; +} + +.repo-view-list { + justify-self: start; + color: var(--accent); + font-size: 13px; +} + +.repo-licence-packages { + color: var(--text-secondary); + font-size: 12.5px; + overflow-wrap: anywhere; +} + +/* The four Heute buckets of a repo card, each a link to Heute. */ +.repo-card-buckets { + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 6px; +} + +.repo-card-bucket { + display: grid; + gap: 2px; + min-width: 0; + min-height: 44px; + padding: 6px 8px; + border: 1px solid var(--border); + border-top: 3px solid var(--tone, var(--border-strong)); + border-radius: var(--radius-sm); + color: var(--text-primary); + text-decoration: none; +} + +.repo-card-bucket:hover { + background: var(--bg-card-hover); +} + +.repo-card-bucket.tone-danger { --tone: var(--danger); } +.repo-card-bucket.tone-warning { --tone: var(--orange); } +.repo-card-bucket.tone-neutral { --tone: var(--info); } +.repo-card-bucket.tone-accent { --tone: var(--accent); } + +.repo-card-bucket-n { + font-size: 16px; + font-weight: 600; + font-variant-numeric: tabular-nums; +} + +.repo-card-bucket-label { + overflow: hidden; + color: var(--text-tertiary); + font-size: 11px; + text-overflow: ellipsis; + white-space: nowrap; +} diff --git a/compliance-dashboard/src/app.rs b/compliance-dashboard/src/app.rs index be63df1..bc81308 100644 --- a/compliance-dashboard/src/app.rs +++ b/compliance-dashboard/src/app.rs @@ -1,6 +1,9 @@ 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)] @@ -8,18 +11,28 @@ use crate::pages::*; #[allow(clippy::enum_variant_names)] pub enum Route { #[layout(AppShell)] - // The landing page: the open decisions (#950). - #[route("/")] - HeutePage {}, + // The landing page: the open decisions (#950). `?target=` opens + // one target's, `&bucket=` one bucket (`today`, `this_week`, ...). + #[route("/?:target&:bucket")] + HeutePage { target: String, bucket: String }, #[route("/overview")] OverviewPage {}, #[route("/targets")] TargetsPage {}, - // `?cve_severity=high&cve_vex=open` opens the target's CVE list - // narrowed to that cell of the CVE grid (#957); `all` leaves a side - // open, neither shows the grid. - #[route("/targets/:id?:cve_severity&:cve_vex")] - TargetPage { id: String, cve_severity: Option, cve_vex: Option }, + #[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. + #[route("/targets/:id/views/:view?:cve_severity&:cve_vex")] + TargetViewsPage { + id: String, + view: String, + cve_severity: Option, + cve_vex: Option, + }, #[route("/targets/:id/compliance")] CompliancePage { id: String }, #[route("/onboard")] @@ -76,15 +89,30 @@ pub enum Route { } impl Route { - /// The page of target `id`, its CVE grid shown (no CVE cell chosen). + /// The page (the dashboard) of target `id`. pub fn target(id: String) -> Self { - Self::TargetPage { + 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, } } + /// Heute for target `target` (every target when empty), opened on + /// `bucket` (the most urgent one when `None`). + pub fn heute(target: String, bucket: Option) -> 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 { @@ -119,12 +147,22 @@ pub fn App() -> Element { #[cfg(test)] mod tests { - use super::Route; 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!(matches!(Route::from_str("/"), Ok(Route::HeutePage {}))); + 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 {}) @@ -169,20 +207,22 @@ mod tests { } #[test] - fn the_target_page_carries_the_cve_cell_in_the_query() { - let cell = Route::TargetPage { + 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()), }; assert_eq!( cell.to_string(), - "/targets/t1?cve_severity=high&cve_vex=open" + "/targets/t1/views/cves?cve_severity=high&cve_vex=open" ); assert_eq!(Route::from_str(&cell.to_string()).ok(), Some(cell)); - let column = Route::TargetPage { + let column = Route::TargetViewsPage { id: "t1".to_string(), + view: "cves".to_string(), cve_severity: None, cve_vex: Some("open".to_string()), }; @@ -190,19 +230,14 @@ mod tests { // The router writes the `?` of a two-argument query even when both // are absent; harmless, and it reads back as the 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())) - ); + 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::TargetPage { - id: "t1".to_string(), - cve_severity: None, - cve_vex: None, - }) + Some(Route::target("t1".to_string())) ); assert!(matches!( Route::from_str("/targets/t1/compliance"), diff --git a/compliance-dashboard/src/components/cve_matrix.rs b/compliance-dashboard/src/components/cve_matrix.rs index 5d67ba7..f6fe5fe 100644 --- a/compliance-dashboard/src/components/cve_matrix.rs +++ b/compliance-dashboard/src/components/cve_matrix.rs @@ -15,6 +15,7 @@ use crate::components::vex_panel::VexPanel; use crate::i18n::texts::{common, cve_matrix as tx, vex as vex_tx}; use crate::i18n::{use_lang, Lang}; use crate::infrastructure::cve_matrix::fetch_cve_matrix; +use crate::pages::target_views::RepoView; /// The query value for "every severity and status": the whole list. const ALL: &str = "all"; @@ -56,8 +57,9 @@ fn list_route(target_id: &str, filter: Option) -> Route { .map(VexColumn::as_str) .or(severity.is_none().then_some(ALL)) .map(String::from); - Route::TargetPage { + Route::TargetViewsPage { id: target_id.to_string(), + view: RepoView::Cves.slug().to_string(), cve_severity: severity, cve_vex: vex, } @@ -114,12 +116,12 @@ pub fn CveView( Selection::Grid => rsx! { CveGrid { target_id } }, Selection::List(filter) => rsx! { nav { class: "cve-crumbs", "aria-label": tx::CVES.get(lang), - Link { class: "btn btn-ghost btn-back", to: Route::target(target_id.clone()), + Link { class: "btn btn-ghost btn-back", to: Route::target_view(target_id.clone(), RepoView::Cves), Icon { icon: BsArrowLeft, width: 16, height: 16 } {tx::BACK.get(lang)} } span { class: "cve-crumb-trail", - Link { to: Route::target(target_id.clone()), {tx::CVES.get(lang)} } + Link { to: Route::target_view(target_id.clone(), RepoView::Cves), {tx::CVES.get(lang)} } span { "aria-hidden": "true", " › " } span { "aria-current": "page", "{crumb(filter, lang)}" } } @@ -366,15 +368,16 @@ mod tests { }), ]; for filter in filters { - let Route::TargetPage { + let Route::TargetViewsPage { id, + view, cve_severity, cve_vex, } = list_route("t1", filter) else { panic!("not the target page"); }; - assert_eq!(id, "t1"); + assert_eq!((id.as_str(), view.as_str()), ("t1", "cves")); assert_eq!( selection(cve_severity.as_deref(), cve_vex.as_deref()), Selection::List(filter) diff --git a/compliance-dashboard/src/components/sidebar.rs b/compliance-dashboard/src/components/sidebar.rs index 36e9fd4..de8011b 100644 --- a/compliance-dashboard/src/components/sidebar.rs +++ b/compliance-dashboard/src/components/sidebar.rs @@ -168,7 +168,7 @@ pub fn Sidebar() -> Element { div { class: "sidebar-nav", TodayNavItem { collapsed: collapsed(), - active: current_route == (Route::HeutePage {}), + active: matches!(current_route, Route::HeutePage { .. }), on_navigate: move |_| mobile_open.set(false), } for item in nav_items.into_iter().filter(|i| can_write || !i.write_only) { @@ -315,7 +315,7 @@ fn TodayNavItem(collapsed: bool, active: bool, on_navigate: EventHandler<()>) -> let today = TODAY_COUNT().filter(|n| *n > 0); rsx! { Link { - to: Route::HeutePage {}, + to: Route::heute(String::new(), None), class: if active { "nav-item active" } else { "nav-item" }, title: "{label}", onclick: move |_| on_navigate.call(()), diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 387d80b..d50f5ee 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -6568,3 +6568,118 @@ pub mod licence_overview { } } } + +/// A target's views (#957): the tabs, the breadcrumb and Heute's button. +pub mod repo_views { + use super::super::Lang; + use super::Text; + + pub const BREADCRUMB: Text = Text { + de: "Brotkrumen", + en: "Breadcrumb", + }; + pub const OVERVIEW: Text = Text { + de: "Überblick", + en: "Overview", + }; + pub const SUBTITLE: Text = Text { + de: "Jede Ansicht beginnt mit einem Diagramm. Ein Klick auf einen Balken, eine Zelle \ + oder eine Kachel öffnet die passende Tabelle.", + en: "Every view starts with a chart. A click on a bar, a cell or a tile opens the \ + matching table.", + }; + pub const TABS: Text = Text { + de: "Ansichten", + en: "Views", + }; + pub const ALL_VIEWS: Text = Text { + de: "Alle Ansichten", + en: "All views", + }; + pub const ALL_VIEWS_HINT: Text = Text { + de: "Befunde, CVEs, Komponenten, Lizenzen, CRA, Verlauf", + en: "Findings, CVEs, components, licences, CRA, history", + }; + pub const FINDINGS: Text = Text { + de: "Befunde", + en: "Findings", + }; + pub const CVES: Text = Text { + de: "CVEs & VEX", + en: "CVEs & VEX", + }; + pub const COMPONENTS: Text = Text { + de: "Komponenten", + en: "Components", + }; + pub const LICENCES: Text = Text { + de: "Lizenzen", + en: "Licences", + }; + pub const CRA: Text = Text { + de: "CRA Annex I", + en: "CRA Annex I", + }; + pub const HISTORY: Text = Text { + de: "Verlauf", + en: "History", + }; + pub const TODAY: Text = Text { + de: "Heute", + en: "Today", + }; + pub const FINDINGS_LIST: Text = Text { + de: "Alle Befunde als Liste", + en: "All findings as a list", + }; + pub const CRA_COMING: Text = Text { + de: "Die 40 Anforderungen als Kacheln folgen. Bis dahin der Stand als Balken und die \ + Prüfung als Liste.", + en: "The 40 requirements as tiles are to follow. Until then the status as a bar and \ + the check as a list.", + }; + pub const CRA_LIST: Text = Text { + de: "Zur CRA-Prüfung", + en: "To the CRA check", + }; + pub const HISTORY_COMING: Text = Text { + de: "Das Diagramm je Scan (neue und behobene CVEs) folgt. Bis dahin die Scans als Liste.", + en: "The chart per scan (new and fixed CVEs) is to follow. Until then the scans as a \ + list.", + }; + pub const LICENCE: Text = Text { + de: "Lizenz", + en: "Licence", + }; + pub const COUNT: Text = Text { + de: "Komponenten", + en: "Components", + }; + pub const USED_BY: Text = Text { + de: "Verwendet von", + en: "Used by", + }; + pub const LICENCES_LIST: Text = Text { + de: "Alle Lizenzen im SBOM", + en: "All licences in the SBOM", + }; + + /// A findings tab's figure: `47 offen`. + pub fn open(count: u64, lang: Lang) -> String { + let count = super::super::format_count(count, lang); + match lang { + Lang::De => format!("{count} offen"), + Lang::En => format!("{count} open"), + } + } + + /// Heute's button on a target: `3 heute zu entscheiden`. + pub fn today(count: u64, lang: Lang) -> String { + match (count, lang) { + (0, Lang::De) => "Heute nichts zu entscheiden".to_string(), + (0, Lang::En) => "Nothing to decide today".to_string(), + (n, Lang::De) => format!("{n} heute zu entscheiden"), + (n, Lang::En) => format!("{n} to decide today"), + } + } +} diff --git a/compliance-dashboard/src/pages/inbox.rs b/compliance-dashboard/src/pages/inbox.rs index 57b784d..623d05c 100644 --- a/compliance-dashboard/src/pages/inbox.rs +++ b/compliance-dashboard/src/pages/inbox.rs @@ -120,7 +120,7 @@ struct UndoOffer { } /// The labels of a bucket: name, what goes in it, and what an empty one says. -const fn bucket_texts(bucket: Bucket) -> (Text, Text, Text) { +pub(crate) const fn bucket_texts(bucket: Bucket) -> (Text, Text, Text) { match bucket { Bucket::Today => (tx::TODAY, tx::TODAY_HINT, tx::EMPTY_TODAY), Bucket::ThisWeek => (tx::THIS_WEEK, tx::THIS_WEEK_HINT, tx::EMPTY_THIS_WEEK), @@ -130,7 +130,7 @@ const fn bucket_texts(bucket: Bucket) -> (Text, Text, Text) { } /// The CSS tone of a bucket's tile. -const fn bucket_tone(bucket: Bucket) -> &'static str { +pub(crate) const fn bucket_tone(bucket: Bucket) -> &'static str { match bucket { Bucket::Today => "tone-danger", Bucket::ThisWeek => "tone-warning", @@ -351,12 +351,15 @@ impl Inbox { } } +/// Heute: the open decisions of the workspace, or of target `target` (from +/// `?target=`, e.g. a target page's button), with the bucket `bucket` open +/// (`?bucket=`; the most urgent one when absent or unknown). #[component] -pub fn HeutePage() -> Element { +pub fn HeutePage(target: String, bucket: String) -> Element { let lang = use_lang()(); let can_write = use_can_write(); - let target = use_signal(String::new); - let bucket = use_signal(|| Bucket::Today); + let target = use_signal(|| target.clone()); + let bucket = use_signal(|| Bucket::parse(&bucket).unwrap_or(Bucket::Today)); let mut selected = use_signal(|| 0_usize); let view = use_resource(move || async move { fetch_inbox(target(), bucket(), None).await }); let inbox = Inbox { @@ -577,7 +580,7 @@ fn InboxHeader( class: if target() == t.id { "inbox-target is-active" } else { "inbox-target" }, onclick: move |_| choose_target(t.id.clone()), "{t.name}" - span { class: "inbox-target-count", "{t.cards}" } + span { class: "inbox-target-count", "{t.counts.total()}" } } } } diff --git a/compliance-dashboard/src/pages/mod.rs b/compliance-dashboard/src/pages/mod.rs index bf98dd7..eac1f47 100644 --- a/compliance-dashboard/src/pages/mod.rs +++ b/compliance-dashboard/src/pages/mod.rs @@ -20,6 +20,7 @@ pub mod pentest_dashboard; pub mod pentest_session; pub mod sbom; pub mod target; +pub mod target_views; pub mod targets; pub use chat::ChatPage; @@ -43,4 +44,5 @@ pub use pentest_dashboard::PentestDashboardPage; pub use pentest_session::PentestSessionPage; pub use sbom::SbomPage; pub use target::TargetPage; +pub use target_views::TargetViewsPage; pub use targets::TargetsPage; diff --git a/compliance-dashboard/src/pages/overview.rs b/compliance-dashboard/src/pages/overview.rs index d3a8e22..0f84cc8 100644 --- a/compliance-dashboard/src/pages/overview.rs +++ b/compliance-dashboard/src/pages/overview.rs @@ -12,12 +12,16 @@ use crate::i18n::{format_ago, use_lang, Lang}; use crate::infrastructure::cve_history::fetch_cve_history; use crate::infrastructure::evidence::{fetch_compliance_summary, ComplianceSummaryRow, CraCounts}; use crate::infrastructure::findings::{fetch_findings, location, FindingsQuery}; +use crate::infrastructure::inbox::fetch_inbox; use crate::infrastructure::mcp::fetch_mcp_servers; use crate::infrastructure::onboarding::fetch_targets; use crate::infrastructure::platform::use_source_only; use crate::infrastructure::projects::{fetch_projects, project_ids_of}; use crate::infrastructure::stats::fetch_overview_stats; +use crate::pages::inbox::{bucket_texts, bucket_tone}; +use crate::pages::target_views::RepoView; use compliance_core::cve_history::{CveDay, CveHistory}; +use compliance_core::models::inbox::{Bucket, InboxCounts, InboxTarget}; use compliance_core::models::{Project, ScanRun, ScanRunStatus}; /// Open findings the "Next up" list shows. @@ -41,6 +45,8 @@ struct TargetLine { high: u32, /// Critical plus high per day, oldest first; empty without a history. trend: Vec, + /// Its open decisions per Heute bucket. + buckets: InboxCounts, } impl TargetLine { @@ -50,13 +56,15 @@ impl TargetLine { } } -/// The targets joined with their CRA counts and CVE trend: the most open -/// critical and high CVEs with a fix first, then the most violated -/// requirements, then by name. +/// The targets joined with their CRA counts, CVE trend and Heute buckets +/// (`inbox`, the targets with open decisions): the most open critical and +/// high CVEs with a fix first, then the most violated requirements, then by +/// name. fn target_lines( targets: &[serde_json::Value], summary: &[ComplianceSummaryRow], history: Option<&CveHistory>, + inbox: &[InboxTarget], ) -> Vec { let mut lines: Vec = targets .iter() @@ -90,6 +98,11 @@ fn target_lines( critical: today.critical, high: today.high, trend, + buckets: inbox + .iter() + .find(|i| i.id == id) + .map(|i| i.counts) + .unwrap_or_default(), id, }) }) @@ -174,6 +187,13 @@ pub fn OverviewPage() -> Element { let summary = use_resource(|| async { fetch_compliance_summary().await.ok() }); let projects = use_resource(|| async { fetch_projects().await.ok() }); let history = use_resource(|| async { fetch_cve_history(String::new(), true).await.ok() }); + // The bucket counts of every target; no cards. + let inbox = use_resource(|| async { + fetch_inbox(String::new(), Bucket::Today, Some(0)) + .await + .ok() + .map(|v| v.targets) + }); let next_up = use_resource(|| async { fetch_findings(FindingsQuery { page: 1, @@ -221,7 +241,8 @@ pub fn OverviewPage() -> Element { Some(Some(t)) => { let summary = summary.read().clone().flatten().unwrap_or_default(); let projects = projects.read().clone().flatten().unwrap_or_default(); - let lines = target_lines(&t.data, &summary, history.read().as_ref().and_then(|h| h.as_ref())); + let inbox = inbox.read().clone().flatten().unwrap_or_default(); + let lines = target_lines(&t.data, &summary, history.read().as_ref().and_then(|h| h.as_ref()), &inbox); let groups = group_by_project(&lines, &projects); // Without any project, the one group is every target. let only = groups.len() == 1; @@ -377,7 +398,7 @@ fn RepoCard(line: TargetLine, lang: Lang) -> Element { Link { to: Route::target(line.id.clone()), "{line.name}" } span { class: "ov-target-type", {crate::i18n::texts::kinds::target_type(&line.target_type, lang)} } } - Link { to: Route::SbomPage { target: line.id.clone() }, class: "repo-card-cves", title: "{split}", + Link { to: Route::target_view(line.id.clone(), RepoView::Cves), class: "repo-card-cves", title: "{split}", span { class: "repo-card-n", "{line.urgent()}" } span { class: "repo-card-label", {cve_trend::WITH_FIX.get(lang)} @@ -393,6 +414,17 @@ fn RepoCard(line: TargetLine, lang: Lang) -> Element { None => rsx! { span { class: "ov-target-type", {overview::CRA_UNAVAILABLE.get(lang)} } }, } } + div { class: "repo-card-buckets", + for b in Bucket::ALL { + Link { + key: "{b.as_str()}", + class: "repo-card-bucket {bucket_tone(b)}", + to: Route::heute(line.id.clone(), Some(b)), + span { class: "repo-card-bucket-n", "{line.buckets.get(b)}" } + span { class: "repo-card-bucket-label", {bucket_texts(b).0.get(lang)} } + } + } + } div { class: "repo-card-foot", span { class: "repo-card-scan", match scanned { @@ -596,14 +628,33 @@ mod tests { ..CveHistory::default() }; let targets = [target("a", "alpha", &[]), target("b", "beta", &[])]; - let lines = target_lines(&targets, &[], Some(&history)); + let lines = target_lines(&targets, &[], Some(&history), &[]); assert_eq!(lines[0].name, "beta"); assert_eq!((lines[0].critical, lines[0].high), (1, 2)); assert_eq!(lines[0].trend, [1, 3]); // No alerts in the window: flat at zero over the same days. assert_eq!(lines[1].trend, [0, 0]); // Without a history: no trend at all. - assert!(target_lines(&targets, &[], None)[0].trend.is_empty()); + assert!(target_lines(&targets, &[], None, &[])[0].trend.is_empty()); + } + + #[test] + fn a_target_carries_its_heute_buckets_and_one_without_decisions_none() { + let inbox = [InboxTarget { + id: "b".to_string(), + name: "beta".to_string(), + counts: InboxCounts { + today: 3, + this_week: 1, + later: 0, + likely_false_positive: 2, + }, + }]; + let targets = [target("a", "alpha", &[]), target("b", "beta", &[])]; + let lines = target_lines(&targets, &[], None, &inbox); + let of = |name: &str| lines.iter().find(|l| l.name == name).unwrap().buckets; + assert_eq!(of("beta"), inbox[0].counts); + assert_eq!(of("alpha"), InboxCounts::default()); } #[test] @@ -614,7 +665,7 @@ mod tests { target("c", "gamma", &["deleted"]), target("d", "delta", &[]), ]; - let lines = target_lines(&targets, &[], None); + let lines = target_lines(&targets, &[], None, &[]); let projects = [ project("p1", "Lok"), project("p2", "Steuerung"), @@ -644,6 +695,7 @@ mod tests { critical, high, trend, + buckets: InboxCounts::default(), }; let group = ProjectGroup { project: Some(project("p1", "Lok")), diff --git a/compliance-dashboard/src/pages/target.rs b/compliance-dashboard/src/pages/target.rs index 1117a7d..dd91fc6 100644 --- a/compliance-dashboard/src/pages/target.rs +++ b/compliance-dashboard/src/pages/target.rs @@ -10,7 +10,6 @@ use crate::app::Route; use crate::components::artifact_upload::ArtifactUpload; use crate::components::billing_swap::BillingSwap; use crate::components::cra_bar::CraBar; -use crate::components::cve_matrix::CveView; use crate::components::cve_trend::TargetCveDashboard; use crate::components::evidence_button::EvidencePackButton; use crate::components::layer_pins::LayerPinsCard; @@ -22,7 +21,9 @@ use crate::components::scan_runs::ScanRunList; use crate::components::severity_badge::SeverityBadge; use crate::components::toast::{ToastType, Toasts}; use crate::components::webhook_deliveries::WebhookDeliveries; -use crate::i18n::texts::{common, compliance::language_name, kinds, targets as tx}; +use crate::i18n::texts::{ + common, compliance::language_name, kinds, repo_views as rv, targets as tx, +}; use crate::i18n::use_lang; use crate::infrastructure::evidence::{fetch_compliance, CraCounts}; use crate::infrastructure::findings::{fetch_findings, location, FindingsQuery}; @@ -33,7 +34,10 @@ use crate::infrastructure::onboarding::{ ArchivePassword, ArtifactInputDto, PasswordOutcome, }; use crate::infrastructure::platform::{use_source_only, SourceOnlyNote}; -use crate::infrastructure::projects::{fetch_projects, project_ids_of, set_target_projects}; +use crate::infrastructure::projects::{ + fetch_projects, project_ids_of, projects_named, set_target_projects, +}; +use crate::pages::target_views::{RepoCrumbs, RepoView, TodayLink}; /// Open findings listed on the page; the rest are one click away. const OPEN_SHOWN: usize = 5; @@ -93,10 +97,10 @@ fn editable_artifacts(target: &serde_json::Value) -> Vec { .unwrap_or_default() } -/// The page of target `id`. `cve_severity` and `cve_vex` are the CVE grid's -/// cell from the URL query (see [`CveView`]). +/// The page of target `id`: its dashboard, with the way to its views +/// ([`crate::pages::target_views`]) and to Heute. #[component] -pub fn TargetPage(id: String, cve_severity: Option, cve_vex: Option) -> Element { +pub fn TargetPage(id: String) -> Element { let lang = use_lang()(); let can_write = use_can_write(); let mut toasts = use_context::(); @@ -165,8 +169,16 @@ pub fn TargetPage(id: String, cve_severity: Option, cve_vex: Option 0); + let project_names: Vec = match &*projects.read() { + Some(Ok(all)) => projects_named(&project_ids_of(&t), all) + .into_iter() + .map(|p| p.name.clone()) + .collect(), + _ => Vec::new(), + }; + rsx! { - BackLink {} + RepoCrumbs { target_id: id.clone(), name: name.clone(), projects: project_names, view: None } header { class: "target-head", div { class: "target-head-text", @@ -190,44 +202,54 @@ pub fn TargetPage(id: String, cve_severity: Option, cve_vex: Option { - toasts.push(ToastType::Success, tx::SCAN_STARTED.get(lang)); - scans_started += 1; - } - Err(e) => toasts.push(ToastType::Error, e.to_string()), + Link { + class: "btn btn-secondary", + to: Route::target_view(id.clone(), RepoView::Findings), + title: rv::ALL_VIEWS_HINT.get(lang), + {rv::ALL_VIEWS.get(lang)} + Icon { icon: BsArrowRight, width: 14, height: 14 } + } + TodayLink { target_id: id.clone() } + } + } + div { class: "target-head-tools", + if can_write { + button { + class: "btn btn-ghost", + disabled: starting(), + onclick: move |_| { + starting.set(true); + spawn(async move { + match trigger_target_scan(target_id()).await { + Ok(_) => { + toasts.push(ToastType::Success, tx::SCAN_STARTED.get(lang)); + scans_started += 1; } - starting.set(false); - status.restart(); - }); - }, - Icon { icon: BsPlayFill, width: 16, height: 16 } - {tx::RUN_SCAN.get(lang)} - } + Err(e) => toasts.push(ToastType::Error, e.to_string()), + } + starting.set(false); + status.restart(); + }); + }, + Icon { icon: BsPlayFill, width: 16, height: 16 } + {tx::RUN_SCAN.get(lang)} } - EvidencePackButton { target_id: id.clone() } - if can_write { - button { - class: "btn btn-ghost", - onclick: move |_| editing.set(true), - Icon { icon: BsPencil, width: 14, height: 14 } - {tx::EDIT.get(lang)} - } + } + EvidencePackButton { target_id: id.clone() } + if can_write { + button { + class: "btn btn-ghost", + onclick: move |_| editing.set(true), + Icon { icon: BsPencil, width: 14, height: 14 } + {tx::EDIT.get(lang)} } - if can_write { - button { - class: "btn btn-ghost btn-ghost-danger", - onclick: move |_| confirm_delete.set(true), - Icon { icon: BsTrash, width: 14, height: 14 } - {tx::DELETE.get(lang)} - } + } + if can_write { + button { + class: "btn btn-ghost btn-ghost-danger", + onclick: move |_| confirm_delete.set(true), + Icon { icon: BsTrash, width: 14, height: 14 } + {tx::DELETE.get(lang)} } } } @@ -352,11 +374,6 @@ pub fn TargetPage(id: String, cve_severity: Option, cve_vex: Option &'static str { + match self { + Self::Findings => "findings", + Self::Cves => "cves", + Self::Components => "components", + Self::Licences => "licences", + Self::Cra => "cra", + Self::History => "history", + } + } + + /// The view named `slug`; an unknown name opens the first tab. + pub fn from_slug(slug: &str) -> Self { + Self::ALL + .into_iter() + .find(|v| v.slug() == slug) + .unwrap_or(Self::Findings) + } + + /// The tab's label. + pub fn label(self, lang: Lang) -> &'static str { + match self { + Self::Findings => tx::FINDINGS, + Self::Cves => tx::CVES, + Self::Components => tx::COMPONENTS, + Self::Licences => tx::LICENCES, + Self::Cra => tx::CRA, + Self::History => tx::HISTORY, + } + .get(lang) + } +} + +/// The figure next to a tab's label: the open findings, and from the +/// target's CRA status its CVEs, components and CRA counts; `None` while +/// they load or when the view has no figure. +fn tab_figure( + view: RepoView, + status: Option<&serde_json::Value>, + open_findings: Option, + lang: Lang, +) -> Option { + let number = |key: &str| status?.get(key)?.as_u64(); + match view { + RepoView::Findings => open_findings.map(|n| tx::open(n, lang)), + RepoView::Cves => number("cve_alerts").map(|n| format_count(n, lang)), + RepoView::Components => number("sbom_components").map(|n| format_count(n, lang)), + RepoView::Cra => serde_json::from_value::(status?.get("counts")?.clone()) + .ok() + .map(|c| { + let total = c.not_satisfied + + c.not_assessed + + c.partial + + c.no_violation_found + + c.not_code_checkable; + format!("{}/{total}", c.no_violation_found + c.not_code_checkable) + }), + RepoView::Licences | RepoView::History => None, + } +} + +/// The breadcrumb of target `target_id`: Überblick › its projects › its +/// name, and the open `view` when there is one. +#[component] +pub fn RepoCrumbs( + target_id: String, + name: String, + projects: Vec, + view: Option, +) -> Element { + let lang = use_lang()(); + rsx! { + nav { class: "repo-crumbs", "aria-label": tx::BREADCRUMB.get(lang), + Link { to: Route::OverviewPage {}, {tx::OVERVIEW.get(lang)} } + if !projects.is_empty() { + span { class: "repo-crumb-sep", "aria-hidden": "true", "›" } + span { "{projects.join(\", \")}" } + } + span { class: "repo-crumb-sep", "aria-hidden": "true", "›" } + match view { + Some(view) => rsx! { + Link { class: "repo-crumb-name", to: Route::target(target_id.clone()), "{name}" } + span { class: "repo-crumb-sep", "aria-hidden": "true", "›" } + span { "aria-current": "page", {view.label(lang)} } + }, + None => rsx! { span { class: "repo-crumb-name", "aria-current": "page", "{name}" } }, + } + } + } +} + +/// "N heute zu entscheiden →": Heute, narrowed to target `target_id`. +#[component] +pub fn TodayLink(target_id: String) -> Element { + let lang = use_lang()(); + let id = target_id.clone(); + let view = use_resource(move || { + let id = id.clone(); + async move { fetch_inbox(id, Bucket::Today, Some(0)).await.ok() } + }); + let today = view + .read() + .as_ref() + .and_then(|v| v.as_ref().map(|v| v.counts.today)); + rsx! { + Link { + class: if today.unwrap_or(0) > 0 { "btn btn-primary" } else { "btn btn-secondary" }, + to: Route::heute(target_id, Some(Bucket::Today)), + match today { + Some(n) => rsx! { {tx::today(n, lang)} }, + None => rsx! { {tx::TODAY.get(lang)} }, + } + Icon { icon: BsArrowRight, width: 14, height: 14 } + } + } +} + +/// The views of target `id`, tab `view` open. `cve_severity` and `cve_vex` +/// are the CVE grid's cell from the URL query (see [`CveView`]). +#[component] +pub fn TargetViewsPage( + id: String, + view: String, + cve_severity: Option, + cve_vex: Option, +) -> Element { + let lang = use_lang()(); + let current = RepoView::from_slug(&view); + // The page stays mounted from tab to tab (only `view` changes); another + // target's `id` loads again. + let target = use_resource(use_reactive!( + |id| async move { fetch_target(id).await.ok() } + )); + let status = use_resource(use_reactive!(|id| async move { + fetch_compliance(id).await.ok() + })); + let open_findings = use_resource(use_reactive!(|id| async move { + fetch_findings(FindingsQuery { + page: 1, + repo_id: id, + status: "open".to_string(), + ..Default::default() + }) + .await + .ok() + .and_then(|r| r.total) + })); + let projects = use_resource(fetch_projects); + + let target_json = target.read().clone().flatten().map(|r| r.data); + let name = target_json + .as_ref() + .and_then(|t| t.get("name").and_then(|n| n.as_str())) + .unwrap_or_default() + .to_string(); + let project_names: Vec = match (&target_json, &*projects.read()) { + (Some(t), Some(Ok(all))) => projects_named(&project_ids_of(t), all) + .into_iter() + .map(|p| p.name.clone()) + .collect(), + _ => Vec::new(), + }; + let status = status.read().clone().flatten(); + let open_findings = open_findings.read().flatten(); + + rsx! { + RepoCrumbs { target_id: id.clone(), name: name.clone(), projects: project_names, view: Some(current) } + header { class: "repo-head", + div { class: "repo-head-text", + h2 { class: "repo-head-name", "{name}" } + p { class: "repo-head-sub", {tx::SUBTITLE.get(lang)} } + } + TodayLink { target_id: id.clone() } + } + nav { class: "repo-tabs", role: "tablist", "aria-label": tx::TABS.get(lang), + for v in RepoView::ALL { + Link { + key: "{v.slug()}", + class: if v == current { "repo-tab is-active" } else { "repo-tab" }, + role: "tab", + "aria-selected": if v == current { "true" } else { "false" }, + to: Route::target_view(id.clone(), v), + {v.label(lang)} + if let Some(figure) = tab_figure(v, status.as_ref(), open_findings, lang) { + span { class: "repo-tab-figure", "{figure}" } + } + } + } + } + div { class: "repo-view", + match current { + RepoView::Findings => rsx! { + FindingBreakdownView { target: id.clone(), scan_type: None, severity: None, path: None } + Link { class: "repo-view-list", to: Route::findings(id.clone()), {tx::FINDINGS_LIST.get(lang)} } + }, + RepoView::Cves => rsx! { + CveView { target_id: id.clone(), cve_severity, cve_vex } + }, + RepoView::Components => rsx! { + ComponentsTab { target_id: id.clone() } + }, + RepoView::Licences => rsx! { + LicencesTab { target_id: id.clone() } + }, + RepoView::Cra => rsx! { + section { class: "card", + match status.as_ref().and_then(|s| serde_json::from_value::(s["counts"].clone()).ok()) { + Some(counts) => rsx! { CraBar { counts } }, + None => rsx! { div { class: "loading", {common::LOADING.get(lang)} } }, + } + p { class: "target-muted", {tx::CRA_COMING.get(lang)} } + Link { class: "repo-view-list", to: Route::CompliancePage { id: id.clone() }, {tx::CRA_LIST.get(lang)} } + } + }, + RepoView::History => rsx! { + section { class: "card", + p { class: "target-muted", {tx::HISTORY_COMING.get(lang)} } + ScanRunList { target_id: id.clone() } + } + }, + } + } + } +} + +/// The components view: updates ranked by the CVEs they remove, and the +/// components per ecosystem; an ecosystem opens the SBOM list filtered to it. +#[component] +fn ComponentsTab(target_id: String) -> Element { + let navigator = use_navigator(); + let target = target_id.clone(); + rsx! { + ComponentOverview { + target_id, + ecosystem: String::new(), + on_ecosystem: move |ecosystem: String| { + navigator.push(Route::SbomEcosystemPage { ecosystem, target: target.clone() }); + }, + } + } +} + +/// The licence view: the bar of the licence groups; a group opens its +/// licences, with the components under each. +#[component] +fn LicencesTab(target_id: String) -> Element { + let lang = use_lang()(); + let selected = use_signal(|| None::); + let id = target_id.clone(); + let summary = use_resource(move || { + let id = id.clone(); + async move { fetch_license_summary(Some(id)).await.ok() } + }); + let Some(Some(summary)) = summary.read().clone() else { + return rsx! { div { class: "loading", {common::LOADING.get(lang)} } }; + }; + let counts: LicenseGroupCounts = summary.data.iter().map(|l| (l.category, l.count)).collect(); + let group: Option = selected(); + let licences: Vec = summary + .data + .into_iter() + .filter(|l| group.is_some_and(|g| l.category.group() == g)) + .collect(); + rsx! { + crate::components::licence_overview::LicenceOverview { counts, selected } + if group.is_some() { + div { class: "card table-wrapper", + table { + thead { + tr { + th { {tx::LICENCE.get(lang)} } + th { class: "co-num", {tx::COUNT.get(lang)} } + th { {tx::USED_BY.get(lang)} } + } + } + tbody { + for l in licences { + tr { key: "{l.license}", + td { "{l.license}" } + td { class: "co-num", {format_count(l.count, lang)} } + td { class: "repo-licence-packages", "{l.packages.join(\", \")}" } + } + } + } + } + } + Link { + class: "repo-view-list", + to: Route::SbomPage { target: target_id }, + {tx::LICENCES_LIST.get(lang)} + } + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn every_view_reads_back_from_its_slug_and_an_unknown_one_opens_the_first() { + for view in RepoView::ALL { + assert_eq!(RepoView::from_slug(view.slug()), view); + } + assert_eq!(RepoView::from_slug("nope"), RepoView::Findings); + } + + #[test] + fn the_tabs_show_the_figures_the_status_has() { + let status = serde_json::json!({ + "cve_alerts": 15, + "sbom_components": 312, + "counts": { + "not_satisfied": 6, "not_assessed": 8, "partial": 0, + "no_violation_found": 14, "not_code_checkable": 12, + }, + }); + let figure = |v| tab_figure(v, Some(&status), Some(47), Lang::De); + assert_eq!(figure(RepoView::Findings).as_deref(), Some("47 offen")); + assert_eq!(figure(RepoView::Cves).as_deref(), Some("15")); + assert_eq!(figure(RepoView::Components).as_deref(), Some("312")); + assert_eq!(figure(RepoView::Cra).as_deref(), Some("26/40")); + assert_eq!(figure(RepoView::Licences), None); + assert_eq!(figure(RepoView::History), None); + assert_eq!(tab_figure(RepoView::Cves, None, None, Lang::De), None); + assert_eq!(tab_figure(RepoView::Findings, None, None, Lang::De), None); + } +}