From 48b815a70885bfe6bc70688d44435943f1f7f0fc Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Wed, 23 Sep 2026 14:09:43 +0200 Subject: [PATCH] feat(dashboard): findings show where and what, and saves wait - The findings list shows file:line, scan types and statuses in words, and says so when a filter matches nothing. - The type filter is built from ScanType and sends the stored names: the "Secrets" option sent `secret_detection`, which matches nothing stored (`secretdetection`). Firmware, PLC, ICS and DAST findings are now filterable too. - The detail page has a location card (file:line even without a snippet, scanner, rule id, CRA Annex I refs), marks the current status, re-reads only after a status change is saved, and shows "saved" or why saving failed. Feedback saves when the field is left, not on every keystroke. - Status and feedback saves report the agent's refusal (ok_or_error); the bulk status bar keeps the selection when a save fails. - Both pages in German and English. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- compliance-dashboard/src/i18n/texts.rs | 246 ++++++++++++++++++ .../src/infrastructure/agent_client.rs | 14 + .../src/infrastructure/findings.rs | 62 ++++- .../src/pages/finding_detail.rs | 140 +++++++--- compliance-dashboard/src/pages/findings.rs | 150 +++++------ 5 files changed, 489 insertions(+), 123 deletions(-) diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 2cabd9c..a5b4bbf 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -930,3 +930,249 @@ pub mod onboarding { en: "Onboard another", }; } + +/// The findings list and detail pages. +pub mod findings { + use compliance_core::models::{FindingStatus, ScanType}; + + use super::Text; + + pub const TITLE: Text = Text { + de: "Befunde", + en: "Findings", + }; + pub const SUBTITLE: Text = Text { + de: "Sicherheits- und Compliance-Befunde aller Prüfobjekte", + en: "Security and compliance findings across all targets", + }; + pub const SEARCH: Text = Text { + de: "Befunde durchsuchen …", + en: "Search findings...", + }; + pub const ALL_TARGETS: Text = Text { + de: "Alle Prüfobjekte", + en: "All targets", + }; + pub const ALL_SEVERITIES: Text = Text { + de: "Alle Schweregrade", + en: "All severities", + }; + pub const ALL_TYPES: Text = Text { + de: "Alle Arten", + en: "All types", + }; + pub const ALL_STATUSES: Text = Text { + de: "Alle Status", + en: "All statuses", + }; + pub const INFO: Text = Text { + de: "Info", + en: "Info", + }; + pub const SELECTED: Text = Text { + de: "ausgewählt", + en: "selected", + }; + pub const MARK_AS: Text = Text { + de: "Markieren als", + en: "Mark as", + }; + pub const CLEAR: Text = Text { + de: "Auswahl aufheben", + en: "Clear", + }; + pub const COL_SEVERITY: Text = Text { + de: "Schweregrad", + en: "Severity", + }; + pub const COL_TITLE: Text = Text { + de: "Titel", + en: "Title", + }; + pub const COL_TYPE: Text = Text { + de: "Art", + en: "Type", + }; + pub const COL_SCANNER: Text = Text { + de: "Werkzeug", + en: "Scanner", + }; + pub const COL_LOCATION: Text = Text { + de: "Fundstelle", + en: "Location", + }; + pub const COL_CONTROLS: Text = Text { + de: "CRA", + en: "CRA", + }; + pub const CONTROLS_HINT: Text = Text { + de: "CRA-Anforderungen, für die dieser Befund relevant ist", + en: "CRA requirements this finding is evidence for", + }; + pub const COL_STATUS: Text = Text { + de: "Status", + en: "Status", + }; + pub const LOAD_FAILED: Text = Text { + de: "Die Befunde konnten nicht geladen werden.", + en: "Failed to load findings.", + }; + pub const NONE: Text = Text { + de: "Keine Befunde für diese Auswahl.", + en: "No findings for this selection.", + }; + pub const UPDATE_FAILED: Text = Text { + de: "Der Status konnte nicht gespeichert werden", + en: "The status could not be saved", + }; + pub const BACK: Text = Text { + de: "Zurück", + en: "Back", + }; + pub const NOT_FOUND: Text = Text { + de: "Befund nicht gefunden.", + en: "Finding not found.", + }; + pub const DESCRIPTION: Text = Text { + de: "Beschreibung", + en: "Description", + }; + pub const WHERE: Text = Text { + de: "Fundstelle", + en: "Location", + }; + pub const FILE: Text = Text { + de: "Datei", + en: "File", + }; + pub const RULE: Text = Text { + de: "Regel", + en: "Rule", + }; + pub const CRA_REFS: Text = Text { + de: "CRA-Anforderungen (Anhang I)", + en: "CRA requirements (Annex I)", + }; + pub const CONFIDENCE: Text = Text { + de: "Konfidenz", + en: "Confidence", + }; + pub const TRIAGE: Text = Text { + de: "Einschätzung", + en: "Triage rationale", + }; + pub const CODE: Text = Text { + de: "Code", + en: "Code evidence", + }; + pub const REMEDIATION: Text = Text { + de: "Behebung", + en: "Remediation", + }; + pub const SUGGESTED_FIX: Text = Text { + de: "Vorgeschlagene Korrektur", + en: "Suggested fix", + }; + pub const LINKED_ISSUE: Text = Text { + de: "Verknüpftes Ticket", + en: "Linked issue", + }; + pub const UPDATE_STATUS: Text = Text { + de: "Status ändern", + en: "Update status", + }; + pub const FEEDBACK: Text = Text { + de: "Ihre Einschätzung", + en: "Developer feedback", + }; + pub const FEEDBACK_HINT: Text = Text { + de: "Wie bewerten Sie diesen Befund (z. B. Fehlalarm, umsetzbar, Kontext fehlt)? \ + Wird beim Verlassen des Feldes gespeichert.", + en: "Your assessment of this finding (e.g. false positive, actionable, needs \ + context). Saved when you leave the field.", + }; + pub const SAVED: Text = Text { + de: "Gespeichert", + en: "Saved", + }; + pub const SAVE_FAILED: Text = Text { + de: "Speichern fehlgeschlagen", + en: "Saving failed", + }; + + /// A finding status in words. Exhaustive: a new status needs both. + pub fn status(status: &FindingStatus) -> Text { + match status { + FindingStatus::Open => Text { + de: "Offen", + en: "Open", + }, + FindingStatus::Triaged => Text { + de: "Bewertet", + en: "Triaged", + }, + FindingStatus::FalsePositive => Text { + de: "Fehlalarm", + en: "False positive", + }, + FindingStatus::Resolved => Text { + de: "Behoben", + en: "Resolved", + }, + FindingStatus::Ignored => Text { + de: "Ignoriert", + en: "Ignored", + }, + } + } + + /// A scan type in words. Exhaustive: a new scan type needs both. + pub fn scan_type(scan_type: &ScanType) -> Text { + let (de, en) = match scan_type { + ScanType::Sast => ("Codeanalyse (SAST)", "Code analysis (SAST)"), + ScanType::Sbom => ("SBOM", "SBOM"), + ScanType::Cve => ("Bekannte Schwachstelle (CVE)", "Known vulnerability (CVE)"), + ScanType::Gdpr => ("Datenschutz", "Privacy (GDPR)"), + ScanType::OAuth => ("OAuth", "OAuth"), + ScanType::Graph => ("Code-Graph", "Code graph"), + ScanType::Dast => ("Dynamische Prüfung (DAST)", "Dynamic testing (DAST)"), + ScanType::SecretDetection => ("Zugangsdaten im Code", "Secrets"), + ScanType::Lint => ("Code-Qualität", "Lint"), + ScanType::CodeReview => ("Code-Review", "Code review"), + ScanType::FirmwareStatic => ("Firmware", "Firmware"), + ScanType::PlcControlLogic => ("SPS-Steuerungslogik", "PLC control logic"), + ScanType::MobileStatic => ("Mobile App", "Mobile app"), + ScanType::ContainerScan => ("Container", "Container"), + ScanType::IcsProbe => ("Industrieprotokolle (ICS)", "Industrial protocols (ICS)"), + }; + Text { de, en } + } + + /// Every scan type a finding can carry, in the filter's order. + pub const SCAN_TYPES: [ScanType; 15] = [ + ScanType::Sast, + ScanType::SecretDetection, + ScanType::Cve, + ScanType::Sbom, + ScanType::FirmwareStatic, + ScanType::PlcControlLogic, + ScanType::IcsProbe, + ScanType::Dast, + ScanType::Lint, + ScanType::CodeReview, + ScanType::Gdpr, + ScanType::OAuth, + ScanType::MobileStatic, + ScanType::ContainerScan, + ScanType::Graph, + ]; + + /// Every status, in the order the forms offer them. + pub const STATUSES: [FindingStatus; 5] = [ + FindingStatus::Open, + FindingStatus::Triaged, + FindingStatus::Resolved, + FindingStatus::FalsePositive, + FindingStatus::Ignored, + ]; +} diff --git a/compliance-dashboard/src/infrastructure/agent_client.rs b/compliance-dashboard/src/infrastructure/agent_client.rs index c96d9c1..9c7616b 100644 --- a/compliance-dashboard/src/infrastructure/agent_client.rs +++ b/compliance-dashboard/src/infrastructure/agent_client.rs @@ -66,6 +66,20 @@ pub async fn json_or_error( .map_err(|e| ServerFnError::new(e.to_string())) } +/// Check an agent response whose body the caller does not need. +/// +/// # Errors +/// +/// The refusal for a non-2xx status, as for [`json_or_error`]. +pub async fn ok_or_error(resp: reqwest::Response) -> Result<(), ServerFnError> { + let status = resp.status(); + if status.is_success() { + return Ok(()); + } + let body = resp.text().await.unwrap_or_default(); + Err(ServerFnError::new(refusal_message(status, &body))) +} + /// The message for a refused request: the agent's `error` field when it sent /// one, else the status text, with the status code. fn refusal_message(status: reqwest::StatusCode, body: &str) -> String { diff --git a/compliance-dashboard/src/infrastructure/findings.rs b/compliance-dashboard/src/infrastructure/findings.rs index 37d72d4..459c613 100644 --- a/compliance-dashboard/src/infrastructure/findings.rs +++ b/compliance-dashboard/src/infrastructure/findings.rs @@ -22,6 +22,25 @@ pub struct FindingsQuery { pub sort_order: String, } +/// The value an enum has on the wire (`secretdetection`, `false_positive`), +/// for filters and status updates. +pub fn wire_name(value: &T) -> String { + serde_json::to_value(value) + .ok() + .and_then(|v| v.as_str().map(String::from)) + .unwrap_or_default() +} + +/// Where a finding is, as `file:line` (or just the file). `None` when the +/// finding points at no file (a CVE in a dependency, a DAST endpoint). +pub fn location(file: Option<&str>, line: Option) -> Option { + let file = file.filter(|f| !f.is_empty())?; + Some(match line.filter(|l| *l > 0) { + Some(line) => format!("{file}:{line}"), + None => file.to_string(), + }) +} + /// The control-mapping column is only shown when at least one finding in the /// current view carries `control_refs`. pub fn has_control_refs(findings: &[Finding]) -> bool { @@ -86,7 +105,7 @@ pub async fn fetch_finding_detail(id: String) -> Result #[server] pub async fn update_finding_status(id: String, status: String) -> Result<(), ServerFnError> { - super::agent_client::agent_request( + let resp = super::agent_client::agent_request( reqwest::Method::PATCH, &format!("/api/v1/findings/{id}/status"), ) @@ -95,7 +114,7 @@ pub async fn update_finding_status(id: String, status: String) -> Result<(), Ser .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; - Ok(()) + super::agent_client::ok_or_error(resp).await } #[server] @@ -103,18 +122,19 @@ pub async fn bulk_update_finding_status( ids: Vec, status: String, ) -> Result<(), ServerFnError> { - super::agent_client::agent_request(reqwest::Method::PATCH, "/api/v1/findings/bulk-status") - .await? - .json(&serde_json::json!({ "ids": ids, "status": status })) - .send() - .await - .map_err(|e| ServerFnError::new(e.to_string()))?; - Ok(()) + let resp = + super::agent_client::agent_request(reqwest::Method::PATCH, "/api/v1/findings/bulk-status") + .await? + .json(&serde_json::json!({ "ids": ids, "status": status })) + .send() + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + super::agent_client::ok_or_error(resp).await } #[server] pub async fn update_finding_feedback(id: String, feedback: String) -> Result<(), ServerFnError> { - super::agent_client::agent_request( + let resp = super::agent_client::agent_request( reqwest::Method::PATCH, &format!("/api/v1/findings/{id}/feedback"), ) @@ -123,12 +143,32 @@ pub async fn update_finding_feedback(id: String, feedback: String) -> Result<(), .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; - Ok(()) + super::agent_client::ok_or_error(resp).await } #[cfg(test)] mod tests { use super::*; + + #[test] + fn a_location_reads_file_colon_line() { + assert_eq!( + location(Some("Core/Src/comms.c"), Some(20)).as_deref(), + Some("Core/Src/comms.c:20") + ); + assert_eq!(location(Some("a.c"), Some(0)).as_deref(), Some("a.c")); + assert_eq!(location(Some("a.c"), None).as_deref(), Some("a.c")); + assert_eq!(location(None, Some(3)), None); + assert_eq!(location(Some(""), Some(3)), None); + } + + #[test] + fn filter_values_use_the_stored_names() { + use compliance_core::models::{FindingStatus, ScanType}; + assert_eq!(wire_name(&ScanType::SecretDetection), "secretdetection"); + assert_eq!(wire_name(&ScanType::PlcControlLogic), "plccontrollogic"); + assert_eq!(wire_name(&FindingStatus::FalsePositive), "false_positive"); + } use compliance_core::models::{ScanType, Severity}; fn finding(refs: &[&str]) -> Finding { diff --git a/compliance-dashboard/src/pages/finding_detail.rs b/compliance-dashboard/src/pages/finding_detail.rs index 341bc95..8c02887 100644 --- a/compliance-dashboard/src/pages/finding_detail.rs +++ b/compliance-dashboard/src/pages/finding_detail.rs @@ -5,10 +5,25 @@ use dioxus_free_icons::Icon; use crate::components::code_snippet::CodeSnippet; use crate::components::page_header::PageHeader; use crate::components::severity_badge::SeverityBadge; +use crate::i18n::texts::{common, findings as tx}; +use crate::i18n::use_lang; +use crate::infrastructure::findings::{location, wire_name}; +use crate::pages::findings::status_icon; + +/// What happened to the last save on this page, shown next to what was saved. +#[derive(Debug, Clone, PartialEq)] +enum SaveState { + Idle, + Saved, + Failed(String), +} #[component] pub fn FindingDetailPage(id: String) -> Element { + let lang = use_lang()(); let finding_id = id.clone(); + let mut status_save = use_signal(|| SaveState::Idle); + let mut feedback_save = use_signal(|| SaveState::Idle); let mut finding = use_resource(move || { let fid = finding_id.clone(); @@ -26,19 +41,25 @@ pub fn FindingDetailPage(id: String) -> Element { let finding_id_for_status = id.clone(); let finding_id_for_feedback = id.clone(); let existing_feedback = f.developer_feedback.clone().unwrap_or_default(); + let where_found = location(f.file_path.as_deref(), f.line_number); rsx! { div { class: "back-nav", button { class: "btn btn-ghost btn-back", onclick: move |_| { navigator().go_back(); }, Icon { icon: BsArrowLeft, width: 16, height: 16 } - "Back" + {tx::BACK.get(lang)} } } PageHeader { title: f.title.clone(), - description: format!("{} | {} | {}", f.scanner, f.scan_type, f.status), + description: format!( + "{} | {} | {}", + f.scanner, + tx::scan_type(&f.scan_type).get(lang), + tx::status(&f.status).get(lang) + ), } div { class: "flex gap-2 mb-4", @@ -53,18 +74,44 @@ pub fn FindingDetailPage(id: String) -> Element { span { class: "badge badge-medium", "CVSS: {score}" } } if let Some(confidence) = f.confidence { - span { class: "badge badge-info", "Confidence: {confidence:.1}" } + span { class: "badge badge-info", "{tx::CONFIDENCE.get(lang)}: {confidence:.1}" } } } div { class: "card", - div { class: "card-header", "Description" } + div { class: "card-header", {tx::DESCRIPTION.get(lang)} } p { "{f.description}" } } + // Where it is and what it violates, even when there is no + // snippet to show (a binary, a file no longer readable). + div { class: "card", + div { class: "card-header", {tx::WHERE.get(lang)} } + div { style: "display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px;", + if let Some(place) = where_found.clone() { + span { style: "opacity: 0.7;", {tx::FILE.get(lang)} } + span { style: "font-family: monospace;", "{place}" } + } + span { style: "opacity: 0.7;", {tx::COL_SCANNER.get(lang)} } + span { "{f.scanner}" } + if let Some(rule) = &f.rule_id { + span { style: "opacity: 0.7;", {tx::RULE.get(lang)} } + span { style: "font-family: monospace; word-break: break-all;", "{rule}" } + } + if !f.control_refs.is_empty() { + span { style: "opacity: 0.7;", {tx::CRA_REFS.get(lang)} } + div { style: "display: flex; gap: 4px; flex-wrap: wrap;", + for c in f.control_refs.iter() { + span { class: "badge badge-info", "{c}" } + } + } + } + } + } + if let Some(rationale) = &f.triage_rationale { div { class: "card", - div { class: "card-header", "Triage Rationale" } + div { class: "card-header", {tx::TRIAGE.get(lang)} } div { style: "display: flex; align-items: center; gap: 8px; margin-bottom: 8px;", if let Some(action) = &f.triage_action { @@ -77,7 +124,7 @@ pub fn FindingDetailPage(id: String) -> Element { if let Some(code) = &f.code_snippet { div { class: "card", - div { class: "card-header", "Code Evidence" } + div { class: "card-header", {tx::CODE.get(lang)} } CodeSnippet { code: code.clone(), file_path: f.file_path.clone().unwrap_or_default(), @@ -88,21 +135,21 @@ pub fn FindingDetailPage(id: String) -> Element { if let Some(remediation) = &f.remediation { div { class: "card", - div { class: "card-header", "Remediation" } + div { class: "card-header", {tx::REMEDIATION.get(lang)} } p { "{remediation}" } } } if let Some(fix) = &f.suggested_fix { div { class: "card", - div { class: "card-header", "Suggested Fix" } + div { class: "card-header", {tx::SUGGESTED_FIX.get(lang)} } CodeSnippet { code: fix.clone() } } } if let Some(url) = &f.tracker_issue_url { div { class: "card", - div { class: "card-header", "Linked Issue" } + div { class: "card-header", {tx::LINKED_ISSUE.get(lang)} } a { href: "{url}", target: "_blank", @@ -113,73 +160,90 @@ pub fn FindingDetailPage(id: String) -> Element { } div { class: "card", - div { class: "card-header", "Update Status" } + div { class: "card-header", {tx::UPDATE_STATUS.get(lang)} } div { class: "flex gap-2", - for status in ["open", "triaged", "resolved", "false_positive", "ignored"] { + for status in tx::STATUSES { { - let status_str = status.to_string(); + let current = status == f.status; + let wire = wire_name(&status); let id_clone = finding_id_for_status.clone(); - let label = match status { - "open" => "Open", - "triaged" => "Triaged", - "resolved" => "Resolved", - "false_positive" => "False Positive", - "ignored" => "Ignored", - _ => status, - }; + let label = tx::status(&status).get(lang); rsx! { button { - class: "btn btn-ghost", + class: if current { "btn btn-primary" } else { "btn btn-ghost" }, title: "{label}", + disabled: current, onclick: move |_| { - let s = status_str.clone(); + let s = wire.clone(); let id = id_clone.clone(); spawn(async move { - let _ = crate::infrastructure::findings::update_finding_status(id, s).await; + // Re-read only after the save: restarting + // at once raced it and showed the old status. + match crate::infrastructure::findings::update_finding_status(id, s).await { + Ok(()) => status_save.set(SaveState::Saved), + Err(e) => status_save.set(SaveState::Failed(e.to_string())), + } + finding.restart(); }); - finding.restart(); }, - match status { - "open" => rsx! { Icon { icon: BsCircle, width: 14, height: 14 } }, - "triaged" => rsx! { Icon { icon: BsEye, width: 14, height: 14 } }, - "resolved" => rsx! { Icon { icon: BsCheckCircle, width: 14, height: 14 } }, - "false_positive" => rsx! { Icon { icon: BsXCircle, width: 14, height: 14 } }, - "ignored" => rsx! { Icon { icon: BsDashCircle, width: 14, height: 14 } }, - _ => rsx! {}, - } + {status_icon(&status)} " {label}" } } } } } + SaveNote { state: status_save() } } div { class: "card", - div { class: "card-header", "Developer Feedback" } + div { class: "card-header", {tx::FEEDBACK.get(lang)} } p { style: "font-size: 13px; color: var(--text-secondary); margin-bottom: 8px;", - "Share your assessment of this finding (e.g. false positive, actionable, needs context)" + {tx::FEEDBACK_HINT.get(lang)} } textarea { style: "width: 100%; min-height: 80px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; color: var(--text-primary); font-size: 14px; resize: vertical;", value: "{existing_feedback}", - oninput: move |e| { + // `change` fires when the field loses focus: one save per + // edit, not one per keystroke racing each other. + onchange: move |e| { let feedback = e.value(); let id = finding_id_for_feedback.clone(); spawn(async move { - let _ = crate::infrastructure::findings::update_finding_feedback(id, feedback).await; + match crate::infrastructure::findings::update_finding_feedback(id, feedback).await { + Ok(()) => feedback_save.set(SaveState::Saved), + Err(e) => feedback_save.set(SaveState::Failed(e.to_string())), + } }); }, } + SaveNote { state: feedback_save() } } } } Some(None) => rsx! { - div { class: "card", p { "Finding not found." } } + div { class: "card", p { {tx::NOT_FOUND.get(lang)} } } }, None => rsx! { - div { class: "loading", "Loading finding..." } + div { class: "loading", {common::LOADING.get(lang)} } + }, + } +} + +/// "Saved", or why saving failed. +#[component] +fn SaveNote(state: SaveState) -> Element { + let lang = use_lang()(); + match state { + SaveState::Idle => rsx! {}, + SaveState::Saved => rsx! { + div { style: "margin-top: 6px; font-size: 13px; color: var(--success);", {tx::SAVED.get(lang)} } + }, + SaveState::Failed(e) => rsx! { + div { style: "margin-top: 6px; font-size: 13px; color: var(--danger);", + "{tx::SAVE_FAILED.get(lang)}: {e}" + } }, } } diff --git a/compliance-dashboard/src/pages/findings.rs b/compliance-dashboard/src/pages/findings.rs index d84d84d..18b2518 100644 --- a/compliance-dashboard/src/pages/findings.rs +++ b/compliance-dashboard/src/pages/findings.rs @@ -6,10 +6,15 @@ use crate::app::Route; use crate::components::page_header::PageHeader; use crate::components::pagination::Pagination; use crate::components::severity_badge::SeverityBadge; -use crate::infrastructure::findings::has_control_refs; +use crate::components::toast::{ToastType, Toasts}; +use crate::i18n::texts::{common, findings as tx}; +use crate::i18n::use_lang; +use crate::infrastructure::findings::{has_control_refs, location, wire_name}; #[component] pub fn FindingsPage(target: String) -> Element { + let lang = use_lang()(); + let mut toasts = use_context::(); let mut page = use_signal(|| 1u64); let mut severity_filter = use_signal(String::new); let mut type_filter = use_signal(String::new); @@ -74,20 +79,20 @@ pub fn FindingsPage(target: String) -> Element { rsx! { PageHeader { - title: "Findings", - description: "Security and compliance findings across all repositories", + title: tx::TITLE.get(lang), + description: tx::SUBTITLE.get(lang), } div { class: "filter-bar", input { r#type: "text", - placeholder: "Search findings...", + placeholder: tx::SEARCH.get(lang), style: "min-width: 200px;", oninput: move |e| { search_query.set(e.value()); page.set(1); }, } select { onchange: move |e| { repo_filter.set(e.value()); page.set(1); }, - option { value: "", "All Targets" } + option { value: "", {tx::ALL_TARGETS.get(lang)} } { match &*repos.read() { Some(Some(resp)) => rsx! { @@ -96,7 +101,7 @@ pub fn FindingsPage(target: String) -> Element { let id = t.get("_id").and_then(|o| o.get("$oid")).and_then(|s| s.as_str()).unwrap_or_default().to_string(); let name = t.get("name").and_then(|n| n.as_str()).unwrap_or_default().to_string(); rsx! { - option { value: "{id}", "{name}" } + option { value: "{id}", selected: repo_filter() == id, "{name}" } } } } @@ -107,32 +112,27 @@ pub fn FindingsPage(target: String) -> Element { } select { onchange: move |e| { severity_filter.set(e.value()); page.set(1); }, - option { value: "", "All Severities" } - option { value: "critical", "Critical" } - option { value: "high", "High" } - option { value: "medium", "Medium" } - option { value: "low", "Low" } - option { value: "info", "Info" } + option { value: "", {tx::ALL_SEVERITIES.get(lang)} } + option { value: "critical", {common::CRITICAL.get(lang)} } + option { value: "high", {common::HIGH.get(lang)} } + option { value: "medium", {common::MEDIUM.get(lang)} } + option { value: "low", {common::LOW.get(lang)} } + option { value: "info", {tx::INFO.get(lang)} } } select { onchange: move |e| { type_filter.set(e.value()); page.set(1); }, - option { value: "", "All Types" } - option { value: "sast", "SAST" } - option { value: "sbom", "SBOM" } - option { value: "cve", "CVE" } - option { value: "gdpr", "GDPR" } - option { value: "oauth", "OAuth" } - option { value: "secret_detection", "Secrets" } - option { value: "lint", "Lint" } + option { value: "", {tx::ALL_TYPES.get(lang)} } + // The stored names (`secretdetection`), which a filter must match. + for scan_type in tx::SCAN_TYPES { + option { value: "{wire_name(&scan_type)}", {tx::scan_type(&scan_type).get(lang)} } + } } select { onchange: move |e| { status_filter.set(e.value()); page.set(1); }, - option { value: "", "All Statuses" } - option { value: "open", "Open" } - option { value: "triaged", "Triaged" } - option { value: "resolved", "Resolved" } - option { value: "false_positive", "False Positive" } - option { value: "ignored", "Ignored" } + option { value: "", {tx::ALL_STATUSES.get(lang)} } + for status in tx::STATUSES { + option { value: "{wire_name(&status)}", {tx::status(&status).get(lang)} } + } } } @@ -143,41 +143,33 @@ pub fn FindingsPage(target: String) -> Element { style: "display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin-bottom: 16px; background: rgba(56, 189, 248, 0.08); border-color: rgba(56, 189, 248, 0.2);", span { style: "font-size: 14px; color: var(--text-secondary);", - "{selected_ids().len()} selected" + "{selected_ids().len()} {tx::SELECTED.get(lang)}" } - for status in ["triaged", "resolved", "false_positive", "ignored"] { + for status in tx::STATUSES.into_iter().skip(1) { { - let status_str = status.to_string(); - let label = match status { - "false_positive" => "False Positive", - other => { - // Capitalize first letter - let mut s = other.to_string(); - if let Some(c) = s.get_mut(0..1) { c.make_ascii_uppercase(); } - // Leak to get a &str that lives long enough - this is fine for static-ish UI strings - &*Box::leak(s.into_boxed_str()) - } - }; + let label = tx::status(&status).get(lang); + let wire = wire_name(&status); rsx! { button { class: "btn btn-sm btn-ghost", - title: "Mark {label}", + title: "{tx::MARK_AS.get(lang)} {label}", onclick: move |_| { let ids = selected_ids(); - let s = status_str.clone(); + let s = wire.clone(); spawn(async move { - let _ = crate::infrastructure::findings::bulk_update_finding_status(ids, s).await; + // Wait for the save: the list must show what + // was stored, and a refusal must be seen. + match crate::infrastructure::findings::bulk_update_finding_status(ids, s).await { + Ok(()) => selected_ids.set(Vec::new()), + Err(e) => toasts.push( + ToastType::Error, + format!("{}: {e}", tx::UPDATE_FAILED.get(lang)), + ), + } findings.restart(); }); - selected_ids.set(Vec::new()); }, - match status { - "triaged" => rsx! { Icon { icon: BsEye, width: 14, height: 14 } }, - "resolved" => rsx! { Icon { icon: BsCheckCircle, width: 14, height: 14 } }, - "false_positive" => rsx! { Icon { icon: BsXCircle, width: 14, height: 14 } }, - "ignored" => rsx! { Icon { icon: BsDashCircle, width: 14, height: 14 } }, - _ => rsx! {}, - } + {status_icon(&status)} " {label}" } } @@ -186,7 +178,7 @@ pub fn FindingsPage(target: String) -> Element { button { class: "btn btn-sm btn-ghost", onclick: move |_| { selected_ids.set(Vec::new()); }, - "Clear" + {tx::CLEAR.get(lang)} } } } @@ -220,31 +212,38 @@ pub fn FindingsPage(target: String) -> Element { th { style: "cursor: pointer; user-select: none;", onclick: toggle_sort("severity"), - "Severity{sort_indicator(\"severity\")}" + "{tx::COL_SEVERITY.get(lang)}{sort_indicator(\"severity\")}" } th { style: "cursor: pointer; user-select: none;", onclick: toggle_sort("title"), - "Title{sort_indicator(\"title\")}" + "{tx::COL_TITLE.get(lang)}{sort_indicator(\"title\")}" } th { style: "cursor: pointer; user-select: none;", onclick: toggle_sort("scan_type"), - "Type{sort_indicator(\"scan_type\")}" + "{tx::COL_TYPE.get(lang)}{sort_indicator(\"scan_type\")}" } - th { "Scanner" } - th { "File" } + th { {tx::COL_SCANNER.get(lang)} } + th { {tx::COL_LOCATION.get(lang)} } if show_controls { - th { title: "Compliance controls this finding is evidence for", "Controls" } + th { title: tx::CONTROLS_HINT.get(lang), {tx::COL_CONTROLS.get(lang)} } } th { style: "cursor: pointer; user-select: none;", onclick: toggle_sort("status"), - "Status{sort_indicator(\"status\")}" + "{tx::COL_STATUS.get(lang)}{sort_indicator(\"status\")}" } } } tbody { + if resp.data.is_empty() { + tr { + td { colspan: "8", style: "text-align: center; opacity: 0.6; padding: 24px;", + {tx::NONE.get(lang)} + } + } + } for finding in &resp.data { { let id = finding.id.as_ref().map(|id| id.to_hex()).unwrap_or_default(); @@ -275,7 +274,7 @@ pub fn FindingsPage(target: String) -> Element { "{finding.title}" } } - td { "{finding.scan_type}" } + td { {tx::scan_type(&finding.scan_type).get(lang)} } td { Icon { icon: BsCpu, width: 14, height: 14 } " {finding.scanner}" @@ -283,13 +282,13 @@ pub fn FindingsPage(target: String) -> Element { td { style: "font-family: monospace; font-size: 12px;", Icon { icon: BsFileEarmarkCode, width: 14, height: 14 } - " {finding.file_path.as_deref().unwrap_or(\"-\")}" + " {location(finding.file_path.as_deref(), finding.line_number).unwrap_or_else(|| \"—\".to_string())}" } if show_controls { td { div { style: "display: flex; gap: 4px; flex-wrap: wrap;", for c in finding.control_refs.iter() { - span { class: "badge badge-info", title: "Control {c}", "{c}" } + span { class: "badge badge-info", title: tx::CONTROLS_HINT.get(lang), "{c}" } } if finding.control_refs.is_empty() { span { style: "opacity: 0.4;", "—" } @@ -299,17 +298,8 @@ pub fn FindingsPage(target: String) -> Element { } td { span { class: "badge badge-info", - { - use compliance_core::models::FindingStatus; - match &finding.status { - FindingStatus::Open => rsx! { Icon { icon: BsCircle, width: 12, height: 12 } }, - FindingStatus::Triaged => rsx! { Icon { icon: BsEye, width: 12, height: 12 } }, - FindingStatus::Resolved => rsx! { Icon { icon: BsCheckCircle, width: 12, height: 12 } }, - FindingStatus::FalsePositive => rsx! { Icon { icon: BsXCircle, width: 12, height: 12 } }, - FindingStatus::Ignored => rsx! { Icon { icon: BsDashCircle, width: 12, height: 12 } }, - } - } - " {finding.status}" + {status_icon(&finding.status)} + " {tx::status(&finding.status).get(lang)}" } } } @@ -328,11 +318,23 @@ pub fn FindingsPage(target: String) -> Element { } }, Some(None) => rsx! { - div { class: "card", p { "Failed to load findings." } } + div { class: "card", p { {tx::LOAD_FAILED.get(lang)} } } }, None => rsx! { - div { class: "loading", "Loading findings..." } + div { class: "loading", {common::LOADING.get(lang)} } }, } } } + +/// The icon for a finding status, shared by the list and the detail page. +pub fn status_icon(status: &compliance_core::models::FindingStatus) -> Element { + use compliance_core::models::FindingStatus; + match status { + FindingStatus::Open => rsx! { Icon { icon: BsCircle, width: 12, height: 12 } }, + FindingStatus::Triaged => rsx! { Icon { icon: BsEye, width: 12, height: 12 } }, + FindingStatus::Resolved => rsx! { Icon { icon: BsCheckCircle, width: 12, height: 12 } }, + FindingStatus::FalsePositive => rsx! { Icon { icon: BsXCircle, width: 12, height: 12 } }, + FindingStatus::Ignored => rsx! { Icon { icon: BsDashCircle, width: 12, height: 12 } }, + } +} -- 2.54.1