fix(onboarding): targets visibility + unified pipeline by default (#154)
CI / Check (push) Has been skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Agent (push) Successful in 3m41s
CI / Deploy Dashboard (push) Successful in 2m46s
CI / Deploy Docs (push) Has been skipped
CI / Deploy MCP (push) Successful in 1m46s
CI / Check (push) Has been skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Agent (push) Successful in 3m41s
CI / Deploy Dashboard (push) Successful in 2m46s
CI / Deploy Docs (push) Has been skipped
CI / Deploy MCP (push) Successful in 1m46s
This commit was merged in pull request #154.
This commit is contained in:
@@ -0,0 +1,339 @@
|
||||
//! Targets page — lists onboarded targets (the unified `OnboardedTarget`
|
||||
//! records the wizard creates) and lets the user run a scan, inspect the
|
||||
//! classification / applicable scans, or delete a target.
|
||||
//!
|
||||
//! Creation lives in the Onboard wizard (`/onboard`); this page is the
|
||||
//! "where is my target, and what did the scan find" surface.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_free_icons::icons::bs_icons::*;
|
||||
use dioxus_free_icons::Icon;
|
||||
|
||||
use crate::components::page_header::PageHeader;
|
||||
use crate::components::toast::{ToastType, Toasts};
|
||||
use crate::infrastructure::onboarding::{
|
||||
delete_target, fetch_applicable_scans, fetch_targets, trigger_target_scan,
|
||||
};
|
||||
|
||||
/// Prettify a snake_case target-type value into a human label.
|
||||
fn pretty_type(v: &str) -> String {
|
||||
match v {
|
||||
"web_app" => "Web Application".into(),
|
||||
"backend_service" => "Backend / API".into(),
|
||||
"desktop_app" => "Desktop App".into(),
|
||||
"android_app" => "Android App".into(),
|
||||
"ios_app" => "iOS App".into(),
|
||||
"firmware_bare_metal" => "Firmware — bare metal".into(),
|
||||
"firmware_rtos" => "Firmware — RTOS".into(),
|
||||
"embedded_linux_yocto" => "Embedded Linux / Yocto".into(),
|
||||
"plc_sps" => "PLC / SPS".into(),
|
||||
other => other.replace('_', " "),
|
||||
}
|
||||
}
|
||||
|
||||
fn str_at<'a>(v: &'a serde_json::Value, key: &str) -> &'a str {
|
||||
v.get(key).and_then(|x| x.as_str()).unwrap_or("")
|
||||
}
|
||||
|
||||
fn target_id(t: &serde_json::Value) -> String {
|
||||
t.get("_id")
|
||||
.and_then(|o| o.get("$oid"))
|
||||
.and_then(|s| s.as_str())
|
||||
.unwrap_or_default()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// The applicable-scans matrix for one target, fetched on expand.
|
||||
#[component]
|
||||
fn TargetScans(id: String) -> Element {
|
||||
let scan_id = id.clone();
|
||||
let scans = use_resource(move || {
|
||||
let id = scan_id.clone();
|
||||
async move { fetch_applicable_scans(id).await.ok() }
|
||||
});
|
||||
|
||||
let snapshot = scans.read().clone();
|
||||
match &snapshot {
|
||||
Some(Some(resp)) => {
|
||||
let rows = resp.data.scans.clone();
|
||||
let pentest = resp.data.pentest_supported;
|
||||
rsx! {
|
||||
div { style: "margin-top: 8px;",
|
||||
if rows.is_empty() {
|
||||
div { style: "opacity: 0.6;", "No scans available (no code / URL / firmware artifact present)." }
|
||||
}
|
||||
for s in rows {
|
||||
{
|
||||
let name = str_at(&s, "scan").to_string();
|
||||
let rationale = str_at(&s, "rationale").to_string();
|
||||
let blocked = s.get("blocked_reason").and_then(|b| b.as_str()).map(String::from);
|
||||
let default_on = s.get("default_on").and_then(|b| b.as_bool()).unwrap_or(false);
|
||||
let badge = if blocked.is_some() {
|
||||
"badge badge-info"
|
||||
} else if default_on {
|
||||
"badge badge-success"
|
||||
} else {
|
||||
"badge"
|
||||
};
|
||||
rsx! {
|
||||
div { style: "display: flex; gap: 8px; align-items: center; padding: 4px 0;",
|
||||
span { class: "{badge}", "{name}" }
|
||||
span { style: "opacity: 0.8; font-size: 0.9em;", "{rationale}" }
|
||||
if let Some(b) = blocked {
|
||||
span { style: "opacity: 0.6; font-style: italic; font-size: 0.9em;", "— {b}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if pentest {
|
||||
div { style: "margin-top: 6px; opacity: 0.75; font-size: 0.85em;",
|
||||
"Active pentest is supported for this target type."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(None) => rsx! { div { style: "opacity: 0.6;", "Failed to load applicable scans." } },
|
||||
None => rsx! { div { style: "opacity: 0.6;", "Loading scans..." } },
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn TargetsPage() -> Element {
|
||||
let mut toasts = use_context::<Toasts>();
|
||||
let mut scanning_ids = use_signal(Vec::<String>::new);
|
||||
let mut expanded_ids = use_signal(Vec::<String>::new);
|
||||
let mut confirm_delete = use_signal(|| Option::<(String, String)>::None);
|
||||
|
||||
let mut targets = use_resource(move || async move { fetch_targets().await.ok() });
|
||||
|
||||
rsx! {
|
||||
PageHeader {
|
||||
title: "Targets",
|
||||
description: "Onboarded targets and what their scans found. Add new targets from Onboard.",
|
||||
}
|
||||
|
||||
div { style: "margin-bottom: 16px; display: flex; gap: 8px;",
|
||||
Link { to: crate::app::Route::OnboardingPage {}, class: "btn btn-primary",
|
||||
"+ Onboard a target"
|
||||
}
|
||||
button {
|
||||
class: "btn btn-secondary",
|
||||
onclick: move |_| targets.restart(),
|
||||
"Refresh"
|
||||
}
|
||||
}
|
||||
|
||||
// ── Delete confirmation ──
|
||||
if let Some((del_id, del_name)) = confirm_delete() {
|
||||
div { class: "modal-overlay",
|
||||
div { class: "modal-dialog",
|
||||
h3 { "Delete Target" }
|
||||
p { "Delete " strong { "{del_name}" } "?" }
|
||||
p { class: "modal-warning",
|
||||
"This permanently removes the target and its findings, SBOM entries, scan runs, and CVE alerts."
|
||||
}
|
||||
div { class: "modal-actions",
|
||||
button {
|
||||
class: "btn btn-secondary",
|
||||
onclick: move |_| confirm_delete.set(None),
|
||||
"Cancel"
|
||||
}
|
||||
button {
|
||||
class: "btn btn-danger",
|
||||
onclick: move |_| {
|
||||
let id = del_id.clone();
|
||||
let name = del_name.clone();
|
||||
confirm_delete.set(None);
|
||||
spawn(async move {
|
||||
match delete_target(id).await {
|
||||
Ok(_) => {
|
||||
toasts.push(ToastType::Success, format!("{name} deleted"));
|
||||
targets.restart();
|
||||
}
|
||||
Err(e) => toasts.push(ToastType::Error, e.to_string()),
|
||||
}
|
||||
});
|
||||
},
|
||||
"Delete"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let targets_snapshot = targets.read().clone();
|
||||
match &targets_snapshot {
|
||||
Some(Some(resp)) => {
|
||||
let rows = resp.data.clone();
|
||||
if rows.is_empty() {
|
||||
rsx! {
|
||||
div { class: "card", style: "padding: 24px; text-align: center;",
|
||||
p { style: "opacity: 0.7;", "No targets yet." }
|
||||
Link { to: crate::app::Route::OnboardingPage {}, class: "btn btn-primary",
|
||||
"Onboard your first target"
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rsx! {
|
||||
div { class: "card",
|
||||
div { class: "table-wrapper",
|
||||
table {
|
||||
thead {
|
||||
tr {
|
||||
th { "Name" }
|
||||
th { "Type" }
|
||||
th { "Detected" }
|
||||
th { "Artifacts" }
|
||||
th { "Findings" }
|
||||
th { "Actions" }
|
||||
}
|
||||
}
|
||||
tbody {
|
||||
for t in rows {
|
||||
{
|
||||
let id = target_id(&t);
|
||||
let name = str_at(&t, "name").to_string();
|
||||
let ttype = pretty_type(str_at(&t, "target_type"));
|
||||
let suggested = t
|
||||
.get("classification")
|
||||
.and_then(|c| c.get("suggested"))
|
||||
.and_then(|s| s.as_str())
|
||||
.map(pretty_type);
|
||||
let artifacts = t
|
||||
.get("artifacts")
|
||||
.and_then(|a| a.as_array())
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
let findings = t
|
||||
.get("findings_count")
|
||||
.and_then(|n| n.as_u64())
|
||||
.unwrap_or(0);
|
||||
let facts = t
|
||||
.get("classification")
|
||||
.and_then(|c| c.get("facts"))
|
||||
.and_then(|f| f.as_array())
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
let is_scanning = scanning_ids().contains(&id);
|
||||
let is_expanded = expanded_ids().contains(&id);
|
||||
let id_scan = id.clone();
|
||||
let id_exp = id.clone();
|
||||
let id_del = id.clone();
|
||||
let name_del = name.clone();
|
||||
let artifacts_detail = artifacts.clone();
|
||||
rsx! {
|
||||
tr {
|
||||
td { strong { "{name}" } }
|
||||
td { "{ttype}" }
|
||||
td {
|
||||
if let Some(sug) = suggested.clone() {
|
||||
span { class: "badge badge-success", "{sug}" }
|
||||
} else {
|
||||
span { style: "opacity: 0.5;", "—" }
|
||||
}
|
||||
}
|
||||
td { "{artifacts.len()}" }
|
||||
td { "{findings}" }
|
||||
td { style: "display: flex; gap: 4px;",
|
||||
button {
|
||||
class: "btn btn-ghost",
|
||||
title: "Details",
|
||||
onclick: move |_| {
|
||||
let mut ids = expanded_ids();
|
||||
if ids.contains(&id_exp) {
|
||||
ids.retain(|i| i != &id_exp);
|
||||
} else {
|
||||
ids.push(id_exp.clone());
|
||||
}
|
||||
expanded_ids.set(ids);
|
||||
},
|
||||
Icon { icon: BsInfoCircle, width: 16, height: 16 }
|
||||
}
|
||||
button {
|
||||
class: if is_scanning { "btn btn-ghost btn-scanning" } else { "btn btn-ghost" },
|
||||
title: "Run scan",
|
||||
disabled: is_scanning,
|
||||
onclick: move |_| {
|
||||
let id = id_scan.clone();
|
||||
let mut ids = scanning_ids();
|
||||
ids.push(id.clone());
|
||||
scanning_ids.set(ids);
|
||||
spawn(async move {
|
||||
match trigger_target_scan(id.clone()).await {
|
||||
Ok(_) => toasts.push(ToastType::Success, "Scan triggered — findings appear as it runs. Use Refresh."),
|
||||
Err(e) => toasts.push(ToastType::Error, e.to_string()),
|
||||
}
|
||||
let mut ids = scanning_ids();
|
||||
ids.retain(|i| i != &id);
|
||||
scanning_ids.set(ids);
|
||||
});
|
||||
},
|
||||
if is_scanning {
|
||||
span { class: "spinner" }
|
||||
} else {
|
||||
Icon { icon: BsPlayCircle, width: 16, height: 16 }
|
||||
}
|
||||
}
|
||||
button {
|
||||
class: "btn btn-ghost btn-ghost-danger",
|
||||
title: "Delete target",
|
||||
onclick: move |_| {
|
||||
confirm_delete.set(Some((id_del.clone(), name_del.clone())));
|
||||
},
|
||||
Icon { icon: BsTrash, width: 16, height: 16 }
|
||||
}
|
||||
}
|
||||
}
|
||||
if is_expanded {
|
||||
tr {
|
||||
td { colspan: "6",
|
||||
div { style: "padding: 12px 8px;",
|
||||
h4 { style: "margin: 0 0 6px;", "Artifacts" }
|
||||
if artifacts_detail.is_empty() {
|
||||
div { style: "opacity: 0.6;", "No artifacts." }
|
||||
}
|
||||
for a in artifacts_detail {
|
||||
div { style: "font-size: 0.9em; padding: 2px 0;",
|
||||
span { style: "opacity: 0.7;", "{str_at(&a, \"kind\")}: " }
|
||||
span { style: "font-family: monospace;", "{str_at(&a, \"source_ref\")}" }
|
||||
}
|
||||
}
|
||||
if !facts.is_empty() {
|
||||
h4 { style: "margin: 12px 0 6px;", "Detected facts" }
|
||||
for f in facts {
|
||||
div { style: "font-size: 0.9em; padding: 2px 0;",
|
||||
span { style: "font-family: monospace;", "{str_at(&f, \"key\")}={str_at(&f, \"value\")}" }
|
||||
span { style: "opacity: 0.5;", " ({str_at(&f, \"source\")})" }
|
||||
}
|
||||
}
|
||||
}
|
||||
h4 { style: "margin: 12px 0 6px;", "Applicable scans" }
|
||||
TargetScans { id: id.clone() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(None) => rsx! {
|
||||
div { class: "card", p { "Failed to load targets." } }
|
||||
},
|
||||
None => rsx! {
|
||||
div { class: "loading", "Loading targets..." }
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user