feat(dashboard): a page per target, and a targets list that leads to it (#408)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Agent (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Dashboard (push) Successful in 4m7s

This commit was merged in pull request #408.
This commit is contained in:
sharang committed 2026-09-26 08:46:23 +00:00
1 parent 6ab3390db3
commit d1a4147488
8 files changed
+1171 -613

No files matched your search

+293
View File
@@ -4575,3 +4575,296 @@ tbody tr:last-child td {
justify-self: start;
}
}
/* ── Targets list ── */
.page-actions {
display: flex;
gap: 8px;
margin-bottom: 16px;
}
.targets-empty {
display: grid;
gap: 12px;
justify-items: center;
padding: 28px;
text-align: center;
color: var(--text-secondary);
}
.targets-empty-actions {
display: flex;
gap: 8px;
flex-wrap: wrap;
justify-content: center;
}
.targets-empty-hint {
font-size: 12px;
color: var(--text-tertiary);
max-width: 60ch;
}
.targets-row {
cursor: pointer;
}
.targets-row:hover td {
background: var(--bg-card-hover);
}
.targets-name {
display: block;
color: var(--text-primary);
font-weight: 600;
text-decoration: none;
}
.targets-name:hover {
color: var(--accent);
}
.targets-type,
.targets-ago {
display: block;
font-size: 12px;
color: var(--text-tertiary);
}
.targets-scan .badge {
margin-bottom: 2px;
}
.targets-cra {
min-width: 220px;
}
.targets-table .num {
text-align: right;
font-variant-numeric: tabular-nums;
}
.targets-actions {
text-align: right;
white-space: nowrap;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
/* ── Target page ── */
.target-missing {
padding: 20px;
}
.target-head {
display: flex;
flex-wrap: wrap;
gap: 16px;
align-items: flex-start;
justify-content: space-between;
margin-bottom: 20px;
}
.target-head-text {
display: grid;
gap: 6px;
min-width: 0;
}
.target-head h2 {
font-size: 22px;
font-weight: 600;
letter-spacing: -0.02em;
}
.target-head-meta {
display: flex;
flex-wrap: wrap;
gap: 4px 14px;
font-size: 12.5px;
color: var(--text-tertiary);
}
.target-head-artifact code {
font-family: var(--font-mono);
font-size: 12px;
color: var(--text-secondary);
overflow-wrap: anywhere;
}
.target-head-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.target-head-actions .btn {
display: inline-flex;
align-items: center;
gap: 6px;
}
.target-summary {
display: grid;
grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
gap: 20px;
margin-bottom: 20px;
}
.target-card-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.target-card-head h3 {
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 600;
}
.target-card-link {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 12.5px;
font-weight: 500;
color: var(--accent);
text-decoration: none;
}
.target-count {
font-family: var(--font-mono);
font-size: 12px;
font-weight: 500;
color: var(--text-secondary);
background: var(--bg-elevated);
border-radius: 99px;
padding: 1px 8px;
}
.target-figures {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
}
.target-figure {
display: block;
font-size: 26px;
font-weight: 600;
letter-spacing: -0.02em;
font-variant-numeric: tabular-nums;
}
.target-figure-label {
font-size: 12px;
color: var(--text-tertiary);
}
.target-open,
.target-manual {
margin-bottom: 20px;
}
.target-findings {
list-style: none;
}
.target-findings li {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
gap: 12px;
align-items: center;
padding: 10px 0;
border-top: 1px solid var(--border);
}
.target-finding-title {
color: var(--text-primary);
font-weight: 500;
text-decoration: none;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.target-finding-title:hover {
color: var(--accent);
}
.target-finding-place {
font-family: var(--font-mono);
font-size: 11.5px;
color: var(--text-tertiary);
}
.target-columns {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 20px;
margin-bottom: 20px;
align-items: start;
}
.target-subhead {
margin: 16px 0 6px;
font-family: var(--font-mono);
font-size: 11px;
font-weight: 500;
letter-spacing: 0.06em;
text-transform: uppercase;
color: var(--text-tertiary);
}
.target-facts {
list-style: none;
display: grid;
gap: 2px;
font-size: 12px;
color: var(--text-tertiary);
}
.target-facts code {
font-family: var(--font-mono);
color: var(--text-secondary);
}
.target-muted {
font-size: 12.5px;
color: var(--text-tertiary);
}
@media (max-width: 1000px) {
.target-summary,
.target-columns {
grid-template-columns: 1fr;
}
}
@media (max-width: 640px) {
.target-findings li {
grid-template-columns: auto minmax(0, 1fr);
}
.target-finding-place {
grid-column: 2;
}
}
/* The overview's list cards pad their own rows. */
.card.ov-cra,
.card.ov-next {
padding: 0;
}
+2
View File
@@ -12,6 +12,8 @@ pub enum Route {
OverviewPage {},
#[route("/targets")]
TargetsPage {},
#[route("/targets/:id")]
TargetPage { id: String },
#[route("/targets/:id/compliance")]
CompliancePage { id: String },
#[route("/onboard")]
@@ -7,7 +7,7 @@ use dioxus::prelude::*;
use crate::i18n::texts::{coverage, findings};
use crate::i18n::{use_lang, Lang};
use crate::infrastructure::platform::{is_feature_disabled_skip, stage_tone};
use crate::infrastructure::platform::{is_feature_disabled_skip, stage_tone, use_source_only};
/// One row of the agent's applicable-scans list, read from its JSON.
struct ScanLine {
@@ -45,8 +45,15 @@ impl ScanLine {
.unwrap_or_else(|| self.raw_name.clone())
}
fn switched_off(&self) -> bool {
/// Off in this deployment: reported as a disabled feature, or a scan of
/// a running device where only source code is examined.
fn switched_off(&self, source_only: bool) -> bool {
is_feature_disabled_skip(self.status.as_deref(), self.blocked.as_deref())
|| (source_only
&& matches!(
self.scan_type,
Some(ScanType::Dast | ScanType::IcsProbe | ScanType::Pentest)
))
}
}
@@ -55,9 +62,11 @@ impl ScanLine {
#[component]
pub fn ScanCoverage(scans: Vec<serde_json::Value>) -> Element {
let lang = use_lang()();
let source_only = use_source_only();
let lines: Vec<ScanLine> = scans.iter().map(ScanLine::parse).collect();
let (off, shown): (Vec<&ScanLine>, Vec<&ScanLine>) =
lines.iter().partition(|line| line.switched_off());
let (off, shown): (Vec<&ScanLine>, Vec<&ScanLine>) = lines
.iter()
.partition(|line| line.switched_off(source_only));
let off_labels = off
.iter()
.map(|line| line.label(lang))
+64 -14
View File
@@ -473,10 +473,6 @@ pub mod targets {
de: "+ Prüfobjekt anlegen",
en: "+ Add a target",
};
pub const REFRESH: Text = Text {
de: "Aktualisieren",
en: "Refresh",
};
pub const COL_NAME: Text = Text {
de: "Name",
en: "Name",
@@ -485,10 +481,6 @@ pub mod targets {
de: "Typ",
en: "Type",
};
pub const COL_DETECTED: Text = Text {
de: "Erkannt",
en: "Detected",
};
pub const COL_LAST_SCAN: Text = Text {
de: "Letzte Prüfung",
en: "Last scan",
@@ -505,10 +497,6 @@ pub mod targets {
de: "Befunde dieses Prüfobjekts anzeigen",
en: "Show this target's findings",
};
pub const DETAILS: Text = Text {
de: "Details",
en: "Details",
};
pub const EDIT: Text = Text {
de: "Bearbeiten",
en: "Edit target",
@@ -522,8 +510,8 @@ pub mod targets {
en: "Delete",
};
pub const SCAN_STARTED: Text = Text {
de: "Prüfung gestartet. Den Fortschritt sehen Sie in den Details.",
en: "Scan started. Follow its progress in the details.",
de: "Prüfung gestartet. Den Fortschritt sehen Sie unter Prüfläufe.",
en: "Scan started. Follow its progress under Scan runs.",
};
pub const ARTIFACTS: Text = Text {
de: "Artefakte",
@@ -651,6 +639,68 @@ pub mod targets {
en: "ZIP with the OSCAL assessment (CRA Annex I), SBOM (CycloneDX, SPDX), \
findings (JSON, CSV), CVE alerts and a manifest with SHA-256 checksums.",
};
pub const BACK: Text = Text {
de: "Prüfobjekte",
en: "Targets",
};
pub const NOT_FOUND: Text = Text {
de: "Dieses Prüfobjekt gibt es nicht (mehr).",
en: "This target does not exist (any more).",
};
pub const CRA_TITLE: Text = Text {
de: "CRA-Stand",
en: "CRA status",
};
pub const CRA_DETAILS: Text = Text {
de: "Stand je Anforderung",
en: "Status by requirement",
};
pub const SBOM_TITLE: Text = Text {
de: "Stückliste",
en: "SBOM",
};
pub const COMPONENTS: Text = Text {
de: "Komponenten",
en: "components",
};
pub const KNOWN_VULNS: Text = Text {
de: "bekannte Schwachstellen (CVE)",
en: "known vulnerabilities (CVE)",
};
pub const OPEN_FINDINGS: Text = Text {
de: "Offene Befunde",
en: "Open findings",
};
pub const NO_OPEN_FINDINGS: Text = Text {
de: "Keine offenen Befunde.",
en: "No open findings.",
};
pub const ALL_FINDINGS: Text = Text {
de: "Alle Befunde dieses Prüfobjekts",
en: "All findings of this target",
};
pub const SCAN_RUNS: Text = Text {
de: "Prüfläufe",
en: "Scan runs",
};
pub const SCOPE: Text = Text {
de: "Prüfumfang",
en: "What is checked",
};
pub const MANUAL_ADD: Text = Text {
de: "Befund erfassen",
en: "Add a finding",
};
pub const MANUAL_CLOSE: Text = Text {
de: "Formular schließen",
en: "Close the form",
};
pub const MANUAL_HINT: Text = Text {
de: "Ergebnisse aus Penetrationstests oder DAST-Läufen, von Hand erfasst oder als \
SARIF bzw. ZAP-JSON importiert. Sie erscheinen neben den übrigen Befunden.",
en: "Results of penetration tests or DAST runs, entered by hand or imported as \
SARIF or ZAP JSON. They appear next to the other findings.",
};
}
/// Target types and artifact kinds, keyed by their API value.
@@ -456,6 +456,17 @@ pub async fn enable_target_scans(
super::agent_client::json_or_error(resp).await
}
/// One target (`GET /api/v1/targets/{id}`), credentials redacted.
#[server]
pub async fn fetch_target(id: String) -> Result<TargetResponse, ServerFnError> {
let resp = super::agent_client::agent_get(&format!("/api/v1/targets/{id}"))
.await?
.send()
.await
.map_err(|e| ServerFnError::new(e.to_string()))?;
super::agent_client::json_or_error(resp).await
}
/// Run kind-based classification on a target.
#[server]
pub async fn detect_target(id: String) -> Result<TargetResponse, ServerFnError> {
+2
View File
@@ -18,6 +18,7 @@ pub mod overview;
pub mod pentest_dashboard;
pub mod pentest_session;
pub mod sbom;
pub mod target;
pub mod targets;
pub use chat::ChatPage;
@@ -40,4 +41,5 @@ pub use overview::OverviewPage;
pub use pentest_dashboard::PentestDashboardPage;
pub use pentest_session::PentestSessionPage;
pub use sbom::SbomPage;
pub use target::TargetPage;
pub use targets::TargetsPage;
+655
View File
@@ -0,0 +1,655 @@
//! One target: where it stands on the CRA, what is open, what its scans
//! check and have done, and its settings. Opened from the targets list and
//! the overview.
use dioxus::prelude::*;
use dioxus_free_icons::icons::bs_icons::*;
use dioxus_free_icons::Icon;
use crate::app::Route;
use crate::components::cra_bar::CraBar;
use crate::components::manual_findings::ManualFindingsPanel;
use crate::components::scan_coverage::ScanCoverage;
use crate::components::scan_runs::ScanRunList;
use crate::components::severity_badge::SeverityBadge;
use crate::components::toast::{ToastType, Toasts};
use crate::i18n::texts::{common, kinds, targets as tx};
use crate::i18n::use_lang;
use crate::infrastructure::evidence::{evidence_pack_url, fetch_compliance, CraCounts};
use crate::infrastructure::findings::{fetch_findings, location, FindingsQuery};
use crate::infrastructure::onboarding::{
delete_target, fetch_applicable_scans, fetch_target, set_archive_password, trigger_target_scan,
update_target, validate_artifact_ref, validate_target_name, ArchivePassword, ArtifactInputDto,
PasswordOutcome,
};
use crate::infrastructure::platform::{use_source_only, SourceOnlyNote};
/// Open findings listed on the page; the rest are one click away.
const OPEN_SHOWN: usize = 5;
fn str_at<'a>(v: &'a serde_json::Value, key: &str) -> &'a str {
v.get(key).and_then(|x| x.as_str()).unwrap_or("")
}
/// The target's artifacts as the editor edits them. Credentials never come
/// back from the agent; only whether one is set.
fn editable_artifacts(target: &serde_json::Value) -> Vec<ArtifactInputDto> {
target
.get("artifacts")
.and_then(|a| a.as_array())
.map(|arts| {
arts.iter()
.map(|a| ArtifactInputDto {
kind: str_at(a, "kind").to_string(),
source_ref: str_at(a, "source_ref").to_string(),
branch: a
.get("git")
.and_then(|g| g.get("default_branch"))
.and_then(|b| b.as_str())
.map(String::from),
// Kept, or an edit would reset a project archive to PLCopen XML.
plc_format: a
.get("plc")
.and_then(|p| p.get("format"))
.and_then(|f| f.as_str())
.map(String::from),
has_token: a
.get("auth")
.and_then(|x| x.get("method"))
.and_then(|m| m.as_str())
== Some("token"),
artifact_id: str_at(a, "id").to_string(),
archive_password: ArchivePassword::of(a),
..Default::default()
})
.collect()
})
.unwrap_or_default()
}
#[component]
pub fn TargetPage(id: String) -> Element {
let lang = use_lang()();
let mut toasts = use_context::<Toasts>();
let navigator = use_navigator();
let target_id = use_signal(|| id.clone());
let mut target = use_resource(move || async move { fetch_target(target_id()).await.ok() });
let mut status = use_resource(move || async move { fetch_compliance(target_id()).await.ok() });
let mut open_findings = use_resource(move || async move {
fetch_findings(FindingsQuery {
page: 1,
repo_id: target_id(),
status: "open".to_string(),
sort_by: "severity".to_string(),
sort_order: "desc".to_string(),
..Default::default()
})
.await
.ok()
});
let mut editing = use_signal(|| false);
let mut confirm_delete = use_signal(|| false);
let mut adding_manual = use_signal(|| false);
let mut starting = use_signal(|| false);
let snapshot = target.read().clone();
let Some(Some(resp)) = snapshot else {
return rsx! {
BackLink {}
match snapshot {
Some(None) => rsx! { div { class: "card target-missing", p { {tx::NOT_FOUND.get(lang)} } } },
_ => rsx! { div { class: "loading", {common::LOADING.get(lang)} } },
}
};
};
let t = resp.data.clone();
let name = str_at(&t, "name").to_string();
let type_label = kinds::target_type(str_at(&t, "target_type"), lang);
let artifacts = t
.get("artifacts")
.and_then(|a| a.as_array())
.cloned()
.unwrap_or_default();
let facts = t
.get("classification")
.and_then(|c| c.get("facts"))
.and_then(|f| f.as_array())
.cloned()
.unwrap_or_default();
let status_data = status.read().clone().flatten();
let counts: Option<CraCounts> = status_data
.as_ref()
.and_then(|d| serde_json::from_value(d["counts"].clone()).ok());
let components = status_data
.as_ref()
.and_then(|d| d["sbom_components"].as_u64());
let cves = status_data.as_ref().and_then(|d| d["cve_alerts"].as_u64());
rsx! {
BackLink {}
header { class: "target-head",
div { class: "target-head-text",
h2 { "{name}" }
p { class: "target-head-meta",
span { "{type_label}" }
for a in artifacts.iter() {
span { class: "target-head-artifact",
"{kinds::artifact_kind(str_at(a, \"kind\"), lang)}: "
code { "{str_at(a, \"source_ref\")}" }
}
}
}
}
div { class: "target-head-actions",
button {
class: "btn btn-primary",
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)),
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)}
}
a {
class: "btn btn-secondary",
href: evidence_pack_url(&id),
download: "",
title: tx::EVIDENCE_HINT.get(lang),
Icon { icon: BsDownload, width: 14, height: 14 }
{tx::EVIDENCE_PACK.get(lang)}
}
button {
class: "btn btn-ghost",
onclick: move |_| editing.set(true),
Icon { icon: BsPencil, width: 14, height: 14 }
{tx::EDIT.get(lang)}
}
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)}
}
}
}
div { class: "target-summary",
section { class: "card target-cra",
div { class: "target-card-head",
h3 { {tx::CRA_TITLE.get(lang)} }
Link { to: Route::CompliancePage { id: id.clone() }, class: "target-card-link",
{tx::CRA_DETAILS.get(lang)}
Icon { icon: BsArrowRight, width: 14, height: 14 }
}
}
match counts {
Some(counts) => rsx! { CraBar { counts } },
None => rsx! { div { class: "loading", {common::LOADING.get(lang)} } },
}
}
section { class: "card target-sbom",
div { class: "target-card-head",
h3 { {tx::SBOM_TITLE.get(lang)} }
Link { to: Route::SbomPage {}, class: "target-card-link",
Icon { icon: BsArrowRight, width: 14, height: 14 }
}
}
div { class: "target-figures",
div {
span { class: "target-figure", "{components.map(|n| n.to_string()).unwrap_or_else(|| \"–\".into())}" }
span { class: "target-figure-label", {tx::COMPONENTS.get(lang)} }
}
div {
span { class: "target-figure", "{cves.map(|n| n.to_string()).unwrap_or_else(|| \"–\".into())}" }
span { class: "target-figure-label", {tx::KNOWN_VULNS.get(lang)} }
}
}
}
}
section { class: "card target-open",
div { class: "target-card-head",
h3 {
{tx::OPEN_FINDINGS.get(lang)}
if let Some(Some(r)) = &*open_findings.read() {
span { class: "target-count", "{r.total.unwrap_or(0)}" }
}
}
Link { to: Route::FindingsPage { target: id.clone() }, class: "target-card-link",
{tx::ALL_FINDINGS.get(lang)}
Icon { icon: BsArrowRight, width: 14, height: 14 }
}
}
match &*open_findings.read() {
Some(Some(r)) if r.data.is_empty() => rsx! { p { class: "target-muted", {tx::NO_OPEN_FINDINGS.get(lang)} } },
Some(Some(r)) => rsx! {
ul { class: "target-findings",
for f in r.data.iter().take(OPEN_SHOWN) {
{
let fid = f.id.as_ref().map(|i| i.to_hex()).unwrap_or_default();
let place = location(f.file_path.as_deref(), f.line_number);
rsx! {
li {
SeverityBadge { severity: f.severity.to_string() }
Link { to: Route::FindingDetailPage { id: fid }, class: "target-finding-title", "{f.title}" }
if let Some(place) = place {
code { class: "target-finding-place", "{place}" }
}
}
}
}
}
}
},
Some(None) => rsx! { p { class: "target-muted", {tx::LOAD_FAILED.get(lang)} } },
None => rsx! { div { class: "loading", {common::LOADING.get(lang)} } },
}
}
div { class: "target-columns",
section { class: "card",
div { class: "target-card-head", h3 { {tx::SCAN_RUNS.get(lang)} } }
div { class: "target-card-body", ScanRunList { target_id: id.clone() } }
}
section { class: "card",
div { class: "target-card-head", h3 { {tx::SCOPE.get(lang)} } }
div { class: "target-card-body",
TargetScans { id: id.clone() }
if !facts.is_empty() {
h4 { class: "target-subhead", {tx::DETECTED_FACTS.get(lang)} }
ul { class: "target-facts",
for f in facts {
li {
code { "{str_at(&f, \"key\")}={str_at(&f, \"value\")}" }
span { " ({str_at(&f, \"source\")})" }
}
}
}
}
}
}
}
section { class: "card target-manual",
div { class: "target-card-head",
h3 { {crate::i18n::texts::manual::TITLE.get(lang)} }
button {
class: "btn btn-secondary btn-sm",
onclick: move |_| adding_manual.set(!adding_manual()),
if adding_manual() { {tx::MANUAL_CLOSE.get(lang)} } else { {tx::MANUAL_ADD.get(lang)} }
}
}
div { class: "target-card-body",
p { class: "target-muted", {tx::MANUAL_HINT.get(lang)} }
if adding_manual() {
ManualFindingsPanel {
target_id: id.clone(),
on_change: move |_| open_findings.restart(),
}
}
}
}
if editing() {
TargetEditor {
target: t.clone(),
on_close: move |_| editing.set(false),
on_saved: move |_| {
editing.set(false);
target.restart();
},
}
}
if confirm_delete() {
div { class: "modal-overlay",
div { class: "modal-dialog",
h3 { {tx::DELETE_TITLE.get(lang)} }
p { strong { "{name}" } }
p { class: "modal-warning", {tx::DELETE_WARNING.get(lang)} }
div { class: "modal-actions",
button {
class: "btn btn-secondary",
onclick: move |_| confirm_delete.set(false),
{tx::CANCEL.get(lang)}
}
button {
class: "btn btn-danger",
onclick: move |_| {
confirm_delete.set(false);
let deleted = name.clone();
spawn(async move {
match delete_target(target_id()).await {
Ok(_) => {
toasts.push(ToastType::Success, format!("{deleted} {}", tx::DELETED.get(lang)));
navigator.push(Route::TargetsPage {});
}
Err(e) => toasts.push(ToastType::Error, e.to_string()),
}
});
},
{tx::DELETE.get(lang)}
}
}
}
}
}
}
}
/// Back to the targets list.
#[component]
fn BackLink() -> Element {
let lang = use_lang()();
rsx! {
div { class: "back-nav",
Link { to: Route::TargetsPage {}, class: "btn btn-ghost btn-back",
Icon { icon: BsArrowLeft, width: 16, height: 16 }
{tx::BACK.get(lang)}
}
}
}
}
/// What the target's scans check, and why one cannot run.
#[component]
fn TargetScans(id: String) -> Element {
let scan_id = use_signal(|| id.clone());
let scans = use_resource(move || async move { fetch_applicable_scans(scan_id()).await.ok() });
let source_only = use_source_only();
let lang = use_lang()();
let snapshot = scans.read().clone();
match &snapshot {
Some(Some(resp)) => {
let rows = resp.data.scans.clone();
let pentest = resp.data.pentest_supported;
rsx! {
if rows.is_empty() {
p { class: "target-muted", {tx::NO_SCANS.get(lang)} }
}
ScanCoverage { scans: rows }
if pentest {
p { class: "target-muted",
{tx::PENTEST_SUPPORTED.get(lang)}
if source_only {
SourceOnlyNote { inline: true }
}
}
}
}
}
Some(None) => rsx! { p { class: "target-muted", {tx::LOAD_FAILED.get(lang)} } },
None => rsx! { div { class: "loading", {common::LOADING.get(lang)} } },
}
}
/// The target's name, type and artifacts, edited in a dialog.
#[component]
fn TargetEditor(
target: serde_json::Value,
on_close: EventHandler<()>,
on_saved: EventHandler<()>,
) -> Element {
let lang = use_lang()();
let mut toasts = use_context::<Toasts>();
let eid = target
.get("_id")
.and_then(|o| o.get("$oid"))
.and_then(|s| s.as_str())
.unwrap_or_default()
.to_string();
let eid_password = eid.clone();
let mut edit_name = use_signal(|| str_at(&target, "name").to_string());
let mut edit_type = use_signal(|| str_at(&target, "target_type").to_string());
let mut edit_arts = use_signal(|| editable_artifacts(&target));
let mut edit_saving = use_signal(|| false);
// The dialog's "add artifact" row.
let mut e_kind = use_signal(|| "git_repo".to_string());
let mut e_source = use_signal(String::new);
let mut e_branch = use_signal(|| "main".to_string());
let mut e_token = use_signal(String::new);
{
let name_err = validate_target_name(&edit_name());
let e_source_err = if e_source().is_empty() {
None
} else {
validate_artifact_ref(&e_kind(), &e_source())
};
rsx! {
div { class: "modal-overlay",
div { class: "modal-dialog",
h3 { {tx::EDIT_TITLE.get(lang)} }
div { class: "form-group",
label { {tx::COL_NAME.get(lang)} }
input {
r#type: "text",
value: "{edit_name}",
oninput: move |e| edit_name.set(e.value()),
}
if !edit_name().is_empty() {
if let Some(err) = name_err.clone() {
div { style: "color: var(--danger, #d33); font-size: 0.85em;", "{err}" }
}
}
}
div { class: "form-group",
label { {tx::COL_TYPE.get(lang)} }
select {
value: "{edit_type}",
oninput: move |e| edit_type.set(e.value()),
for (v, l) in kinds::TARGET_TYPES {
option { value: "{v}", selected: edit_type() == v, {l.get(lang)} }
}
}
}
label { style: "font-weight: 600;", {tx::ARTIFACTS.get(lang)} }
for (i, a) in edit_arts().iter().enumerate() {
div { style: "display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; flex-wrap: wrap;",
span { style: "font-size: 0.9em;",
span { style: "opacity: 0.7;", "{kinds::artifact_kind(&a.kind, lang)}: " }
span { style: "font-family: monospace;", "{a.source_ref}" }
if a.token.as_deref() == Some("") {
span { class: "badge badge-medium", style: "margin-left: 6px;", {tx::TOKEN_REMOVED.get(lang)} }
} else if a.has_token {
span { class: "badge badge-neutral", style: "margin-left: 6px;", {tx::TOKEN_SET.get(lang)} }
}
}
if a.kind == "git_repo" {
input {
r#type: "password",
autocomplete: "off",
placeholder: tx::NEW_TOKEN.get(lang),
style: "flex: 1; min-width: 180px;",
oninput: move |e| {
let v = e.value();
edit_arts.write()[i].token = (!v.is_empty()).then_some(v);
},
}
if a.has_token {
button {
class: "btn btn-ghost btn-sm",
onclick: move |_| { edit_arts.write()[i].token = Some(String::new()); },
{tx::REMOVE_TOKEN.get(lang)}
}
}
}
if a.archive_password != ArchivePassword::NotNeeded {
ArchivePasswordField {
target_id: eid_password.clone(),
artifact_id: a.artifact_id.clone(),
state: a.archive_password,
on_saved: move |_| edit_arts.write()[i].archive_password = ArchivePassword::Set,
}
}
button {
class: "btn btn-ghost btn-ghost-danger btn-sm",
onclick: move |_| { edit_arts.write().remove(i); },
{tx::REMOVE.get(lang)}
}
}
}
div { style: "display: flex; gap: 8px; align-items: flex-end; margin-top: 8px;",
div { class: "form-group", style: "margin: 0;",
label { {tx::KIND.get(lang)} }
select {
value: "{e_kind}",
oninput: move |e| e_kind.set(e.value()),
for (v, l) in kinds::ARTIFACT_KINDS {
option { value: "{v}", selected: e_kind() == v, {l.get(lang)} }
}
}
}
div { class: "form-group", style: "margin: 0; flex: 1;",
label { {tx::REFERENCE.get(lang)} }
input {
r#type: "text",
value: "{e_source}",
oninput: move |e| e_source.set(e.value()),
}
}
if e_kind() == "git_repo" {
div { class: "form-group", style: "margin: 0;",
label { {tx::BRANCH.get(lang)} }
input {
r#type: "text",
value: "{e_branch}",
oninput: move |e| e_branch.set(e.value()),
}
}
div { class: "form-group", style: "margin: 0;",
label { {tx::TOKEN.get(lang)} }
input {
r#type: "password",
autocomplete: "off",
value: "{e_token}",
oninput: move |e| e_token.set(e.value()),
}
}
}
button {
class: "btn btn-secondary",
disabled: e_source().trim().is_empty() || e_source_err.is_some(),
onclick: move |_| {
let kind = e_kind();
if !e_source().trim().is_empty()
&& validate_artifact_ref(&kind, &e_source()).is_none()
{
let git = kind == "git_repo";
let token = (git && !e_token().trim().is_empty()).then_some(e_token());
edit_arts.write().push(ArtifactInputDto {
branch: git.then_some(e_branch()),
has_token: token.is_some(),
token,
kind,
source_ref: e_source(),
..Default::default()
});
e_source.set(String::new());
e_token.set(String::new());
}
},
{tx::ADD_ARTIFACT.get(lang)}
}
}
if let Some(err) = e_source_err.clone() {
div { style: "color: var(--danger, #d33); font-size: 0.85em;", "{err}" }
}
div { class: "modal-actions",
button {
class: "btn btn-secondary",
onclick: move |_| on_close.call(()),
{tx::CANCEL.get(lang)}
}
button {
class: "btn btn-primary",
disabled: edit_saving() || name_err.is_some(),
onclick: move |_| {
let id = eid.clone();
let nm = edit_name();
let tt = edit_type();
let arts = edit_arts();
edit_saving.set(true);
spawn(async move {
match update_target(id, Some(nm), Some(tt), Some(arts)).await {
Ok(_) => {
toasts.push(ToastType::Success, tx::UPDATED.get(lang));
on_saved.call(());
}
Err(e) => toasts.push(ToastType::Error, e.to_string()),
}
edit_saving.set(false);
});
},
if edit_saving() { {tx::SAVING.get(lang)} } else { {tx::SAVE.get(lang)} }
}
}
}
}
}
}
}
/// The password of a stored, password-protected archive: its state, and a
/// field that checks and saves a new one at once (not with the editor's Save,
/// which never carries credentials).
#[component]
fn ArchivePasswordField(
target_id: String,
artifact_id: String,
state: ArchivePassword,
on_saved: EventHandler<()>,
) -> Element {
let lang = use_lang()();
let mut password = use_signal(String::new);
let mut note = use_signal(|| Option::<String>::None);
let (badge, label) = if state == ArchivePassword::Set {
("badge badge-neutral", common::PASSWORD_SET)
} else {
("badge badge-medium", common::PASSWORD_MISSING)
};
rsx! {
span { class: "{badge}", {label.get(lang)} }
input {
r#type: "password",
autocomplete: "off",
placeholder: common::ARCHIVE_PASSWORD.get(lang),
style: "flex: 1; min-width: 180px;",
value: "{password}",
oninput: move |e| password.set(e.value()),
}
button {
class: "btn btn-ghost btn-sm",
disabled: password().is_empty(),
onclick: move |_| {
let (target_id, artifact_id, pw) = (target_id.clone(), artifact_id.clone(), password());
spawn(async move {
let text = match set_archive_password(target_id, artifact_id, pw).await {
Ok(PasswordOutcome::Saved) => {
password.set(String::new());
on_saved.call(());
common::PASSWORD_SAVED.get(lang).to_string()
}
Ok(PasswordOutcome::Wrong) => common::PASSWORD_WRONG.get(lang).to_string(),
Ok(PasswordOutcome::NotEncrypted) => common::NOT_ENCRYPTED.get(lang).to_string(),
Err(e) => e.to_string(),
};
note.set(Some(text));
});
},
{common::SAVE_PASSWORD.get(lang)}
}
if let Some(text) = note() {
span { style: "font-size: 0.85em; opacity: 0.8;", "{text}" }
}
}
}
+131 -595
View File
@@ -1,40 +1,37 @@
//! 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.
//! Targets page: every onboarded target with where it stands on the CRA,
//! its last scan and its findings. A row opens the target's page; creation
//! lives in the onboarding wizard (`/onboard`).
use dioxus::prelude::*;
use dioxus_free_icons::icons::bs_icons::*;
use dioxus_free_icons::Icon;
use crate::app::Route;
use crate::components::cra_bar::CraBar;
use crate::components::demo_targets::DemoTargetsButton;
use crate::components::manual_findings::ManualFindingsPanel;
use crate::components::page_header::PageHeader;
use crate::components::scan_coverage::ScanCoverage;
use crate::components::scan_runs::{status_badge, ScanRunList};
use crate::components::scan_runs::status_badge;
use crate::components::toast::{ToastType, Toasts};
use crate::i18n::texts::{common, kinds, scans as scan_texts, targets as tx};
use crate::i18n::{use_lang, Lang};
use crate::infrastructure::onboarding::{
delete_target, fetch_applicable_scans, fetch_targets, set_archive_password,
trigger_target_scan, update_target, validate_artifact_ref, validate_target_name,
ArchivePassword, ArtifactInputDto, PasswordOutcome,
};
use crate::infrastructure::platform::{use_source_only, SourceOnlyNote};
use crate::i18n::{format_ago, use_lang, Lang};
use crate::infrastructure::evidence::fetch_compliance_summary;
use crate::infrastructure::onboarding::{fetch_targets, trigger_target_scan};
use compliance_core::models::{ScanRun, ScanRunStatus};
/// The last scan's badge class and label (with the step a running scan is
/// at), or `None` before the first scan.
/// How often the list refreshes while a scan is running, in milliseconds.
#[cfg(feature = "web")]
const REFRESH_MS: u32 = 5_000;
fn last_scan_label(target: &serde_json::Value, lang: Lang) -> Option<(&'static str, String)> {
/// The last scan's badge class and label (with the step a running scan is
/// at) and how long ago it was, or `None` before the first scan.
fn last_scan_label(
target: &serde_json::Value,
lang: Lang,
) -> Option<(&'static str, String, String)> {
let run = target.get("last_scan").filter(|r| !r.is_null())?;
let run: compliance_core::models::ScanRun = serde_json::from_value(run.clone()).ok()?;
let run: ScanRun = serde_json::from_value(run.clone()).ok()?;
let (badge, status) = status_badge(&run.status);
let label = if run.status == compliance_core::models::ScanRunStatus::Running {
let label = if run.status == ScanRunStatus::Running {
format!(
"{} · {}",
status.get(lang),
@@ -43,7 +40,12 @@ fn last_scan_label(target: &serde_json::Value, lang: Lang) -> Option<(&'static s
} else {
status.get(lang).to_string()
};
Some((badge, label))
let ago = format_ago(
&run.completed_at.unwrap_or(run.started_at),
&chrono::Utc::now(),
lang,
);
Some((badge, label, ago))
}
fn str_at<'a>(v: &'a serde_json::Value, key: &str) -> &'a str {
@@ -58,66 +60,13 @@ fn target_id(t: &serde_json::Value) -> String {
.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 source_only = use_source_only();
let lang = use_lang()();
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;", {tx::NO_SCANS.get(lang)} }
}
ScanCoverage { scans: rows }
if pentest && source_only {
div { style: "margin-top: 6px; opacity: 0.75; font-size: 0.85em;",
{tx::PENTEST_SUPPORTED.get(lang)}
SourceOnlyNote { inline: true }
}
} else if pentest {
div { style: "margin-top: 6px; opacity: 0.75; font-size: 0.85em;",
{tx::PENTEST_SUPPORTED.get(lang)}
}
}
}
}
}
Some(None) => rsx! { div { style: "opacity: 0.6;", {tx::LOAD_FAILED.get(lang)} } },
None => rsx! { div { style: "opacity: 0.6;", {common::LOADING.get(lang)} } },
}
}
#[component]
pub fn TargetsPage() -> Element {
let mut toasts = use_context::<Toasts>();
let navigator = use_navigator();
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);
// Edit-target modal state.
let mut edit_id = use_signal(|| Option::<String>::None);
let mut edit_name = use_signal(String::new);
let mut edit_type = use_signal(String::new);
let mut edit_arts = use_signal(Vec::<ArtifactInputDto>::new);
let mut edit_saving = use_signal(|| false);
// In-modal "add artifact" mini-form.
let mut e_kind = use_signal(|| "git_repo".to_string());
let mut e_source = use_signal(String::new);
let mut e_branch = use_signal(|| "main".to_string());
let mut e_token = use_signal(String::new);
let mut targets = use_resource(move || async move { fetch_targets().await.ok() });
let summary = use_resource(move || async move { fetch_compliance_summary().await.ok() });
let lang = use_lang()();
// While a scan runs, its status and finding count change: keep the list
// current without a reload (the browser only).
@@ -142,481 +91,123 @@ pub fn TargetsPage() -> Element {
description: tx::SUBTITLE.get(lang),
}
div { style: "margin-bottom: 16px; display: flex; gap: 8px;",
Link { to: crate::app::Route::OnboardingPage {}, class: "btn btn-primary",
div { class: "page-actions",
Link { to: Route::OnboardingPage {}, class: "btn btn-primary",
{tx::ADD.get(lang)}
}
button {
class: "btn btn-secondary",
onclick: move |_| targets.restart(),
{tx::REFRESH.get(lang)}
}
}
// ── Delete confirmation ──
if let Some((del_id, del_name)) = confirm_delete() {
div { class: "modal-overlay",
div { class: "modal-dialog",
h3 { {tx::DELETE_TITLE.get(lang)} }
p { strong { "{del_name}" } }
p { class: "modal-warning", {tx::DELETE_WARNING.get(lang)} }
div { class: "modal-actions",
button {
class: "btn btn-secondary",
onclick: move |_| confirm_delete.set(None),
{tx::CANCEL.get(lang)}
}
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} {}", tx::DELETED.get(lang)),
);
targets.restart();
}
Err(e) => toasts.push(ToastType::Error, e.to_string()),
}
});
},
{tx::DELETE.get(lang)}
}
}
}
}
}
// ── Edit target ──
if let Some(eid) = edit_id() {
{
let name_err = validate_target_name(&edit_name());
let e_source_err = if e_source().is_empty() {
None
} else {
validate_artifact_ref(&e_kind(), &e_source())
};
rsx! {
div { class: "modal-overlay",
div { class: "modal-dialog",
h3 { {tx::EDIT_TITLE.get(lang)} }
div { class: "form-group",
label { {tx::COL_NAME.get(lang)} }
input {
r#type: "text",
value: "{edit_name}",
oninput: move |e| edit_name.set(e.value()),
}
if !edit_name().is_empty() {
if let Some(err) = name_err.clone() {
div { style: "color: var(--danger, #d33); font-size: 0.85em;", "{err}" }
}
}
}
div { class: "form-group",
label { {tx::COL_TYPE.get(lang)} }
select {
value: "{edit_type}",
oninput: move |e| edit_type.set(e.value()),
for (v, l) in kinds::TARGET_TYPES {
option { value: "{v}", selected: edit_type() == v, {l.get(lang)} }
}
}
}
label { style: "font-weight: 600;", {tx::ARTIFACTS.get(lang)} }
for (i, a) in edit_arts().iter().enumerate() {
div { style: "display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; flex-wrap: wrap;",
span { style: "font-size: 0.9em;",
span { style: "opacity: 0.7;", "{kinds::artifact_kind(&a.kind, lang)}: " }
span { style: "font-family: monospace;", "{a.source_ref}" }
if a.token.as_deref() == Some("") {
span { class: "badge badge-medium", style: "margin-left: 6px;", {tx::TOKEN_REMOVED.get(lang)} }
} else if a.has_token {
span { class: "badge badge-neutral", style: "margin-left: 6px;", {tx::TOKEN_SET.get(lang)} }
}
}
if a.kind == "git_repo" {
input {
r#type: "password",
autocomplete: "off",
placeholder: tx::NEW_TOKEN.get(lang),
style: "flex: 1; min-width: 180px;",
oninput: move |e| {
let v = e.value();
edit_arts.write()[i].token = (!v.is_empty()).then_some(v);
},
}
if a.has_token {
button {
class: "btn btn-ghost btn-sm",
onclick: move |_| { edit_arts.write()[i].token = Some(String::new()); },
{tx::REMOVE_TOKEN.get(lang)}
}
}
}
if a.archive_password != ArchivePassword::NotNeeded {
ArchivePasswordField {
target_id: edit_id().unwrap_or_default(),
artifact_id: a.artifact_id.clone(),
state: a.archive_password,
on_saved: move |_| edit_arts.write()[i].archive_password = ArchivePassword::Set,
}
}
button {
class: "btn btn-ghost btn-ghost-danger btn-sm",
onclick: move |_| { edit_arts.write().remove(i); },
{tx::REMOVE.get(lang)}
}
}
}
div { style: "display: flex; gap: 8px; align-items: flex-end; margin-top: 8px;",
div { class: "form-group", style: "margin: 0;",
label { {tx::KIND.get(lang)} }
select {
value: "{e_kind}",
oninput: move |e| e_kind.set(e.value()),
for (v, l) in kinds::ARTIFACT_KINDS {
option { value: "{v}", selected: e_kind() == v, {l.get(lang)} }
}
}
}
div { class: "form-group", style: "margin: 0; flex: 1;",
label { {tx::REFERENCE.get(lang)} }
input {
r#type: "text",
value: "{e_source}",
oninput: move |e| e_source.set(e.value()),
}
}
if e_kind() == "git_repo" {
div { class: "form-group", style: "margin: 0;",
label { {tx::BRANCH.get(lang)} }
input {
r#type: "text",
value: "{e_branch}",
oninput: move |e| e_branch.set(e.value()),
}
}
div { class: "form-group", style: "margin: 0;",
label { {tx::TOKEN.get(lang)} }
input {
r#type: "password",
autocomplete: "off",
value: "{e_token}",
oninput: move |e| e_token.set(e.value()),
}
}
}
button {
class: "btn btn-secondary",
disabled: e_source().trim().is_empty() || e_source_err.is_some(),
onclick: move |_| {
let kind = e_kind();
if !e_source().trim().is_empty()
&& validate_artifact_ref(&kind, &e_source()).is_none()
{
let git = kind == "git_repo";
let token = (git && !e_token().trim().is_empty()).then_some(e_token());
edit_arts.write().push(ArtifactInputDto {
branch: git.then_some(e_branch()),
has_token: token.is_some(),
token,
kind,
source_ref: e_source(),
..Default::default()
});
e_source.set(String::new());
e_token.set(String::new());
}
},
{tx::ADD_ARTIFACT.get(lang)}
}
}
if let Some(err) = e_source_err.clone() {
div { style: "color: var(--danger, #d33); font-size: 0.85em;", "{err}" }
}
div { class: "modal-actions",
button {
class: "btn btn-secondary",
onclick: move |_| edit_id.set(None),
{tx::CANCEL.get(lang)}
}
button {
class: "btn btn-primary",
disabled: edit_saving() || name_err.is_some(),
onclick: move |_| {
let id = eid.clone();
let nm = edit_name();
let tt = edit_type();
let arts = edit_arts();
edit_saving.set(true);
spawn(async move {
match update_target(id, Some(nm), Some(tt), Some(arts)).await {
Ok(_) => {
toasts.push(ToastType::Success, tx::UPDATED.get(lang));
targets.restart();
edit_id.set(None);
}
Err(e) => toasts.push(ToastType::Error, e.to_string()),
}
edit_saving.set(false);
});
},
if edit_saving() { {tx::SAVING.get(lang)} } else { {tx::SAVE.get(lang)} }
}
}
}
}
}
}
}
{
let targets_snapshot = targets.read().clone();
let counts_of = |id: &str| {
summary
.read()
.as_ref()
.and_then(|s| s.as_ref())
.and_then(|rows| rows.iter().find(|r| r.target_id == id))
.and_then(|r| r.counts)
};
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;", {tx::EMPTY.get(lang)} }
div { style: "display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;",
Link { to: crate::app::Route::OnboardingPage {}, class: "btn btn-primary",
{tx::EMPTY_ACTION.get(lang)}
}
DemoTargetsButton {
secondary: true,
on_seeded: move |_| targets.restart(),
}
}
p { style: "opacity: 0.6; font-size: 0.85em; margin-top: 10px;",
{tx::DEMO_HINT.get(lang)}
}
Some(Some(resp)) if resp.data.is_empty() => rsx! {
div { class: "card targets-empty",
p { {tx::EMPTY.get(lang)} }
div { class: "targets-empty-actions",
Link { to: Route::OnboardingPage {}, class: "btn btn-primary",
{tx::EMPTY_ACTION.get(lang)}
}
DemoTargetsButton {
secondary: true,
on_seeded: move |_| targets.restart(),
}
}
} else {
rsx! {
div { class: "card",
div { class: "table-wrapper",
table {
thead {
tr {
th { {tx::COL_NAME.get(lang)} }
th { {tx::COL_TYPE.get(lang)} }
th { {tx::COL_DETECTED.get(lang)} }
th { {tx::COL_LAST_SCAN.get(lang)} }
th { {tx::COL_FINDINGS.get(lang)} }
th { {tx::COL_ACTIONS.get(lang)} }
}
}
tbody {
for t in rows {
{
let id = target_id(&t);
let name = str_at(&t, "name").to_string();
let ttype = kinds::target_type(str_at(&t, "target_type"), lang);
let suggested = t
.get("classification")
.and_then(|c| c.get("suggested"))
.and_then(|s| s.as_str())
.map(|s| kinds::target_type(s, lang));
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 last_scan = last_scan_label(&t, lang);
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 id_edit = id.clone();
let name_del = name.clone();
let name_edit = name.clone();
let ttype_raw = str_at(&t, "target_type").to_string();
let artifacts_detail = artifacts.clone();
let artifacts_edit = 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 {
match last_scan.clone() {
Some((badge, label)) => rsx! { span { class: "{badge}", "{label}" } },
None => rsx! { span { style: "opacity: 0.5;", {scan_texts::NEVER_SCANNED.get(lang)} } },
}
}
td {
Link {
to: crate::app::Route::FindingsPage { target: id.clone() },
title: tx::SHOW_FINDINGS.get(lang),
"{findings}"
}
}
td { style: "display: flex; gap: 4px;",
button {
class: "btn btn-ghost",
title: tx::DETAILS.get(lang),
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: "btn btn-ghost",
title: tx::EDIT.get(lang),
onclick: move |_| {
edit_name.set(name_edit.clone());
edit_type.set(ttype_raw.clone());
let arts: Vec<ArtifactInputDto> = artifacts_edit
.iter()
.map(|a| ArtifactInputDto {
kind: str_at(a, "kind").to_string(),
source_ref: str_at(a, "source_ref").to_string(),
branch: a
.get("git")
.and_then(|g| g.get("default_branch"))
.and_then(|b| b.as_str())
.map(String::from),
// Kept, or an edit would reset a project
// archive to PLCopen XML.
plc_format: a
.get("plc")
.and_then(|p| p.get("format"))
.and_then(|f| f.as_str())
.map(String::from),
has_token: a
.get("auth")
.and_then(|x| x.get("method"))
.and_then(|m| m.as_str())
== Some("token"),
artifact_id: str_at(a, "id").to_string(),
archive_password: ArchivePassword::of(a),
..Default::default()
})
.collect();
edit_arts.set(arts);
e_source.set(String::new());
edit_id.set(Some(id_edit.clone()));
},
Icon { icon: BsPencil, width: 16, height: 16 }
}
button {
class: if is_scanning { "btn btn-ghost btn-scanning" } else { "btn btn-ghost" },
title: tx::RUN_SCAN.get(lang),
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, tx::SCAN_STARTED.get(lang));
targets.restart();
}
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: tx::DELETE.get(lang),
onclick: move |_| {
confirm_delete.set(Some((id_del.clone(), name_del.clone())));
},
Icon { icon: BsTrash, width: 16, height: 16 }
}
}
p { class: "targets-empty-hint", {tx::DEMO_HINT.get(lang)} }
}
},
Some(Some(resp)) => rsx! {
div { class: "card",
div { class: "table-wrapper",
table { class: "targets-table",
thead {
tr {
th { {tx::COL_NAME.get(lang)} }
th { {tx::COL_LAST_SCAN.get(lang)} }
th { {tx::CRA_TITLE.get(lang)} }
th { class: "num", {tx::COL_FINDINGS.get(lang)} }
th { span { class: "sr-only", {tx::COL_ACTIONS.get(lang)} } }
}
}
tbody {
for t in resp.data.iter() {
{
let id = target_id(t);
let name = str_at(t, "name").to_string();
let ttype = kinds::target_type(str_at(t, "target_type"), lang);
let findings = t.get("findings_count").and_then(|n| n.as_u64()).unwrap_or(0);
let last_scan = last_scan_label(t, lang);
let counts = counts_of(&id);
let is_scanning = scanning_ids().contains(&id);
let (id_open, id_scan) = (id.clone(), id.clone());
rsx! {
tr {
class: "targets-row",
onclick: move |_| { navigator.push(Route::TargetPage { id: id_open.clone() }); },
td {
Link {
to: Route::TargetPage { id: id.clone() },
class: "targets-name",
onclick: move |e: MouseEvent| e.stop_propagation(),
"{name}"
}
if is_expanded {
tr {
td { colspan: "6",
div { style: "padding: 12px 8px;",
div { style: "margin-bottom: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;",
Link {
to: crate::app::Route::CompliancePage { id: id.clone() },
class: "btn btn-primary",
{crate::i18n::texts::compliance::OPEN.get(lang)}
}
a {
class: "btn btn-secondary",
href: crate::infrastructure::evidence::evidence_pack_url(&id),
download: "",
{tx::EVIDENCE_PACK.get(lang)}
}
span { style: "opacity: 0.7; font-size: 0.85em;", {tx::EVIDENCE_HINT.get(lang)} }
}
h4 { style: "margin: 0 0 6px;", {scan_texts::HISTORY.get(lang)} }
ScanRunList { target_id: id.clone() }
h4 { style: "margin: 12px 0 6px;", {tx::ARTIFACTS.get(lang)} }
if artifacts_detail.is_empty() {
div { style: "opacity: 0.6;", {tx::NO_ARTIFACTS.get(lang)} }
}
for a in artifacts_detail {
div { style: "font-size: 0.9em; padding: 2px 0;",
span { style: "opacity: 0.7;", "{kinds::artifact_kind(str_at(&a, \"kind\"), lang)}: " }
span { style: "font-family: monospace;", "{str_at(&a, \"source_ref\")}" }
}
}
if !facts.is_empty() {
h4 { style: "margin: 12px 0 6px;", {tx::DETECTED_FACTS.get(lang)} }
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;", {tx::APPLICABLE_SCANS.get(lang)} }
TargetScans { id: id.clone() }
h4 { style: "margin: 12px 0 6px;", {crate::i18n::texts::manual::TITLE.get(lang)} }
ManualFindingsPanel {
target_id: id.clone(),
on_change: move |_| targets.restart(),
span { class: "targets-type", "{ttype}" }
}
td { class: "targets-scan",
match last_scan {
Some((badge, label, ago)) => rsx! {
span { class: "{badge}", "{label}" }
span { class: "targets-ago", "{ago}" }
},
None => rsx! { span { class: "targets-ago", {scan_texts::NEVER_SCANNED.get(lang)} } },
}
}
td { class: "targets-cra",
if let Some(counts) = counts {
CraBar { counts, compact: true }
}
}
td { class: "num",
Link {
to: Route::FindingsPage { target: id.clone() },
title: tx::SHOW_FINDINGS.get(lang),
onclick: move |e: MouseEvent| e.stop_propagation(),
"{findings}"
}
}
td { class: "targets-actions",
button {
class: if is_scanning { "btn btn-ghost btn-sm btn-scanning" } else { "btn btn-ghost btn-sm" },
title: tx::RUN_SCAN.get(lang),
disabled: is_scanning,
onclick: move |e: MouseEvent| {
e.stop_propagation();
let id = id_scan.clone();
scanning_ids.write().push(id.clone());
spawn(async move {
match trigger_target_scan(id.clone()).await {
Ok(_) => {
toasts.push(ToastType::Success, tx::SCAN_STARTED.get(lang));
targets.restart();
}
Err(e) => toasts.push(ToastType::Error, e.to_string()),
}
}
scanning_ids.write().retain(|i| i != &id);
});
},
if is_scanning {
span { class: "spinner" }
} else {
Icon { icon: BsPlayFill, width: 14, height: 14 }
}
{tx::RUN_SCAN.get(lang)}
}
}
}
@@ -627,7 +218,7 @@ pub fn TargetsPage() -> Element {
}
}
}
}
},
Some(None) => rsx! {
div { class: "card", p { {tx::LOAD_FAILED.get(lang)} } }
},
@@ -638,58 +229,3 @@ pub fn TargetsPage() -> Element {
}
}
}
/// The password of a stored, password-protected archive: its state, and a
/// field that checks and saves a new one at once (not with the editor's Save,
/// which never carries credentials).
#[component]
fn ArchivePasswordField(
target_id: String,
artifact_id: String,
state: ArchivePassword,
on_saved: EventHandler<()>,
) -> Element {
let lang = use_lang()();
let mut password = use_signal(String::new);
let mut note = use_signal(|| Option::<String>::None);
let (badge, label) = if state == ArchivePassword::Set {
("badge badge-neutral", common::PASSWORD_SET)
} else {
("badge badge-medium", common::PASSWORD_MISSING)
};
rsx! {
span { class: "{badge}", {label.get(lang)} }
input {
r#type: "password",
autocomplete: "off",
placeholder: common::ARCHIVE_PASSWORD.get(lang),
style: "flex: 1; min-width: 180px;",
value: "{password}",
oninput: move |e| password.set(e.value()),
}
button {
class: "btn btn-ghost btn-sm",
disabled: password().is_empty(),
onclick: move |_| {
let (target_id, artifact_id, pw) = (target_id.clone(), artifact_id.clone(), password());
spawn(async move {
let text = match set_archive_password(target_id, artifact_id, pw).await {
Ok(PasswordOutcome::Saved) => {
password.set(String::new());
on_saved.call(());
common::PASSWORD_SAVED.get(lang).to_string()
}
Ok(PasswordOutcome::Wrong) => common::PASSWORD_WRONG.get(lang).to_string(),
Ok(PasswordOutcome::NotEncrypted) => common::NOT_ENCRYPTED.get(lang).to_string(),
Err(e) => e.to_string(),
};
note.set(Some(text));
});
},
{common::SAVE_PASSWORD.get(lang)}
}
if let Some(text) = note() {
span { style: "font-size: 0.85em; opacity: 0.8;", "{text}" }
}
}
}