From ffe31964e684d6dc0ff5d50ffa29986ad0fab7d7 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Thu, 8 Oct 2026 21:24:15 +0000 Subject: [PATCH] fix(dashboard): targets named owner/repo can be edited and saved (#527) --- compliance-dashboard/src/i18n/texts.rs | 8 ++++ .../src/infrastructure/onboarding.rs | 41 ++++++++++++------- compliance-dashboard/src/pages/onboarding.rs | 4 +- compliance-dashboard/src/pages/target.rs | 4 +- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index c2d5de7..ee5c1d5 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -708,6 +708,14 @@ pub mod targets { de: "Typ", en: "Type", }; + pub const NAME_EMPTY: Text = Text { + de: "Bitte einen Namen eingeben", + en: "Enter a name", + }; + pub const NAME_OUTER_SPACES: Text = Text { + de: "Bitte Leerzeichen am Anfang und Ende entfernen", + en: "Remove the leading/trailing spaces", + }; pub const COL_LAST_SCAN: Text = Text { de: "Letzte Prüfung", en: "Last scan", diff --git a/compliance-dashboard/src/infrastructure/onboarding.rs b/compliance-dashboard/src/infrastructure/onboarding.rs index 0568fe3..fdea4f4 100644 --- a/compliance-dashboard/src/infrastructure/onboarding.rs +++ b/compliance-dashboard/src/infrastructure/onboarding.rs @@ -4,8 +4,8 @@ use dioxus::prelude::*; use serde::{Deserialize, Serialize}; -use crate::i18n::texts::demo; -use crate::i18n::Lang; +use crate::i18n::texts::{demo, targets}; +use crate::i18n::{Lang, Text}; /// One artifact the wizard collects for a target. #[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)] @@ -225,8 +225,6 @@ pub fn demo_seed_default_selection(targets: &[DemoSeedTarget], source_only: bool .collect() } -/// Validate a target name. The name is used as the clone directory downstream, -/// so it must be a single safe segment (no slashes) and free of stray spaces. /// Artifact kinds provided as an uploaded file (rather than a URL/text ref). pub fn is_file_kind(kind: &str) -> bool { matches!( @@ -249,18 +247,19 @@ pub fn plc_format_for(file_name: &str) -> Option<&'static str> { } } -pub fn validate_target_name(name: &str) -> Option { - let n = name.trim(); - if n.is_empty() { - return Some("Enter a name".to_string()); +/// Validate a target name, returning the message to show when it is unusable. +/// +/// Only an empty name and stray outer spaces are refused. Slashes are fine: +/// targets created from a git repo are named `owner/repo`, and the agent +/// collapses the name to one safe path segment wherever it needs a folder. +pub fn validate_target_name(name: &str) -> Option { + if name.trim().is_empty() { + Some(targets::NAME_EMPTY) + } else if name != name.trim() { + Some(targets::NAME_OUTER_SPACES) + } else { + None } - if name != n { - return Some("Remove the leading/trailing spaces".to_string()); - } - if n.contains('/') || n.contains('\\') { - return Some("No slashes — the name becomes a folder (e.g. stm32f411-blinky)".to_string()); - } - None } /// Client-side validation of an artifact reference for its kind. Returns an @@ -569,6 +568,18 @@ mod tests { assert_eq!(plc_format_for("firmware.bin"), None); assert!(is_file_kind("source_archive") && !is_file_kind("git_repo")); } + + #[test] + fn a_target_name_may_carry_slashes_but_not_blanks() { + assert_eq!(validate_target_name("bp-test/plc-codesys"), None); + assert_eq!(validate_target_name("sensor-node"), None); + assert_eq!(validate_target_name(""), Some(targets::NAME_EMPTY)); + assert_eq!(validate_target_name(" "), Some(targets::NAME_EMPTY)); + assert_eq!( + validate_target_name(" owner/repo"), + Some(targets::NAME_OUTER_SPACES) + ); + } use super::*; #[test] diff --git a/compliance-dashboard/src/pages/onboarding.rs b/compliance-dashboard/src/pages/onboarding.rs index ff5ed9d..a19134c 100644 --- a/compliance-dashboard/src/pages/onboarding.rs +++ b/compliance-dashboard/src/pages/onboarding.rs @@ -178,8 +178,8 @@ pub fn OnboardingPage() -> Element { oninput: move |e| name.set(e.value()), } if !name().is_empty() { - if let Some(err) = name_error.clone() { - div { style: "color: var(--danger, #d33); font-size: 0.85em; margin-top: 4px;", "{err}" } + if let Some(err) = name_error { + div { style: "color: var(--danger, #d33); font-size: 0.85em; margin-top: 4px;", {err.get(lang)} } } } } diff --git a/compliance-dashboard/src/pages/target.rs b/compliance-dashboard/src/pages/target.rs index e9512cc..e71ca2b 100644 --- a/compliance-dashboard/src/pages/target.rs +++ b/compliance-dashboard/src/pages/target.rs @@ -462,8 +462,8 @@ fn TargetEditor( 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}" } + if let Some(err) = name_err { + div { style: "color: var(--danger, #d33); font-size: 0.85em;", {err.get(lang)} } } } }