fix(dashboard): adding demo targets selects them by key #420

Merged
sharang merged 1 commits from fix/demo-seed into main 2026-09-28 21:23:49 +00:00
2 changed files with 17 additions and 9 deletions

No files matched your search

@@ -107,14 +107,14 @@ pub fn DemoTargetsButton(
for t in targets {
DemoTargetRow {
target: t.clone(),
checked: selected().contains(&t.name),
checked: selected().contains(&t.key),
disabled: source_only && !t.source_only,
on_toggle: move |name: String| {
on_toggle: move |key: String| {
let mut v = selected();
if let Some(p) = v.iter().position(|n| n == &name) {
if let Some(p) = v.iter().position(|k| k == &key) {
v.remove(p);
} else {
v.push(name);
v.push(key);
}
selected.set(v);
},
@@ -177,7 +177,8 @@ fn DemoTargetRow(
on_toggle: EventHandler<String>,
) -> Element {
let lang = use_lang()();
let name = target.name.clone();
// Selected by manifest key; the display name is only shown.
let key = target.key.clone();
let note = common::NOT_AVAILABLE_HERE.get(lang);
let style = if disabled {
"display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); opacity: 0.55;"
@@ -190,7 +191,7 @@ fn DemoTargetRow(
r#type: "checkbox",
checked: checked && !disabled,
disabled: disabled,
onchange: move |_| on_toggle.call(name.clone()),
onchange: move |_| on_toggle.call(key.clone()),
}
div { style: "flex: 1; min-width: 0;",
div { style: "display: flex; gap: 8px; align-items: center; flex-wrap: wrap;",
@@ -147,6 +147,10 @@ pub struct ApplicableScansResponse {
/// One entry of the demo-target manifest (`GET /api/v1/targets/demo-seed`).
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct DemoSeedTarget {
/// The manifest key: what a seed request selects by.
pub key: String,
/// The display name, prefix included (what the target is called once
/// seeded).
pub name: String,
#[serde(default)]
pub kind: String,
@@ -217,7 +221,7 @@ pub fn demo_seed_default_selection(targets: &[DemoSeedTarget], source_only: bool
targets
.iter()
.filter(|t| !source_only || t.source_only)
.map(|t| t.name.clone())
.map(|t| t.key.clone())
.collect()
}
@@ -661,8 +665,11 @@ mod tests {
fn manifest_parses_and_default_selection_respects_source_only() {
let body = serde_json::json!({
"targets": [
{"name": "plc-pump-station", "kind": "plc_sps", "description": "x", "source_only": true},
{"name": "web-juice-shop", "kind": "web_app", "description": "y", "source_only": false}
// The agent's shape: a key to select by, and a display name.
{"key": "plc-pump-station", "name": "Demo · PLC pump station",
"kind": "plc_sps", "description": "x", "source_only": true},
{"key": "web-juice-shop", "name": "Demo · Juice Shop",
"kind": "web_app", "description": "y", "source_only": false}
]
});
let list: DemoSeedListResponse = serde_json::from_value(body).unwrap();