From 62e9700d8de6d2c6c1c087958cc4c7a62f86a77a Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Sat, 26 Sep 2026 09:46:20 +0200 Subject: [PATCH] feat(dashboard): the CRA status page grouped by what needs doing The page was a flat 40-row table with six stat tiles and the same explanation repeated on every process requirement. Now: - the CRA bar with its legend, the last scan, languages, components and known vulnerabilities in one summary; - one section per state, violated first; a reason shared by a whole group is said once instead of on every row; - the 19 requirements evidenced outside the code folded behind one explanation; - back leads to the target's page. The StatCard component and the old severity chart's styles had no users left and are removed. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- compliance-dashboard/assets/main.css | 181 ++++++----- compliance-dashboard/src/components/mod.rs | 1 - .../src/components/stat_card.rs | 17 - compliance-dashboard/src/i18n/texts.rs | 8 +- compliance-dashboard/src/pages/compliance.rs | 296 ++++++++++-------- 5 files changed, 284 insertions(+), 219 deletions(-) delete mode 100644 compliance-dashboard/src/components/stat_card.rs diff --git a/compliance-dashboard/assets/main.css b/compliance-dashboard/assets/main.css index 7d41644..531956f 100644 --- a/compliance-dashboard/assets/main.css +++ b/compliance-dashboard/assets/main.css @@ -643,35 +643,6 @@ code { background: var(--bg-card); } -.stat-card { - padding: 13px 15px 14px; - border-right: 1px solid var(--border); - border-bottom: 1px solid var(--border); - margin: 0 -1px -1px 0; - position: relative; -} - -.stat-card .label, -.stat-card .stat-label { - font-family: var(--font-mono); - font-size: 10px; - font-weight: 500; - text-transform: uppercase; - letter-spacing: 0.13em; - color: var(--text-tertiary); - margin-bottom: 9px; -} - -.stat-card .value, -.stat-card .stat-value { - font-family: var(--font-mono); - font-variant-numeric: tabular-nums; - font-size: 25px; - font-weight: 500; - letter-spacing: -0.02em; - line-height: 1; -} - /* ── Cards (the portal's panel) ── */ @@ -1470,50 +1441,6 @@ tbody tr:last-child td { } -/* ── Severity Chart ── */ - -.severity-chart { - display: flex; - gap: 8px; - align-items: flex-end; - height: 200px; - padding: 16px 0; -} - -.severity-bar { - flex: 1; - display: flex; - flex-direction: column; - align-items: center; - gap: 6px; - height: 100%; - justify-content: flex-end; -} - -.severity-bar-count { - font-family: var(--font-mono); - font-size: 14px; - font-weight: 600; - color: var(--text-primary); -} - -.severity-bar-fill { - width: 100%; - border-radius: 2px 2px 0 0; - min-height: 4px; - transition: height 0.6s var(--ease-out); - position: relative; -} - -.severity-bar-label { - font-family: var(--font-mono); - font-size: 10px; - font-weight: 500; - color: var(--text-tertiary); - text-transform: uppercase; - letter-spacing: 0.1em; -} - /* ── Toast Notifications (the portal's ink toasts) ── */ @@ -4868,3 +4795,111 @@ tbody tr:last-child td { .card.ov-next { padding: 0; } + +/* ── CRA status page ── */ +.cra-summary { + display: grid; + gap: 12px; + margin-bottom: 20px; +} + +.cra-summary-meta { + font-size: 12.5px; + color: var(--text-tertiary); +} + +.cra-group { + margin-bottom: 16px; +} + +.cra-group-head { + display: flex; + align-items: center; + gap: 10px; + margin-bottom: 8px; +} + +.cra-group-n { + font-family: var(--font-mono); + font-size: 12px; + color: var(--text-tertiary); +} + +.cra-group-hint { + font-size: 12.5px; + color: var(--text-secondary); + max-width: 75ch; + margin-bottom: 8px; +} + +.cra-controls { + list-style: none; +} + +.cra-control { + display: grid; + gap: 4px; + padding: 10px 0; + border-top: 1px solid var(--border); +} + +.cra-control-head { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: 6px 10px; +} + +.cra-control-id { + font-family: var(--font-mono); + font-size: 11.5px; + color: var(--text-tertiary); + min-width: 72px; +} + +.cra-control-title { + font-weight: 500; +} + +.cra-control-evidence { + font-size: 11.5px; + color: var(--text-tertiary); +} + +.cra-control-reason { + padding-left: 82px; + font-size: 12.5px; + color: var(--text-secondary); +} + +.cra-control-findings { + list-style: none; + display: grid; + gap: 3px; + padding-left: 82px; + font-size: 12.5px; +} + +.cra-control-findings code { + font-family: var(--font-mono); + font-size: 11.5px; + color: var(--text-tertiary); +} + +.cra-control-status { + color: var(--text-tertiary); +} + +.cra-fold summary { + cursor: pointer; + font-weight: 500; + color: var(--accent); + padding: 4px 0; +} + +@media (max-width: 640px) { + .cra-control-reason, + .cra-control-findings { + padding-left: 0; + } +} diff --git a/compliance-dashboard/src/components/mod.rs b/compliance-dashboard/src/components/mod.rs index 6b6e501..3bfdb8d 100644 --- a/compliance-dashboard/src/components/mod.rs +++ b/compliance-dashboard/src/components/mod.rs @@ -17,6 +17,5 @@ pub mod scan_coverage; pub mod scan_runs; pub mod severity_badge; pub mod sidebar; -pub mod stat_card; pub mod theme_toggle; pub mod toast; diff --git a/compliance-dashboard/src/components/stat_card.rs b/compliance-dashboard/src/components/stat_card.rs deleted file mode 100644 index c6c790b..0000000 --- a/compliance-dashboard/src/components/stat_card.rs +++ /dev/null @@ -1,17 +0,0 @@ -use dioxus::prelude::*; - -#[component] -pub fn StatCard(label: String, value: String, #[props(default)] color: String) -> Element { - let value_style = if color.is_empty() { - String::new() - } else { - format!("color: {color}") - }; - - rsx! { - div { class: "stat-card", - div { class: "label", "{label}" } - div { class: "value", style: value_style, "{value}" } - } - } -} diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 68f1902..18b64db 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -1862,6 +1862,10 @@ pub mod compliance { de: "Nicht im Code prüfbar", en: "Not checkable in code", }; + pub const SHOW_REQUIREMENTS: Text = Text { + de: "Anforderungen anzeigen", + en: "Show the requirements", + }; pub const NOT_CODE_CHECKABLE_HINT: Text = Text { de: "Eigenschaft des Designs oder Prozesses; wird im BreakPilot-Compliance-Prozess nachgewiesen.", en: "A design or process property; evidenced in the BreakPilot compliance process.", @@ -1887,8 +1891,8 @@ pub mod compliance { en: "Components (SBOM)", }; pub const CVES: Text = Text { - de: "CVE-Warnungen", - en: "CVE alerts", + de: "Bekannte Schwachstellen (CVE)", + en: "Known vulnerabilities (CVE)", }; pub const LAST_SCAN: Text = Text { de: "Letzte Prüfung", diff --git a/compliance-dashboard/src/pages/compliance.rs b/compliance-dashboard/src/pages/compliance.rs index a4b5e24..18d4bd4 100644 --- a/compliance-dashboard/src/pages/compliance.rs +++ b/compliance-dashboard/src/pages/compliance.rs @@ -4,14 +4,17 @@ use dioxus::prelude::*; +use dioxus_free_icons::icons::bs_icons::{BsArrowLeft, BsDownload}; +use dioxus_free_icons::Icon; + use crate::app::Route; -use crate::components::page_header::PageHeader; -use crate::components::stat_card::StatCard; +use crate::components::cra_bar::CraBar; use crate::i18n::texts::{common, compliance as tx, findings as ftx, targets as ttx}; use crate::i18n::{use_lang, Lang, Text}; -use crate::infrastructure::evidence::{evidence_pack_url, fetch_compliance}; +use crate::infrastructure::evidence::{evidence_pack_url, fetch_compliance, CraCounts}; -/// The label and badge of a control state, in the order the page lists them. +/// The label and badge of each control state, in the order the page lists +/// them: violated first, requirements evidenced outside the code last. const STATES: [(&str, Text, &str); 4] = [ ("not_satisfied", tx::NOT_SATISFIED, "badge badge-critical"), ("not_assessed", tx::NOT_ASSESSED, "badge badge-medium"), @@ -27,17 +30,6 @@ const STATES: [(&str, Text, &str); 4] = [ ), ]; -/// Where a state sorts, and how it is shown; an unknown state sorts last and -/// shows as it is. -fn state_info(state: &str) -> (usize, Option<(Text, &'static str)>) { - STATES - .iter() - .position(|(s, _, _)| *s == state) - .map_or((STATES.len(), None), |i| { - (i, Some((STATES[i].1, STATES[i].2))) - }) -} - #[component] pub fn CompliancePage(id: String) -> Element { let lang = use_lang()(); @@ -53,10 +45,8 @@ pub fn CompliancePage(id: String) -> Element { }; let name = data["target_name"].as_str().unwrap_or_default().to_string(); - let count = |key: &str| data["counts"][key].as_u64().unwrap_or(0).to_string(); - let mut controls: Vec = - data["controls"].as_array().cloned().unwrap_or_default(); - controls.sort_by_key(|c| state_info(c["state"].as_str().unwrap_or_default()).0); + let counts: CraCounts = serde_json::from_value(data["counts"].clone()).unwrap_or_default(); + let controls: Vec = data["controls"].as_array().cloned().unwrap_or_default(); // The last scan's status in words, as on the targets page. let last_scan = serde_json::from_value::( data["last_scan"]["status"].clone(), @@ -68,120 +58,165 @@ pub fn CompliancePage(id: String) -> Element { .as_array() .map_or(&[][..], Vec::as_slice), ); + let in_state = |state: &str| -> Vec { + controls + .iter() + .filter(|c| c["state"].as_str() == Some(state)) + .cloned() + .collect() + }; rsx! { - PageHeader { - title: format!("{} · {name}", tx::TITLE.get(lang)), - description: tx::SUBTITLE.get(lang), - } - div { style: "margin-bottom: 16px; display: flex; gap: 8px; flex-wrap: wrap;", - Link { to: Route::TargetsPage {}, class: "btn btn-secondary", "← {ttx::TITLE.get(lang)}" } - a { class: "btn btn-secondary", href: evidence_pack_url(&id), download: "", - {ttx::EVIDENCE_PACK.get(lang)} + div { class: "back-nav", + Link { to: Route::TargetPage { id: id.clone() }, class: "btn btn-ghost btn-back", + Icon { icon: BsArrowLeft, width: 16, height: 16 } + "{name}" } } - - div { class: "stat-cards", - StatCard { label: tx::NOT_SATISFIED.get(lang), value: count("not_satisfied"), color: "var(--danger)" } - StatCard { label: tx::NOT_ASSESSED.get(lang), value: count("not_assessed"), color: "var(--warning)" } - StatCard { label: tx::NO_VIOLATION.get(lang), value: count("no_violation_found"), color: "var(--success)" } - StatCard { label: tx::NOT_CODE_CHECKABLE.get(lang), value: count("not_code_checkable") } - StatCard { label: tx::DEPENDENCIES.get(lang), value: data["sbom_components"].to_string() } - StatCard { label: tx::CVES.get(lang), value: data["cve_alerts"].to_string() } - } - if let Some(status) = last_scan { - p { style: "opacity: 0.75; font-size: 0.9em;", - "{tx::LAST_SCAN.get(lang)}: {status}" - if !languages.is_empty() { - " · {tx::LANGUAGES.get(lang)}: {languages}" + header { class: "target-head", + div { class: "target-head-text", + h2 { {tx::TITLE.get(lang)} } + p { class: "target-head-meta", {tx::SUBTITLE.get(lang)} } + } + div { class: "target-head-actions", + a { class: "btn btn-secondary", href: evidence_pack_url(&id), download: "", + Icon { icon: BsDownload, width: 14, height: 14 } + {ttx::EVIDENCE_PACK.get(lang)} } } - } else { - p { style: "opacity: 0.75; font-size: 0.9em;", {tx::NOT_ASSESSED_HINT.get(lang)} } } - div { class: "card", - div { class: "table-wrapper", - table { - thead { - tr { - th { {tx::CONTROL.get(lang)} } - th { {tx::STATE.get(lang)} } - th { {tx::EVIDENCE.get(lang)} } + section { class: "card cra-summary", + CraBar { counts } + p { class: "cra-summary-meta", + match last_scan { + Some(status) => rsx! { + "{tx::LAST_SCAN.get(lang)}: {status}" + if !languages.is_empty() { + " · {tx::LANGUAGES.get(lang)}: {languages}" + } + }, + None => rsx! { {tx::NOT_ASSESSED_HINT.get(lang)} }, + } + " · {tx::DEPENDENCIES.get(lang)}: {data[\"sbom_components\"]} · {tx::CVES.get(lang)}: {data[\"cve_alerts\"]}" + } + } + + // Violated first; what the code check cleared, then what is + // evidenced outside the code, last and folded. + for (state, label, badge) in STATES.into_iter().take(3) { + { + let group = in_state(state); + // One reason for the whole group is said once, not per row. + let reasons: Vec> = group + .iter() + .map(|c| tx::not_assessed_reason(&c["reason"], lang)) + .collect(); + let shared = reasons + .first() + .cloned() + .flatten() + .filter(|first| reasons.iter().all(|r| r.as_deref() == Some(first.as_str()))); + let per_row = shared.is_none(); + rsx! { + if !group.is_empty() { + section { class: "card cra-group", + h3 { class: "cra-group-head", + span { class: "{badge}", {label.get(lang)} } + span { class: "cra-group-n", "{group.len()}" } + } + if let Some(reason) = shared { + p { class: "cra-group-hint", "{reason}" } + } + ul { class: "cra-controls", + for control in group { + ControlRow { control, lang, show_reason: per_row } + } + } } } - tbody { - for control in controls { - { - let state = control["state"].as_str().unwrap_or_default().to_string(); - let shown = state_info(&state).1; - let findings = control["findings"].as_array().cloned().unwrap_or_default(); - // The control map's notes are engineering prose in - // English; the German hint above says the same. - let note = control["note"] - .as_str() - .filter(|_| lang == Lang::En) - .map(String::from); - let reason = tx::not_assessed_reason(&control["reason"], lang); - let severity = control["severity"].as_str().unwrap_or_default().to_string(); - let severity_label = tx::severity(&severity).map(|t| t.get(lang)); - let evidence = control["evidence_type"] - .as_str() - .and_then(tx::evidence_type) - .map(|t| t.get(lang)); - rsx! { - tr { - td { - div { style: "font-family: monospace; font-size: 0.85em; opacity: 0.7;", "{control[\"control\"].as_str().unwrap_or_default()}" } - div { "{control[\"title\"].as_str().unwrap_or_default()}" } - if severity_label.is_some() || evidence.is_some() { - div { style: "display: flex; gap: 6px; align-items: center; margin-top: 3px; font-size: 0.8em; opacity: 0.8;", - if let Some(label) = severity_label { - span { class: "badge badge-{severity}", "{label}" } - } - if let Some(evidence) = evidence { - span { "{evidence}" } - } - } - } - } - td { - match shown { - Some((label, badge)) => rsx! { span { class: "{badge}", {label.get(lang)} } }, - None => rsx! { span { "{state}" } }, - } - } - td { style: "font-size: 0.9em;", - if state == "not_code_checkable" { - div { style: "opacity: 0.75;", {tx::NOT_CODE_CHECKABLE_HINT.get(lang)} } - if let Some(note) = note { - div { style: "opacity: 0.6; font-size: 0.9em;", "{note}" } - } - } - if let Some(reason) = reason { - div { style: "opacity: 0.75;", "{reason}" } - } - for f in findings { - { - let fid = f["id"].as_str().unwrap_or_default().to_string(); - let status = f["status"].as_str().unwrap_or_default().to_string(); - let status_label = serde_json::from_value::( - serde_json::Value::String(status.clone()), - ) - .map_or(status.clone(), |s| ftx::status(&s).get(lang).to_string()); - rsx! { - div { style: "margin-bottom: 4px;", - Link { to: Route::FindingDetailPage { id: fid }, "{f[\"title\"].as_str().unwrap_or_default()}" } - if let Some(loc) = f["location"].as_str() { - span { style: "font-family: monospace; opacity: 0.75;", " · {loc}" } - } - span { style: "opacity: 0.6;", " · {status_label}" } - } - } - } - } - } + } + } + } + { + let process = in_state("not_code_checkable"); + rsx! { + if !process.is_empty() { + section { class: "card cra-group", + h3 { class: "cra-group-head", + span { class: "badge badge-neutral", {tx::NOT_CODE_CHECKABLE.get(lang)} } + span { class: "cra-group-n", "{process.len()}" } + } + p { class: "cra-group-hint", {tx::NOT_CODE_CHECKABLE_HINT.get(lang)} } + details { class: "cra-fold", + summary { {tx::SHOW_REQUIREMENTS.get(lang)} } + ul { class: "cra-controls", + for control in process { + ControlRow { control, lang, show_reason: true } + } + } + } + } + } + } + } + } +} + +/// One requirement: its id and title, the catalog's rating, and what the +/// state rests on (the findings against it, or why it was not assessed, +/// unless `show_reason` is off because the group states it once). +#[component] +fn ControlRow(control: serde_json::Value, lang: Lang, show_reason: bool) -> Element { + let findings = control["findings"].as_array().cloned().unwrap_or_default(); + // The control map's notes are engineering prose in English; in German + // the group's hint says the same. + let note = control["note"] + .as_str() + .filter(|_| lang == Lang::En) + .map(String::from); + let reason = tx::not_assessed_reason(&control["reason"], lang).filter(|_| show_reason); + let severity = control["severity"].as_str().unwrap_or_default().to_string(); + let severity_label = tx::severity(&severity).map(|t| t.get(lang)); + let evidence = control["evidence_type"] + .as_str() + .and_then(tx::evidence_type) + .map(|t| t.get(lang)); + rsx! { + li { class: "cra-control", + div { class: "cra-control-head", + code { class: "cra-control-id", "{control[\"control\"].as_str().unwrap_or_default()}" } + span { class: "cra-control-title", "{control[\"title\"].as_str().unwrap_or_default()}" } + if let Some(label) = severity_label { + span { class: "badge badge-{severity}", "{label}" } + } + if let Some(evidence) = evidence { + span { class: "cra-control-evidence", "{evidence}" } + } + } + if let Some(reason) = reason { + p { class: "cra-control-reason", "{reason}" } + } + if let Some(note) = note { + p { class: "cra-control-reason", "{note}" } + } + if !findings.is_empty() { + ul { class: "cra-control-findings", + for f in findings { + { + let fid = f["id"].as_str().unwrap_or_default().to_string(); + let status = f["status"].as_str().unwrap_or_default().to_string(); + let status_label = serde_json::from_value::( + serde_json::Value::String(status.clone()), + ) + .map_or(status.clone(), |s| ftx::status(&s).get(lang).to_string()); + rsx! { + li { + Link { to: Route::FindingDetailPage { id: fid }, "{f[\"title\"].as_str().unwrap_or_default()}" } + if let Some(loc) = f["location"].as_str() { + code { " {loc}" } } + span { class: "cra-control-status", " · {status_label}" } } } } @@ -197,9 +232,18 @@ mod tests { use super::*; #[test] - fn violated_controls_come_first() { - assert!(state_info("not_satisfied").0 < state_info("no_violation_found").0); - assert_eq!(state_info("brand_new").0, STATES.len()); - assert!(state_info("brand_new").1.is_none()); + fn violated_requirements_lead_and_process_ones_close() { + // The page lists the first three states as open groups and folds the + // last one; this order is what it relies on. + let order: Vec<&str> = STATES.iter().map(|(state, _, _)| *state).collect(); + assert_eq!( + order, + [ + "not_satisfied", + "not_assessed", + "no_violation_found", + "not_code_checkable" + ] + ); } }