From ac17650e8425e0ded9bdf5a4aef023de27ff9a8f Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:58:33 +0100 Subject: [PATCH 1/2] feat(dashboard): where a target's SBOM goes, the supplier's release screen (#1028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The supplier side of mockup RL3h ("Prüfwerk, Zulieferer: Freigaben eines Prüfobjekts") at /targets/{id}/releases, opened from the target page ("SBOM freigeben", own targets only). - The route: the target (components by ecosystem, last scan), a line to each connected customer: receives (with the version delivered), waiting, declined, component removed, connection gone, or a dashed "Freigeben an …". One row per connection; ended releases are history. Each active release can be ended. The height follows the customers. - The published versions as a timeline (the latest four, older folded), each with how many customers it reached, and the next as a draft. - Publishing: the label, what it changes against the latest version, what goes to customers and what stays (the released_cyclonedx allowlist), who receives it, a preview download. - Refusals read in words; the agent_client `data` helper is shared. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- compliance-dashboard/assets/main.css | 344 ++++++ compliance-dashboard/src/app.rs | 4 + .../src/components/sidebar.rs | 1 + compliance-dashboard/src/i18n/texts.rs | 494 ++++++++ .../src/infrastructure/agent_client.rs | 20 + .../src/infrastructure/mod.rs | 1 + .../src/infrastructure/releases.rs | 228 ++++ .../src/infrastructure/supply_chain.rs | 28 +- compliance-dashboard/src/pages/mod.rs | 2 + compliance-dashboard/src/pages/releases.rs | 1007 +++++++++++++++++ compliance-dashboard/src/pages/target.rs | 15 +- 11 files changed, 2121 insertions(+), 23 deletions(-) create mode 100644 compliance-dashboard/src/infrastructure/releases.rs create mode 100644 compliance-dashboard/src/pages/releases.rs diff --git a/compliance-dashboard/assets/main.css b/compliance-dashboard/assets/main.css index b1d62ec..47f90a2 100644 --- a/compliance-dashboard/assets/main.css +++ b/compliance-dashboard/assets/main.css @@ -8974,3 +8974,347 @@ span.repo-crumb-name { color: var(--bg-card); background: var(--text-tertiary); } + +/* ============ SBOM releases (#1028): where a target's SBOM goes ============ */ +.rel-page { + display: flex; + flex-direction: column; + gap: 22px; + min-width: 0; + max-width: 1180px; +} +.rel-page > * { min-width: 0; } +.rel-note { + margin: 0; + padding: 10px 14px; + font-size: 14px; + color: var(--warning); + background: var(--warning-bg); + border-radius: 10px; +} +.rel-route, +.rel-train { + overflow-x: auto; + background: var(--bg-card); + border: 1px solid var(--border); + border-radius: 16px; +} +.rel-canvas { + position: relative; + background-image: radial-gradient(var(--border-bright) 1px, transparent 1.2px); + background-size: 20px 20px; +} +.rel-route-note { + margin: 0; + padding: 0 24px 20px; + max-width: 66ch; + font-size: 14px; + line-height: 1.5; + color: var(--text-secondary); +} +.rel-lines { + position: absolute; + inset: 0; + overflow: visible; + pointer-events: none; +} +.rel-line { + fill: none; + stroke-linecap: round; + stroke-linejoin: round; +} +.rel-line.live { stroke: var(--accent); stroke-width: 2.5; } +.rel-line.wait { stroke: var(--warning); stroke-width: 2; stroke-dasharray: 5 6; } +.rel-line.off { stroke: var(--border-strong); stroke-width: 2; stroke-dasharray: 5 6; } +.rel-line.thick { stroke-width: 3; } +.rel-arrow-head { fill: var(--accent); } +.rel-dot { stroke: var(--bg-card); stroke-width: 3; } +.rel-dot.live { fill: var(--accent); } +.rel-dot.wait { fill: var(--bg-card); stroke: var(--warning); stroke-width: 2; } +.rel-dot.off { fill: var(--bg-card); stroke: var(--border-strong); stroke-width: 2; } +.rel-target { + position: absolute; + box-sizing: border-box; + padding: 16px; + display: flex; + flex-direction: column; + justify-content: center; + gap: 8px; + color: var(--bg-card); + background: var(--text-primary); + border-radius: 18px; +} +.rel-target-kind { font-size: 12px; color: var(--text-faint); } +.rel-target-name { + font-size: 18px; + font-weight: 600; + letter-spacing: -0.01em; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.rel-eco { + display: flex; + gap: 2px; + height: 8px; + border-radius: 4px; + overflow: hidden; +} +/* Mixed toward the box's text colour, so they read on the dark box in the + light theme and on the light box in the dark one. */ +.rel-eco-part { background: color-mix(in srgb, var(--text-faint) 60%, var(--bg-card)); } +.rel-eco-part.eco-0 { background: color-mix(in srgb, var(--accent) 65%, var(--bg-card)); } +.rel-eco-part.eco-1 { background: color-mix(in srgb, var(--info) 65%, var(--bg-card)); } +.rel-eco-part.eco-2 { background: color-mix(in srgb, var(--warning) 65%, var(--bg-card)); } +.rel-chip { + position: absolute; + transform: translate(-50%, -50%); + max-width: 180px; + height: 26px; + box-sizing: border-box; + padding: 0 12px; + display: flex; + align-items: center; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + border-radius: 13px; + font-size: 12px; + font-weight: 600; +} +/* Opaque, so the line under it does not show through. */ +.rel-chip.live { color: var(--success); background: color-mix(in srgb, var(--success) 12%, var(--bg-card)); } +.rel-chip.wait { color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, var(--bg-card)); } +.rel-chip svg { flex: none; margin-right: 6px; } +.rel-chip.off { color: var(--text-secondary); background: var(--bg-elevated); } +.rel-peer { + position: absolute; + box-sizing: border-box; + padding: 10px 14px; + display: flex; + flex-direction: column; + justify-content: center; + gap: 2px; + font: inherit; + text-align: left; + color: var(--text-primary); + background: var(--bg-card); + border: 1px solid var(--border-bright); + border-radius: 14px; +} +.rel-peer.wait { border-color: color-mix(in srgb, var(--warning) 35%, var(--bg-card)); } +.rel-peer.off { background: var(--bg-primary); border-style: dashed; } +.rel-peer-name { + font-size: 15px; + font-weight: 600; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.rel-peer-status { font-size: 12px; color: var(--text-tertiary); } +.rel-peer-status.live { color: var(--success); } +.rel-peer-status.wait { color: var(--warning); } +.rel-peer-top { + display: flex; + align-items: baseline; + gap: 8px; + min-width: 0; +} +.rel-peer-top .rel-peer-name { flex: 1 1 auto; min-width: 0; } +.rel-end { + flex: none; + align-self: center; + margin-right: -6px; + width: 26px; + height: 26px; + display: inline-flex; + align-items: center; + justify-content: center; + padding: 0; + font: inherit; + font-size: 12px; + color: var(--text-tertiary); + background: none; + border: 0; + border-radius: 6px; + cursor: pointer; +} +.rel-end:hover { color: var(--danger); background: var(--danger-bg); } +.rel-peer-add { + flex-direction: row; + align-items: center; + justify-content: flex-start; + gap: 10px; + color: var(--accent); + background: var(--bg-primary); + border: 1.5px dashed var(--border-accent); + text-decoration: none; + cursor: pointer; +} +.rel-peer-add:hover { background: var(--accent-muted); } +.rel-peer-add .rel-peer-name { font-size: 14px; white-space: normal; } +.rel-plus { font-size: 22px; font-weight: 500; line-height: 1; } +.rel-train-canvas { + position: relative; + height: 200px; +} +.rel-train-canvas h2 { + position: absolute; + left: 32px; + top: 22px; + margin: 0; + font-size: 16px; + font-weight: 600; +} +.rel-train-canvas .rel-route-note { position: absolute; left: 32px; top: 64px; padding: 0; } +.rel-stops { margin: 0; padding: 0; list-style: none; } +.rel-stop { + position: absolute; + top: 64px; + width: 176px; + transform: translateX(-50%); + display: flex; + flex-direction: column; + align-items: center; + gap: 10px; + text-align: center; +} +.rel-stop-label { + height: 18px; + font-family: var(--font-mono); + font-size: 14px; + font-weight: 600; +} +.rel-stop-dot { + width: 16px; + height: 16px; + box-sizing: border-box; + border-radius: 8px; + background: var(--bg-card); + border: 3px solid var(--accent); +} +.rel-stop.latest .rel-stop-dot { + width: 20px; + height: 20px; + margin: -2px 0; + border: 0; + background: var(--accent); + box-shadow: 0 0 0 5px var(--accent-muted); +} +.rel-stop.older .rel-stop-dot { border-color: var(--border-strong); border-style: dotted; } +.rel-stop.draft .rel-stop-label, +.rel-stop.draft .rel-stop-meta { color: var(--accent); } +.rel-stop.draft .rel-stop-dot { + width: 20px; + height: 20px; + margin: -2px 0; + border: 2px dashed var(--accent); +} +.rel-stop-meta { font-size: 12px; line-height: 18px; color: var(--text-tertiary); } +.rel-reached { color: var(--success); } +.rel-publish { + display: flex; + flex-direction: column; + gap: 18px; + padding: 22px; + background: var(--bg-card); + border: 2px solid var(--accent); + border-radius: 16px; +} +.rel-publish-head { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 12px 16px; +} +.rel-publish-head h2 { + flex: 1 1 280px; + margin: 0; + font-size: 20px; + font-weight: 600; + letter-spacing: -0.02em; +} +.rel-publish-head label { font-size: 13px; color: var(--text-secondary); } +.rel-publish-head input { + width: 140px; + min-height: 40px; + box-sizing: border-box; + padding: 9px 12px; + font-family: var(--font-mono); + font-size: 14px; + color: var(--text-primary); + background: var(--bg-card); + border: 1px solid var(--border-bright); + border-radius: 8px; +} +.rel-last { font-size: 13px; color: var(--text-tertiary); } +.rel-publish-body { display: flex; flex-wrap: wrap; gap: 18px; } +.rel-changes { + flex: 1 1 320px; + display: flex; + flex-direction: column; + gap: 10px; +} +.rel-changes-title { font-size: 14px; font-weight: 600; } +.rel-diff { + display: flex; + gap: 3px; + height: 14px; + overflow: hidden; + border-radius: 7px; + background: var(--bg-primary); +} +.rel-diff-added { background: var(--accent); } +.rel-diff-updated { background: color-mix(in srgb, var(--accent) 45%, var(--bg-card)); } +.rel-diff-same { background: var(--border); } +.rel-diff-counts { + display: flex; + flex-wrap: wrap; + gap: 6px 16px; + font-size: 13px; + color: var(--text-secondary); +} +.rel-diff-added-text { color: var(--accent); } +.rel-diff-updated-text { color: color-mix(in srgb, var(--accent) 75%, var(--text-secondary)); } +.rel-changes-text { margin: 0; font-size: 13px; line-height: 1.5; color: var(--text-tertiary); } +.rel-blocked { margin: 0; font-size: 14px; line-height: 1.5; color: var(--warning); } +.rel-sieve { + flex: 1 1 380px; + display: grid; + grid-template-columns: minmax(0, 1fr) 4px minmax(0, 1fr); + gap: 14px; + padding: 14px; + background: var(--bg-primary); + border-radius: 14px; +} +.rel-sieve-side { display: flex; flex-direction: column; gap: 8px; } +.rel-sieve-title { font-size: 13px; font-weight: 600; color: var(--text-secondary); } +.rel-sieve-title.goes { color: var(--success); } +.rel-sieve-mesh { + border-radius: 2px; + background: repeating-linear-gradient(to bottom, var(--accent) 0 6px, transparent 6px 11px); +} +.rel-pills { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; } +.rel-pill { padding: 4px 10px; border-radius: 999px; } +.rel-pill.goes { + background: var(--bg-card); + border: 1px solid color-mix(in srgb, var(--success) 30%, var(--bg-card)); +} +.rel-pill.stays { color: var(--text-tertiary); border: 1px dashed var(--border-strong); } +.rel-publish-foot { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: flex-end; + gap: 12px; +} +.rel-recipients { + flex: 1 1 300px; + font-size: 13px; + line-height: 1.5; + color: var(--text-tertiary); +} +@media (max-width: 640px) { + .rel-sieve { grid-template-columns: minmax(0, 1fr); } + .rel-sieve-mesh { height: 4px; background: repeating-linear-gradient(to right, var(--accent) 0 6px, transparent 6px 11px); } +} diff --git a/compliance-dashboard/src/app.rs b/compliance-dashboard/src/app.rs index 5834505..f3b31aa 100644 --- a/compliance-dashboard/src/app.rs +++ b/compliance-dashboard/src/app.rs @@ -41,6 +41,10 @@ pub enum Route { }, #[route("/targets/:id/compliance")] CompliancePage { id: String }, + // Where the target's SBOM goes: its releases to connected customers + // and its published versions (#1028). + #[route("/targets/:id/releases")] + TargetReleasesPage { id: String }, // A machine (#1026): a product project and its targets; `?tab=` // `parts` (the default), `cves` or `history`. #[route("/projects/:id?:tab")] diff --git a/compliance-dashboard/src/components/sidebar.rs b/compliance-dashboard/src/components/sidebar.rs index 6e38f27..a3b5280 100644 --- a/compliance-dashboard/src/components/sidebar.rs +++ b/compliance-dashboard/src/components/sidebar.rs @@ -185,6 +185,7 @@ pub fn Sidebar() -> Element { (Route::SbomPage { .. }, Route::SbomPage { .. }) => true, (Route::SbomEcosystemPage { .. }, Route::SbomPage { .. }) => true, (Route::CompliancePage { .. }, Route::TargetsPage {}) => true, + (Route::TargetReleasesPage { .. }, Route::TargetsPage {}) => true, (Route::DastTargetsPage {}, Route::DastOverviewPage {}) => true, (Route::DastFindingsPage {}, Route::DastOverviewPage {}) => true, (Route::DastFindingDetailPage { .. }, Route::DastOverviewPage {}) => true, diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index d2e1801..9d894fa 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -7943,3 +7943,497 @@ pub mod supply_chain { } } } + +/// The supplier's release screen (#1028): where a target's SBOM goes. +pub mod releases { + use super::Text; + use crate::i18n::Lang; + + /// `14.11.` in German, `Nov 14` in English. + pub fn day(time: &chrono::DateTime, lang: Lang) -> String { + match lang { + Lang::De => time.format("%-d.%-m.").to_string(), + Lang::En => time.format("%b %-d").to_string(), + } + } + + /// `A`, `A und B`, `A, B und C`. + fn listed(names: &[String], lang: Lang) -> String { + let and = match lang { + Lang::De => " und ", + Lang::En => " and ", + }; + match names { + [] => String::new(), + [one] => one.clone(), + [rest @ .., last] => format!("{}{and}{last}", rest.join(", ")), + } + } + + pub fn title(name: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Wohin die SBOM von {name} geht"), + Lang::En => format!("Where the SBOM of {name} goes"), + } + } + pub const INTRO: Text = Text { + de: "Verbundene Kunden erhalten jede Version, die Sie veröffentlichen, sobald sie Ihre \ + Freigabe angenommen haben.", + en: "Connected customers receive every version you publish once they have accepted \ + your release.", + }; + pub const CRUMB: Text = Text { + de: "Freigaben", + en: "Releases", + }; + pub const ENTRY: Text = Text { + de: "SBOM freigeben", + en: "Release the SBOM", + }; + pub const ENTRY_HINT: Text = Text { + de: "An verbundene Kunden, Version für Version", + en: "To connected customers, version by version", + }; + pub const LOADING: Text = Text { + de: "Freigaben werden geladen …", + en: "Loading the releases …", + }; + pub const LOAD_FAILED: Text = Text { + de: "Die Freigaben lassen sich gerade nicht laden.", + en: "The releases cannot be loaded right now.", + }; + + // The delivery route. + pub const ROUTE: Text = Text { + de: "Lieferweg der SBOM", + en: "Where the SBOM is delivered", + }; + pub const YOUR_TARGET: Text = Text { + de: "Ihr Prüfobjekt", + en: "Your target", + }; + pub fn components(n: usize, scanned: Option<&str>, lang: Lang) -> String { + match (lang, scanned) { + (Lang::De, Some(day)) => format!("{n} Komponenten, Prüfung vom {day}"), + (Lang::De, None) => format!("{n} Komponenten"), + (Lang::En, Some(day)) => format!("{n} components, scan of {day}"), + (Lang::En, None) => format!("{n} components"), + } + } + pub fn ecosystems(parts: &[(String, u64)], lang: Lang) -> String { + let total: u64 = parts.iter().map(|(_, n)| n).sum(); + let each = parts + .iter() + .map(|(name, n)| format!("{n} {name}")) + .collect::>() + .join(", "); + match lang { + Lang::De => format!("{total} Komponenten: {each}"), + Lang::En => format!("{total} components: {each}"), + } + } + pub const OTHER_ECOSYSTEMS: Text = Text { + de: "andere", + en: "other", + }; + pub const RECEIVES: Text = Text { + de: "erhält jede Version", + en: "receives every version", + }; + pub fn delivered(label: &str, day: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("{label} am {day}"), + Lang::En => format!("{label} on {day}"), + } + } + pub const ACCEPTED: Text = Text { + de: "angenommen", + en: "accepted", + }; + pub const RECEIVES_NEXT: Text = Text { + de: "erhält die nächste Version", + en: "receives the next version", + }; + pub const WAITING: Text = Text { + de: "wartet auf Annahme", + en: "awaiting acceptance", + }; + pub const NOT_ACCEPTED: Text = Text { + de: "hat noch nicht angenommen", + en: "has not accepted yet", + }; + pub const DECLINED_CHIP: Text = Text { + de: "abgelehnt", + en: "declined", + }; + pub const DECLINED: Text = Text { + de: "hat abgelehnt", + en: "declined the release", + }; + pub const REMOVED_CHIP: Text = Text { + de: "Komponente entfernt", + en: "component removed", + }; + pub const REMOVED: Text = Text { + de: "erhält nichts mehr", + en: "receives nothing more", + }; + pub const GONE_CHIP: Text = Text { + de: "keine Verbindung", + en: "no connection", + }; + pub const GONE: Text = Text { + de: "Verbindung beendet", + en: "connection ended", + }; + pub const NOT_RELEASED: Text = Text { + de: "nicht freigegeben", + en: "not released", + }; + pub fn release_to(peer: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Freigeben an {peer}"), + Lang::En => format!("Release to {peer}"), + } + } + pub fn end_hint(peer: &str, lang: Lang) -> String { + match lang { + Lang::De => { + format!("Freigabe an {peer} beenden. Was {peer} schon erhalten hat, bleibt dort.") + } + Lang::En => { + format!("End the release to {peer}. What {peer} has received stays there.") + } + } + } + /// What one line of the route says, for a screen reader. + pub fn line(target: &str, peer: &str, state: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Von {target} zu {peer}: {state}"), + Lang::En => format!("From {target} to {peer}: {state}"), + } + } + pub const NO_CONNECTIONS: Text = Text { + de: "Noch keine Verbindung zu einem Kunden. Verbindungen stellen Sie im Portal her: \ + Sie erstellen einen Code, Ihr Kunde gibt ihn ein.", + en: "No connection to a customer yet. You make connections in the portal: you create \ + a code, your customer enters it.", + }; + pub const OPEN_PORTAL: Text = Text { + de: "Zum Portal", + en: "Open the portal", + }; + pub const CONNECTIONS_FAILED: Text = Text { + de: "Die Verbindungen lassen sich gerade nicht abrufen; gezeigt werden nur die \ + bestehenden Freigaben.", + en: "The connections cannot be read right now; only the existing releases are shown.", + }; + + // The published versions. + pub const VERSIONS: Text = Text { + de: "Veröffentlichte Versionen", + en: "Published versions", + }; + pub fn version_meta(day: &str, components: i64, lang: Lang) -> String { + match lang { + Lang::De => format!("{day}, {components} Komp."), + Lang::En => format!("{day}, {components} comp."), + } + } + pub fn to_customers(n: usize, lang: Lang) -> String { + match (lang, n) { + (Lang::De, 1) => "an 1 Kunden".to_string(), + (Lang::De, n) => format!("an {n} Kunden"), + (Lang::En, 1) => "to 1 customer".to_string(), + (Lang::En, n) => format!("to {n} customers"), + } + } + pub const BEFORE_RELEASES: Text = Text { + de: "vor den Freigaben", + en: "before any release", + }; + pub const TO_NOBODY: Text = Text { + de: "an keinen Kunden", + en: "to no customer", + }; + pub fn older(n: usize, lang: Lang) -> String { + match lang { + Lang::De => format!("{n} ältere"), + Lang::En => format!("{n} older"), + } + } + pub const NEXT: Text = Text { + de: "nächste", + en: "next", + }; + pub fn draft_from(scanned: Option<&str>, lang: Lang) -> String { + match (lang, scanned) { + (Lang::De, Some(day)) => format!("Entwurf aus der Prüfung vom {day}"), + (Lang::De, None) => "Entwurf".to_string(), + (Lang::En, Some(day)) => format!("Draft from the scan of {day}"), + (Lang::En, None) => "Draft".to_string(), + } + } + pub const NO_VERSIONS: Text = Text { + de: "Noch keine Version veröffentlicht.", + en: "No version published yet.", + }; + + // Publishing. + pub fn publish_title(label: &str, lang: Lang) -> String { + match (lang, label.is_empty()) { + (Lang::De, true) => "Nächste Version veröffentlichen".to_string(), + (Lang::De, false) => format!("Version {label} veröffentlichen"), + (Lang::En, true) => "Publish the next version".to_string(), + (Lang::En, false) => format!("Publish version {label}"), + } + } + pub const LABEL: Text = Text { + de: "Versionsangabe", + en: "Version label", + }; + pub const LABEL_PLACEHOLDER: Text = Text { + de: "z. B. 1.5.0", + en: "e.g. 1.5.0", + }; + pub fn last_label(label: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("zuletzt {label}"), + Lang::En => format!("last {label}"), + } + } + pub fn against(label: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Gegenüber {label}"), + Lang::En => format!("Compared with {label}"), + } + } + pub const ADDED: Text = Text { + de: "neu", + en: "new", + }; + pub const UPDATED: Text = Text { + de: "aktualisiert", + en: "updated", + }; + pub const REMOVED_COUNT: Text = Text { + de: "entfernt", + en: "removed", + }; + pub const UNCHANGED: Text = Text { + de: "unverändert", + en: "unchanged", + }; + pub fn changes_aria(added: usize, updated: usize, removed: usize, lang: Lang) -> String { + match lang { + Lang::De => { + format!("{added} neue, {updated} aktualisierte, {removed} entfernte Komponenten") + } + Lang::En => format!("{added} new, {updated} updated, {removed} removed components"), + } + } + pub fn examples(added: &[String], updated: &[String], lang: Lang) -> String { + let (a, u) = (listed(added, lang), listed(updated, lang)); + match (lang, a.is_empty(), u.is_empty()) { + (_, true, true) => String::new(), + (Lang::De, false, true) => format!("Neu unter anderem {a}."), + (Lang::De, true, false) => format!("Aktualisiert unter anderem {u}."), + (Lang::De, false, false) => format!("Neu unter anderem {a}; aktualisiert {u}."), + (Lang::En, false, true) => format!("New, among others, {a}."), + (Lang::En, true, false) => format!("Updated, among others, {u}."), + (Lang::En, false, false) => format!("New, among others, {a}; updated {u}."), + } + } + pub fn same_as(label: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Dieselben Komponenten wie {label}."), + Lang::En => format!("The same components as {label}."), + } + } + pub fn first_version(components: usize, lang: Lang) -> String { + match lang { + Lang::De => format!("Ihre erste Version: {components} Komponenten."), + Lang::En => format!("Your first version: {components} components."), + } + } + pub const BLOCKED_EMPTY: Text = Text { + de: "Die letzte Prüfung fand keine Komponenten; es gibt nichts zu veröffentlichen.", + en: "The last scan found no components; there is nothing to publish.", + }; + pub const BLOCKED_TOO_MANY: Text = Text { + de: "Mehr Komponenten, als eine Freigabe fasst. Bitte wenden Sie sich an den Support.", + en: "More components than a release holds. Please contact support.", + }; + pub const SIEVE: Text = Text { + de: "Was weitergegeben wird und was bei Ihnen bleibt", + en: "What is passed on and what stays with you", + }; + pub const GOES: Text = Text { + de: "Geht an Ihre Kunden", + en: "Goes to your customers", + }; + /// What a released SBOM keeps of each component (`released_cyclonedx`). + pub const GOES_ITEMS: [Text; 4] = [ + Text { + de: "Name und Version", + en: "Name and version", + }, + Text { + de: "purl, CPE", + en: "purl, CPE", + }, + Text { + de: "Lizenzen", + en: "Licences", + }, + Text { + de: "Hashes", + en: "Hashes", + }, + ]; + pub const STAYS: Text = Text { + de: "Bleibt bei Ihnen", + en: "Stays with you", + }; + pub const STAYS_ITEMS: [Text; 5] = [ + Text { + de: "Befunde", + en: "Findings", + }, + Text { + de: "Schwachstellen", + en: "Vulnerabilities", + }, + Text { + de: "Fundorte", + en: "Where it was found", + }, + Text { + de: "Ihre Lizenzprüfung", + en: "Your licence review", + }, + Text { + de: "interne Adressen", + en: "Internal addresses", + }, + ]; + /// Who receives version `label`: `now` at once, `later` once they + /// accept. + pub fn recipients(label: &str, now: &[String], later: &[String], lang: Lang) -> String { + let label = if label.is_empty() { + match lang { + Lang::De => "die Version", + Lang::En => "the version", + } + } else { + label + }; + let mut said = Vec::new(); + if !now.is_empty() { + let names = listed(now, lang); + said.push(match (lang, now.len()) { + (Lang::De, 1) => format!("{names} erhält {label} sofort."), + (Lang::De, _) => format!("{names} erhalten {label} sofort."), + (Lang::En, 1) => format!("{names} receives {label} at once."), + (Lang::En, _) => format!("{names} receive {label} at once."), + }); + } + if !later.is_empty() { + let names = listed(later, lang); + said.push(match (lang, later.len()) { + (Lang::De, 1) => { + format!("{names} erhält die jeweils neueste Version, sobald es annimmt.") + } + (Lang::De, _) => { + format!("{names} erhalten die jeweils neueste Version, sobald sie annehmen.") + } + (Lang::En, 1) => format!("{names} receives the latest version once it accepts."), + (Lang::En, _) => format!("{names} receive the latest version once they accept."), + }); + } + if said.is_empty() { + return match lang { + Lang::De => "Noch erhält sie kein Kunde: Geben Sie die SBOM oben frei.".to_string(), + Lang::En => "No customer receives it yet: release the SBOM above.".to_string(), + }; + } + said.join(" ") + } + pub const PREVIEW: Text = Text { + de: "Vorschau laden", + en: "Download a preview", + }; + pub fn publish(label: &str, lang: Lang) -> String { + match (lang, label.is_empty()) { + (Lang::De, true) => "Veröffentlichen".to_string(), + (Lang::De, false) => format!("{label} veröffentlichen"), + (Lang::En, true) => "Publish".to_string(), + (Lang::En, false) => format!("Publish {label}"), + } + } + pub const PUBLISHING: Text = Text { + de: "Wird veröffentlicht …", + en: "Publishing …", + }; + pub fn published(label: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Version {label} veröffentlicht"), + Lang::En => format!("Version {label} published"), + } + } + pub fn released(peer: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("An {peer} freigegeben"), + Lang::En => format!("Released to {peer}"), + } + } + pub fn ended(peer: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Freigabe an {peer} beendet"), + Lang::En => format!("Release to {peer} ended"), + } + } + /// The agent's refusal `error` in words; anything else as it came. + pub fn refusal(error: &str, lang: Lang) -> String { + // The agent's code is one word of the message, as in + // `error running server function: label_taken (409) (details: None)`. + const CODES: [&str; 7] = [ + "label_taken", + "label", + "empty", + "too_many_components", + "unknown_connection", + "peer_not_entitled", + "released", + ]; + let code = error + .split(|c: char| !(c.is_ascii_lowercase() || c == '_')) + .find(|word| CODES.contains(word)); + let text = match code { + Some("label_taken") => Text { + de: "Diese Versionsangabe gibt es schon. Wählen Sie eine neue.", + en: "This label exists already. Choose a new one.", + }, + Some("label") => Text { + de: "Die Versionsangabe ist leer oder zu lang (höchstens 64 Zeichen).", + en: "The label is empty or too long (64 characters at most).", + }, + Some("empty") => BLOCKED_EMPTY, + Some("too_many_components") => BLOCKED_TOO_MANY, + Some("unknown_connection") => Text { + de: "Diese Verbindung besteht nicht mehr.", + en: "This connection no longer exists.", + }, + Some("peer_not_entitled") => Text { + de: "Dieser Kunde nutzt Prüfwerk nicht und kann die Freigabe nicht annehmen.", + en: "This customer does not use Prüfwerk and cannot accept the release.", + }, + Some("released") => Text { + de: "An diesen Kunden ist die SBOM schon freigegeben.", + en: "The SBOM is already released to this customer.", + }, + _ => return error.to_string(), + }; + text.get(lang).to_string() + } +} diff --git a/compliance-dashboard/src/infrastructure/agent_client.rs b/compliance-dashboard/src/infrastructure/agent_client.rs index 7ccc8a4..fd72cf5 100644 --- a/compliance-dashboard/src/infrastructure/agent_client.rs +++ b/compliance-dashboard/src/infrastructure/agent_client.rs @@ -66,6 +66,26 @@ pub async fn json_or_error( .map_err(|e| ServerFnError::new(e.to_string())) } +/// The `data` of the agent's answer to `req`, its usual envelope. +/// +/// # Errors +/// +/// An unreachable agent, or its refusal (as for [`json_or_error`]). +pub async fn data( + req: reqwest::RequestBuilder, +) -> Result { + #[derive(serde::Deserialize)] + struct Body { + data: T, + } + let resp = req + .send() + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + let body: Body = json_or_error(resp).await?; + Ok(body.data) +} + /// The response itself when the agent accepted the request, else the refusal /// (as for [`json_or_error`]); for a body the caller streams on. /// diff --git a/compliance-dashboard/src/infrastructure/mod.rs b/compliance-dashboard/src/infrastructure/mod.rs index d8b28a0..747c28e 100644 --- a/compliance-dashboard/src/infrastructure/mod.rs +++ b/compliance-dashboard/src/infrastructure/mod.rs @@ -24,6 +24,7 @@ pub mod onboarding; pub mod pentest; pub mod platform; pub mod projects; +pub mod releases; #[allow(clippy::too_many_arguments)] pub mod sbom; pub mod sbom_ecosystems; diff --git a/compliance-dashboard/src/infrastructure/releases.rs b/compliance-dashboard/src/infrastructure/releases.rs new file mode 100644 index 0000000..558875c --- /dev/null +++ b/compliance-dashboard/src/infrastructure/releases.rs @@ -0,0 +1,228 @@ +//! A target's SBOM releases to connected workspaces (#1028), the supplier's +//! side: the agent's `/api/v1/targets/{id}/releases` and `…/versions`, and +//! the workspace's connections (`/api/v1/connections`). + +use chrono::{DateTime, Utc}; +use dioxus::prelude::*; +use serde::{Deserialize, Serialize}; + +/// The other workspace's answer to a release. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum Answer { + /// Not answered yet. + Offered, + /// Accepted: it receives every version. + Accepted, + /// Declined. + Declined, + /// It removed the component the release went into. + Ended, +} + +/// A release of the target to one connected workspace. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct ReleaseDto { + pub id: String, + pub connection_id: String, + /// The other workspace's display name. + pub peer_name: String, + pub created_at: DateTime, + #[serde(default)] + pub ended_at: Option>, + /// Not ended. + pub active: bool, + /// `None` while it is open. + #[serde(default)] + pub answer: Option, + /// The version last delivered, and when. + #[serde(default)] + pub delivered_label: Option, + #[serde(default)] + pub delivered_at: Option>, +} + +/// A published version of the target's SBOM. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct VersionDto { + pub id: String, + pub label: String, + pub components: i64, + pub created_at: DateTime, + /// How many customers received it. + #[serde(default)] + pub customers: usize, +} + +/// The target's releases (active ones first) and versions (newest first). +#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)] +pub struct ReleasesDto { + pub releases: Vec, + pub versions: Vec, +} + +/// One of the workspace's active connections. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ConnectionDto { + pub id: String, + /// The other workspace's display name. + pub peer_name: String, +} + +/// Why the next version cannot be published. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum Unpublishable { + /// No components. + Empty, + /// More than a release holds. + TooManyComponents, +} + +/// What the next version changes against the latest published one. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct DraftChangesDto { + /// The latest published version's label. + pub against: String, + pub added: usize, + pub updated: usize, + pub removed: usize, + pub unchanged: usize, + #[serde(default)] + pub added_names: Vec, + #[serde(default)] + pub updated_names: Vec, +} + +/// The next version as publishing it now would make it. +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] +pub struct VersionDraftDto { + pub components: usize, + /// When the scan it comes from finished. + #[serde(default)] + pub scanned_at: Option>, + #[serde(default)] + pub blocked: Option, + /// `None` before the first version. + #[serde(default)] + pub changes: Option, +} + +/// Target `target_id`'s releases and versions. +#[server] +pub async fn fetch_releases(target_id: String) -> Result { + super::agent_client::data( + super::agent_client::agent_get(&format!("/api/v1/targets/{target_id}/releases")).await?, + ) + .await +} + +/// The workspace's active connections. An error when the registry cannot +/// be asked, so the page tells that apart from having none. +#[server] +pub async fn fetch_connections() -> Result, ServerFnError> { + super::agent_client::data(super::agent_client::agent_get("/api/v1/connections").await?).await +} + +/// What publishing target `target_id` now would make. +#[server] +pub async fn fetch_version_draft(target_id: String) -> Result { + super::agent_client::data( + super::agent_client::agent_get(&format!("/api/v1/targets/{target_id}/versions/draft")) + .await?, + ) + .await +} + +/// Release target `target_id` over connection `connection_id`. +#[server] +pub async fn create_release( + target_id: String, + connection_id: String, +) -> Result { + let req = super::agent_client::agent_request( + reqwest::Method::POST, + &format!("/api/v1/targets/{target_id}/releases"), + ) + .await? + .json(&serde_json::json!({ "connection_id": connection_id })); + super::agent_client::data(req).await +} + +/// End release `release_id` of target `target_id`. +#[server] +pub async fn end_release(target_id: String, release_id: String) -> Result<(), ServerFnError> { + let req = super::agent_client::agent_request( + reqwest::Method::POST, + &format!("/api/v1/targets/{target_id}/releases/{release_id}/end"), + ) + .await? + .json(&serde_json::json!({})); + super::agent_client::data::(req) + .await + .map(|_| ()) +} + +/// Publish the next version of target `target_id`, labelled `label`. +#[server] +pub async fn publish_version( + target_id: String, + label: String, +) -> Result { + let req = super::agent_client::agent_request( + reqwest::Method::POST, + &format!("/api/v1/targets/{target_id}/versions"), + ) + .await? + .json(&serde_json::json!({ "label": label })); + super::agent_client::data(req).await +} + +/// The document a version of target `target_id` labelled `label` would +/// hold, as JSON text to save. +#[server] +pub async fn fetch_version_preview( + target_id: String, + label: String, +) -> Result { + let resp = + super::agent_client::agent_get(&format!("/api/v1/targets/{target_id}/versions/preview")) + .await? + .query(&[("label", label.as_str())]) + .send() + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + let document: serde_json::Value = super::agent_client::json_or_error(resp).await?; + serde_json::to_string_pretty(&document).map_err(|e| ServerFnError::new(e.to_string())) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_agents_answers_read() { + let listed: ReleasesDto = serde_json::from_value(serde_json::json!({ + "releases": [{ + "id": "r1", "connection_id": "c-1", "peer_name": "Beispiel Maschinenbau", + "created_at": "2026-11-10T09:00:00Z", "ended_at": null, "active": true, + "answer": "accepted", "delivered_label": "1.4.0", + "delivered_at": "2026-11-14T10:00:00Z" + }], + "versions": [{ + "id": "v1", "label": "1.4.0", "components": 214, + "created_at": "2026-11-14T10:00:00Z", "created_by": "u1", "customers": 1 + }] + })) + .expect("readable"); + assert_eq!(listed.releases[0].answer, Some(Answer::Accepted)); + assert_eq!(listed.versions[0].customers, 1); + + let draft: VersionDraftDto = serde_json::from_value(serde_json::json!({ + "components": 0, "scanned_at": null, "blocked": "too_many_components", + "changes": null + })) + .expect("readable"); + assert_eq!(draft.blocked, Some(Unpublishable::TooManyComponents)); + } +} diff --git a/compliance-dashboard/src/infrastructure/supply_chain.rs b/compliance-dashboard/src/infrastructure/supply_chain.rs index e611cf0..cd7624c 100644 --- a/compliance-dashboard/src/infrastructure/supply_chain.rs +++ b/compliance-dashboard/src/infrastructure/supply_chain.rs @@ -147,39 +147,23 @@ pub struct ProjectDocumentsDto { pub store_path: String, } -/// The `data` of an agent answer to `req`. -#[cfg(feature = "server")] -async fn data( - req: reqwest::RequestBuilder, -) -> Result { - #[derive(Deserialize)] - struct Body { - data: T, - } - let resp = req - .send() - .await - .map_err(|e| ServerFnError::new(e.to_string()))?; - let body: Body = super::agent_client::json_or_error(resp).await?; - Ok(body.data) -} - /// The workspace's supply chain. #[server] pub async fn fetch_supply_chain() -> Result { - data(super::agent_client::agent_get("/api/v1/supply-chain").await?).await + super::agent_client::data(super::agent_client::agent_get("/api/v1/supply-chain").await?).await } /// The customer's arrangement of the supply chain. #[server] pub async fn fetch_supply_chain_layout() -> Result { - data(super::agent_client::agent_get("/api/v1/supply-chain/layout").await?).await + super::agent_client::data(super::agent_client::agent_get("/api/v1/supply-chain/layout").await?) + .await } /// Product project `id`'s description and documents. #[server] pub async fn fetch_project_documents(id: String) -> Result { - data( + super::agent_client::data( super::agent_client::agent_get(&format!("/api/v1/supply-chain/projects/{id}/documents")) .await?, ) @@ -193,7 +177,9 @@ pub async fn save_supply_chain_layout(positions: Vec) -> Result<(), super::agent_client::agent_request(reqwest::Method::PUT, "/api/v1/supply-chain/layout") .await? .json(&serde_json::json!({ "positions": positions })); - data::(req).await.map(|_| ()) + super::agent_client::data::(req) + .await + .map(|_| ()) } /// Reset the arrangement to the computed columns. diff --git a/compliance-dashboard/src/pages/mod.rs b/compliance-dashboard/src/pages/mod.rs index f4111d4..1af362b 100644 --- a/compliance-dashboard/src/pages/mod.rs +++ b/compliance-dashboard/src/pages/mod.rs @@ -19,6 +19,7 @@ pub mod onboarding; pub mod overview; pub mod pentest_dashboard; pub mod pentest_session; +pub mod releases; pub mod sbom; pub mod supply_chain; pub mod target; @@ -45,6 +46,7 @@ pub use onboarding::OnboardingPage; pub use overview::OverviewPage; pub use pentest_dashboard::PentestDashboardPage; pub use pentest_session::PentestSessionPage; +pub use releases::TargetReleasesPage; pub use sbom::SbomPage; pub use supply_chain::SupplyChainPage; pub use target::TargetPage; diff --git a/compliance-dashboard/src/pages/releases.rs b/compliance-dashboard/src/pages/releases.rs new file mode 100644 index 0000000..18beedc --- /dev/null +++ b/compliance-dashboard/src/pages/releases.rs @@ -0,0 +1,1007 @@ +//! Where a target's SBOM goes (#1028), the supplier's side of releases: the +//! target, a line to each connected customer showing whether it receives +//! the versions, the published versions as a timeline, and the next version +//! to publish with what it changes and what stays in the workspace. + +use dioxus::prelude::*; + +use compliance_core::models::auth::AuthInfo; +use compliance_core::sbom_ecosystems::EcosystemCount; + +use crate::app::Route; +use crate::components::no_access::use_can_write; +use crate::components::toast::{ToastType, Toasts}; +use crate::i18n::texts::{releases as tx, repo_views as rv}; +use crate::i18n::{use_lang, Lang}; +use crate::infrastructure::download::save_json; +use crate::infrastructure::onboarding::fetch_target; +use crate::infrastructure::releases::{ + create_release, end_release, fetch_connections, fetch_releases, fetch_version_draft, + fetch_version_preview, publish_version, Answer, ConnectionDto, ReleaseDto, Unpublishable, + VersionDraftDto, VersionDto, +}; +use crate::infrastructure::sbom_ecosystems::fetch_sbom_ecosystems; + +/// The route's width; it scrolls in its box on a narrow screen. +const WIDTH: i32 = 920; +/// The target's box. +const TARGET_X: i32 = 40; +const TARGET_W: i32 = 240; +const TARGET_H: i32 = 136; +/// Where the line to each customer leaves the trunk. +const JUNCTION_X: i32 = 440; +/// The customers' boxes. +const PEER_X: i32 = 640; +const PEER_W: i32 = 240; +const PEER_H: i32 = 76; +/// Room above the first and below the last customer. +const TOP: i32 = 40; +const BOTTOM: i32 = 36; +/// The versions the timeline shows; older ones fold into one stop. +const SHOWN_VERSIONS: usize = 4; +/// Ecosystems the target's bar names; the rest are one segment. +const NAMED_ECOSYSTEMS: usize = 3; + +/// One customer the route leads to: a connection, with its active release +/// if there is one, or an active release whose connection is gone. +#[derive(Debug, Clone, PartialEq)] +struct Row { + connection_id: String, + peer_name: String, + release: Option, + /// The connection is among the workspace's active ones (or they could + /// not be read, which is not taken as ended). + connected: bool, +} + +/// The customers, by connection: those with an active release keep it, +/// ended releases are history and not shown. `connections` is `None` when +/// they could not be read; only the active releases are shown then. +fn rows(connections: Option<&[ConnectionDto]>, releases: &[ReleaseDto]) -> Vec { + let active = |id: &str| { + releases + .iter() + .find(|r| r.active && r.connection_id == id) + .cloned() + }; + let Some(connections) = connections else { + return releases + .iter() + .filter(|r| r.active) + .map(|r| Row { + connection_id: r.connection_id.clone(), + peer_name: r.peer_name.clone(), + release: Some(r.clone()), + connected: true, + }) + .collect(); + }; + let mut listed: Vec = connections + .iter() + .map(|c| Row { + connection_id: c.id.clone(), + peer_name: c.peer_name.clone(), + release: active(&c.id), + connected: true, + }) + .collect(); + listed.extend( + releases + .iter() + .filter(|r| r.active && !connections.iter().any(|c| c.id == r.connection_id)) + .map(|r| Row { + connection_id: r.connection_id.clone(), + peer_name: r.peer_name.clone(), + release: Some(r.clone()), + connected: false, + }), + ); + listed +} + +/// Where a customer stands. +#[derive(Debug, Clone, PartialEq)] +enum RowState { + /// Accepted; `label` arrived on `day`. + Delivering { + label: String, + day: String, + }, + /// Accepted; nothing published since. + Accepted, + /// Released, not answered. + Waiting, + Declined, + /// It removed the component the release went into. + Removed, + /// Released, but the connection has ended. + Gone, + /// Connected, not released. + Open, +} + +impl RowState { + fn of(row: &Row, lang: Lang) -> Self { + let Some(release) = &row.release else { + return Self::Open; + }; + if !row.connected { + return Self::Gone; + } + match release.answer { + None | Some(Answer::Offered) => Self::Waiting, + Some(Answer::Declined) => Self::Declined, + Some(Answer::Ended) => Self::Removed, + Some(Answer::Accepted) => match (&release.delivered_label, &release.delivered_at) { + (Some(label), Some(at)) => Self::Delivering { + label: label.clone(), + day: tx::day(at, lang), + }, + _ => Self::Accepted, + }, + } + } + + /// The line's look: `live` (it receives), `wait` or `off`. + fn tone(&self) -> &'static str { + match self { + Self::Delivering { .. } | Self::Accepted => "live", + Self::Waiting => "wait", + Self::Declined | Self::Removed | Self::Gone | Self::Open => "off", + } + } + + /// The label on the line; none for a customer not released to. + fn chip(&self, lang: Lang) -> Option { + Some(match self { + Self::Delivering { label, day } => tx::delivered(label, day, lang), + Self::Accepted => tx::ACCEPTED.get(lang).to_string(), + Self::Waiting => tx::WAITING.get(lang).to_string(), + Self::Declined => tx::DECLINED_CHIP.get(lang).to_string(), + Self::Removed => tx::REMOVED_CHIP.get(lang).to_string(), + Self::Gone => tx::GONE_CHIP.get(lang).to_string(), + Self::Open => return None, + }) + } + + /// The line under the customer's name. + fn status(&self, lang: Lang) -> &'static str { + match self { + Self::Delivering { .. } => tx::RECEIVES.get(lang), + Self::Accepted => tx::RECEIVES_NEXT.get(lang), + Self::Waiting => tx::NOT_ACCEPTED.get(lang), + Self::Declined => tx::DECLINED.get(lang), + Self::Removed => tx::REMOVED.get(lang), + Self::Gone => tx::GONE.get(lang), + Self::Open => tx::NOT_RELEASED.get(lang), + } + } +} + +/// Where the route's boxes sit for `rows` customers. +#[derive(Debug, Clone, PartialEq, Eq)] +struct Geometry { + height: i32, + /// The middle of each customer's box. + row_y: Vec, + /// The middle of the target's box, where the trunk runs. + trunk_y: i32, +} + +impl Geometry { + fn for_rows(rows: usize) -> Self { + // Three customers get room for their labels; more sit closer. + let pitch = if rows <= 3 { 124 } else { 96 }; + let rows_i = i32::try_from(rows.max(1)).unwrap_or(i32::MAX / pitch); + let row_y: Vec = (0..rows_i).map(|i| TOP + i * pitch + PEER_H / 2).collect(); + let span = TOP + (rows_i - 1) * pitch + PEER_H + BOTTOM; + let height = span.max(TARGET_H + 2 * TOP); + let trunk_y = if rows_i == 1 { + height / 2 + } else { + (row_y[0] + row_y[row_y.len() - 1]) / 2 + }; + let row_y = if rows_i == 1 { vec![trunk_y] } else { row_y }; + Self { + height, + row_y, + trunk_y, + } + } +} + +/// How far a version reached. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum Reach { + Customers(usize), + /// Published before the target was first released. + BeforeReleases, + Nobody, +} + +fn reach(version: &VersionDto, releases: &[ReleaseDto]) -> Reach { + if version.customers > 0 { + return Reach::Customers(version.customers); + } + match releases.iter().map(|r| r.created_at).min() { + Some(first) if version.created_at >= first => Reach::Nobody, + _ => Reach::BeforeReleases, + } +} + +/// The versions the timeline shows, oldest first, and how many older ones +/// it folds. `versions` is newest first, as the agent lists them. +fn shown_versions(versions: &[VersionDto]) -> (usize, Vec<&VersionDto>) { + // With a fold, one slot goes to it. + let room = if versions.len() > SHOWN_VERSIONS { + SHOWN_VERSIONS - 1 + } else { + SHOWN_VERSIONS + }; + let shown: Vec<&VersionDto> = versions.iter().take(room).rev().collect(); + (versions.len() - shown.len(), shown) +} + +/// The target's bar: the largest ecosystems by name, the rest as `other`. +fn ecosystem_parts(counts: &[EcosystemCount], other: &str) -> Vec<(String, u64)> { + let mut sorted: Vec<&EcosystemCount> = counts.iter().filter(|c| c.components > 0).collect(); + sorted.sort_by(|a, b| b.components.cmp(&a.components)); + let mut parts: Vec<(String, u64)> = sorted + .iter() + .take(NAMED_ECOSYSTEMS) + .map(|c| (c.package_manager.clone(), c.components)) + .collect(); + let rest: u64 = sorted + .iter() + .skip(NAMED_ECOSYSTEMS) + .map(|c| c.components) + .sum(); + if rest > 0 { + parts.push((other.to_string(), rest)); + } + parts +} + +/// The supplier's releases of target `id`. +#[component] +pub fn TargetReleasesPage(id: String) -> Element { + let lang = use_lang()(); + let can_write = use_can_write(); + let portal_url = use_context::>().read().portal_url.clone(); + let target_id = use_signal(|| id.clone()); + let target = use_resource(move || async move { fetch_target(target_id()).await.ok() }); + let mut releases = use_resource(move || async move { fetch_releases(target_id()).await }); + let connections = use_resource(move || async move { fetch_connections().await.ok() }); + let mut next_version = + use_resource(move || async move { fetch_version_draft(target_id()).await.ok() }); + let ecosystems = + use_resource(move || async move { fetch_sbom_ecosystems(target_id()).await.ok() }); + + let name = target + .read() + .as_ref() + .and_then(|t| t.as_ref()) + .and_then(|t| { + t.data + .get("name") + .and_then(|n| n.as_str()) + .map(String::from) + }) + .unwrap_or_default(); + let listed = match &*releases.read() { + Some(Ok(listed)) => listed.clone(), + Some(Err(_)) => { + return rsx! { + ReleaseCrumbs { id: id.clone(), name } + div { class: "card", p { {tx::LOAD_FAILED.get(lang)} } } + } + } + None => return rsx! { div { class: "loading", {tx::LOADING.get(lang)} } }, + }; + // Until the connections are read (or when they cannot be), the active + // releases are shown as they are; none is taken for ended. + let connections_read = connections.read().clone(); + let failed = matches!(connections_read, Some(None)); + let known: Option> = connections_read.flatten(); + let rows = rows(known.as_deref(), &listed.releases); + let draft = next_version.read().clone().flatten().unwrap_or_default(); + let parts = ecosystem_parts( + &ecosystems.read().clone().flatten().unwrap_or_default(), + tx::OTHER_ECOSYSTEMS.get(lang), + ); + let on_change = move |_| releases.restart(); + let on_published = move |_| { + releases.restart(); + next_version.restart(); + }; + + rsx! { + div { class: "rel-page", + ReleaseCrumbs { id: id.clone(), name: name.clone() } + header { class: "chain-head", + h1 { {tx::title(&name, lang)} } + p { {tx::INTRO.get(lang)} } + } + if failed { + p { class: "rel-note", role: "status", {tx::CONNECTIONS_FAILED.get(lang)} } + } + ReleaseRoute { + target_id: id.clone(), + name: name.clone(), + rows: rows.clone(), + draft: draft.clone(), + parts, + can_write, + portal_url: if failed { String::new() } else { portal_url }, + on_change, + } + VersionTrain { + versions: listed.versions.clone(), + releases: listed.releases.clone(), + draft: draft.clone(), + show_draft: can_write, + } + if can_write { + PublishPanel { + target_id: id.clone(), + rows, + draft, + last: listed.versions.first().map(|v| v.label.clone()), + on_published, + } + } + } + } +} + +/// Überblick › the target › Freigaben. +#[component] +fn ReleaseCrumbs(id: String, name: String) -> Element { + let lang = use_lang()(); + rsx! { + nav { class: "repo-crumbs", "aria-label": rv::BREADCRUMB.get(lang), + Link { to: Route::OverviewPage {}, {rv::OVERVIEW.get(lang)} } + span { class: "repo-crumb-sep", "aria-hidden": "true", "›" } + Link { class: "repo-crumb-name", to: Route::target(id.clone()), "{name}" } + span { class: "repo-crumb-sep", "aria-hidden": "true", "›" } + span { "aria-current": "page", {tx::CRUMB.get(lang)} } + } + } +} + +/// The target, a line to each customer and the customer's box. +#[component] +fn ReleaseRoute( + target_id: String, + name: String, + rows: Vec, + draft: VersionDraftDto, + parts: Vec<(String, u64)>, + can_write: bool, + portal_url: String, + on_change: EventHandler<()>, +) -> Element { + let lang = use_lang()(); + let mut toasts = use_context::(); + let mut busy = use_signal(|| false); + let geometry = Geometry::for_rows(rows.len()); + let states: Vec = rows.iter().map(|r| RowState::of(r, lang)).collect(); + let trunk = if states.iter().any(|s| s.tone() == "live") { + "live" + } else { + "off" + }; + let (height, trunk_y) = (geometry.height, geometry.trunk_y); + let target_top = trunk_y - TARGET_H / 2; + let scanned = draft.scanned_at.as_ref().map(|t| tx::day(t, lang)); + let total: u64 = parts.iter().map(|(_, n)| n).sum(); + let component_count = if total > 0 { + usize::try_from(total).unwrap_or(usize::MAX) + } else { + draft.components + }; + // Lines that receive are drawn last, over the dashed ones. + let mut order: Vec = (0..rows.len()).collect(); + order.sort_by_key(|&i| states[i].tone() == "live"); + + rsx! { + section { class: "rel-route", "aria-label": tx::ROUTE.get(lang), + div { class: "rel-canvas", style: "width: {WIDTH}px; height: {height}px;", + svg { + class: "rel-lines", + width: "{WIDTH}", + height: "{height}", + "aria-hidden": "true", + defs { + marker { + id: "rel-arrow", + "markerWidth": "8", + "markerHeight": "8", + "refX": "6", + "refY": "4", + orient: "auto", + path { d: "M0 0 L8 4 L0 8 Z", class: "rel-arrow-head" } + } + } + path { + class: "rel-line {trunk}", + d: "M {TARGET_X + TARGET_W} {trunk_y} H {JUNCTION_X}", + } + if rows.is_empty() { + path { + class: "rel-line off", + d: "M {JUNCTION_X} {trunk_y} H {PEER_X}", + } + } + for i in order.iter().copied() { + { + let y = geometry.row_y[i]; + let tone = states[i].tone(); + let end = if tone == "live" { PEER_X - 8 } else { PEER_X }; + rsx! { + path { + class: "rel-line {tone}", + d: "M {JUNCTION_X} {trunk_y} V {y} H {end}", + "marker-end": if tone == "live" { "url(#rel-arrow)" }, + } + circle { class: "rel-dot {tone}", cx: "{JUNCTION_X}", cy: "{y}", r: "5" } + } + } + } + } + div { + class: "rel-target", + style: "left: {TARGET_X}px; top: {target_top}px; width: {TARGET_W}px; height: {TARGET_H}px;", + span { class: "rel-target-kind", {tx::YOUR_TARGET.get(lang)} } + span { class: "rel-target-name", "{name}" } + if total > 0 { + span { + class: "rel-eco", + role: "img", + "aria-label": tx::ecosystems(&parts, lang), + for (i, (eco, n)) in parts.iter().enumerate() { + span { key: "{eco}", class: "rel-eco-part eco-{i}", style: "flex: {n};" } + } + } + } + span { class: "rel-target-kind", {tx::components(component_count, scanned.as_deref(), lang)} } + } + for (i, row) in rows.iter().enumerate() { + { + let y = geometry.row_y[i]; + let state = states[i].clone(); + let top = y - PEER_H / 2; + let style = format!("left: {PEER_X}px; top: {top}px; width: {PEER_W}px; height: {PEER_H}px;"); + let peer = row.peer_name.clone(); + let chip = state.chip(lang).map(|text| { + let line = tx::line(&name, &peer, &text, lang); + (text, line) + }); + let tone = state.tone(); + rsx! { + if let Some((text, line)) = chip { + span { + class: "rel-chip {tone}", + style: "left: {(JUNCTION_X + PEER_X) / 2}px; top: {y}px;", + title: "{line}", + if matches!(state, RowState::Delivering { .. }) { + svg { width: "12", height: "12", view_box: "0 0 24 24", "aria-hidden": "true", + path { d: "M5 12.5l4.5 4.5L19 7.5", fill: "none", stroke: "currentColor", stroke_width: "3", stroke_linecap: "round", stroke_linejoin: "round" } + } + } + "{text}" + } + } + match (&row.release, can_write && state == RowState::Open) { + (None, true) => { + let connection = row.connection_id.clone(); + let target = target_id.clone(); + let peer = peer.clone(); + rsx! { + button { + class: "rel-peer rel-peer-add", + style: "{style}", + r#type: "button", + disabled: busy(), + onclick: move |_| { + let (connection, target, peer) = (connection.clone(), target.clone(), peer.clone()); + busy.set(true); + spawn(async move { + match create_release(target, connection).await { + Ok(_) => toasts.push(ToastType::Success, tx::released(&peer, lang)), + Err(e) => toasts.push(ToastType::Error, tx::refusal(&e.to_string(), lang)), + } + busy.set(false); + on_change.call(()); + }); + }, + span { class: "rel-plus", "aria-hidden": "true", "+" } + span { class: "rel-peer-name", {tx::release_to(&peer, lang)} } + } + } + } + (release, _) => { + let release_id = release.as_ref().map(|r| r.id.clone()); + let target = target_id.clone(); + let ending = peer.clone(); + rsx! { + div { class: "rel-peer {tone}", style: "{style}", + div { class: "rel-peer-top", + span { class: "rel-peer-name", title: "{peer}", "{peer}" } + if let (Some(release_id), true) = (release_id, can_write) { + button { + class: "rel-end", + r#type: "button", + title: tx::end_hint(&peer, lang), + "aria-label": tx::end_hint(&peer, lang), + disabled: busy(), + onclick: move |_| { + let (release_id, target, ending) = (release_id.clone(), target.clone(), ending.clone()); + busy.set(true); + spawn(async move { + match end_release(target, release_id).await { + Ok(()) => toasts.push(ToastType::Success, tx::ended(&ending, lang)), + Err(e) => toasts.push(ToastType::Error, tx::refusal(&e.to_string(), lang)), + } + busy.set(false); + on_change.call(()); + }); + }, + svg { width: "14", height: "14", view_box: "0 0 24 24", "aria-hidden": "true", + path { d: "M6 6l12 12M18 6L6 18", fill: "none", stroke: "currentColor", stroke_width: "2.2", stroke_linecap: "round" } + } + } + } + } + span { class: "rel-peer-status {tone}", {state.status(lang)} } + } + } + } + } + } + } + } + if rows.is_empty() { + { + let top = trunk_y - PEER_H / 2; + let style = format!("left: {PEER_X}px; top: {top}px; width: {PEER_W}px; height: {PEER_H}px;"); + rsx! { + if portal_url.is_empty() { + div { class: "rel-peer off", style: "{style}", + span { class: "rel-peer-status off", {tx::NOT_RELEASED.get(lang)} } + } + } else { + a { class: "rel-peer rel-peer-add", style: "{style}", href: "{portal_url}", + span { class: "rel-plus", "aria-hidden": "true", "+" } + span { class: "rel-peer-name", {tx::OPEN_PORTAL.get(lang)} } + } + } + } + } + } + } + if rows.is_empty() { + p { class: "rel-route-note", {tx::NO_CONNECTIONS.get(lang)} } + } + } + } +} + +/// The published versions, oldest to newest, and the next one. +#[component] +fn VersionTrain( + versions: Vec, + releases: Vec, + draft: VersionDraftDto, + show_draft: bool, +) -> Element { + let lang = use_lang()(); + let (older, shown) = shown_versions(&versions); + let with_draft = show_draft && draft.blocked.is_none() && draft.components > 0; + let stops = shown.len() + usize::from(older > 0) + usize::from(with_draft); + let slot = (WIDTH - 120) / i32::try_from(stops.max(1)).unwrap_or(1); + let x = |i: usize| 60 + slot * i32::try_from(i).unwrap_or(0) + slot / 2; + let fold = usize::from(older > 0); + let last_version = (fold + shown.len()).checked_sub(1); + let scanned = draft.scanned_at.as_ref().map(|t| tx::day(t, lang)); + const LINE_Y: i32 = 106; + + rsx! { + section { class: "rel-train", "aria-labelledby": "rel-train-h", + div { class: "rel-train-canvas", style: "width: {WIDTH}px;", + h2 { id: "rel-train-h", {tx::VERSIONS.get(lang)} } + if stops == 0 { + p { class: "rel-route-note", {tx::NO_VERSIONS.get(lang)} } + } else { + svg { class: "rel-lines", width: "{WIDTH}", height: "200", "aria-hidden": "true", + if let Some(last) = last_version.filter(|&l| l > 0) { + path { class: "rel-line live thick", d: "M {x(0)} {LINE_Y} H {x(last)}" } + } + if with_draft { + path { + class: "rel-line off thick", + d: "M {last_version.map_or(x(0), x)} {LINE_Y} H {x(stops - 1)}", + } + } + } + ol { class: "rel-stops", + if older > 0 { + li { class: "rel-stop older", style: "left: {x(0)}px;", + span { class: "rel-stop-label" } + span { class: "rel-stop-dot", "aria-hidden": "true" } + span { class: "rel-stop-meta", {tx::older(older, lang)} } + } + } + for (i, v) in shown.iter().enumerate() { + { + let at = x(fold + i); + let latest = Some(fold + i) == last_version; + let meta = tx::version_meta(&tx::day(&v.created_at, lang), v.components, lang); + let (reach_text, reached) = match reach(v, &releases) { + Reach::Customers(n) => (tx::to_customers(n, lang), true), + Reach::BeforeReleases => (tx::BEFORE_RELEASES.get(lang).to_string(), false), + Reach::Nobody => (tx::TO_NOBODY.get(lang).to_string(), false), + }; + rsx! { + li { key: "{v.id}", class: if latest { "rel-stop latest" } else { "rel-stop" }, style: "left: {at}px;", + span { class: "rel-stop-label", "{v.label}" } + span { class: "rel-stop-dot", "aria-hidden": "true" } + span { class: "rel-stop-meta", + "{meta}" + br {} + span { class: if reached { "rel-reached" } else { "" }, "{reach_text}" } + } + } + } + } + } + if with_draft { + li { class: "rel-stop draft", style: "left: {x(stops - 1)}px;", + span { class: "rel-stop-label", {tx::NEXT.get(lang)} } + span { class: "rel-stop-dot", "aria-hidden": "true" } + span { class: "rel-stop-meta", {tx::draft_from(scanned.as_deref(), lang)} } + } + } + } + } + } + } + } +} + +/// The next version: its label, what it changes, what is passed on, who +/// receives it, and publishing it. +#[component] +fn PublishPanel( + target_id: String, + rows: Vec, + draft: VersionDraftDto, + last: Option, + on_published: EventHandler<()>, +) -> Element { + let lang = use_lang()(); + let mut toasts = use_context::(); + let mut label = use_signal(String::new); + let mut publishing = use_signal(|| false); + let typed = label().trim().to_string(); + let receive_now: Vec = rows + .iter() + .filter(|r| { + r.connected && r.release.as_ref().and_then(|x| x.answer) == Some(Answer::Accepted) + }) + .map(|r| r.peer_name.clone()) + .collect(); + let receive_later: Vec = rows + .iter() + .filter(|r| { + r.connected + && r.release + .as_ref() + .is_some_and(|x| matches!(x.answer, None | Some(Answer::Offered))) + }) + .map(|r| r.peer_name.clone()) + .collect(); + let blocked = draft.blocked; + let can_publish = blocked.is_none() && !typed.is_empty() && !publishing(); + let preview_target = target_id.clone(); + + rsx! { + section { class: "rel-publish", "aria-labelledby": "rel-publish-h", + div { class: "rel-publish-head", + h2 { id: "rel-publish-h", {tx::publish_title(&typed, lang)} } + label { r#for: "rel-label", {tx::LABEL.get(lang)} } + input { + id: "rel-label", + r#type: "text", + maxlength: "64", + autocomplete: "off", + placeholder: tx::LABEL_PLACEHOLDER.get(lang), + value: "{label}", + oninput: move |e| label.set(e.value()), + } + if let Some(last) = &last { + span { class: "rel-last", {tx::last_label(last, lang)} } + } + } + div { class: "rel-publish-body", + div { class: "rel-changes", + match (blocked, &draft.changes) { + (Some(Unpublishable::Empty), _) => rsx! { p { class: "rel-blocked", {tx::BLOCKED_EMPTY.get(lang)} } }, + (Some(Unpublishable::TooManyComponents), _) => rsx! { p { class: "rel-blocked", {tx::BLOCKED_TOO_MANY.get(lang)} } }, + (None, None) => rsx! { p { class: "rel-changes-text", {tx::first_version(draft.components, lang)} } }, + (None, Some(c)) => rsx! { + span { class: "rel-changes-title", {tx::against(&c.against, lang)} } + span { + class: "rel-diff", + role: "img", + "aria-label": tx::changes_aria(c.added, c.updated, c.removed, lang), + if c.added > 0 { span { class: "rel-diff-added", style: "flex: {c.added};" } } + if c.updated > 0 { span { class: "rel-diff-updated", style: "flex: {c.updated};" } } + if c.unchanged > 0 { span { class: "rel-diff-same", style: "flex: {c.unchanged};" } } + } + span { class: "rel-diff-counts", + span { b { class: "rel-diff-added-text", "{c.added}" } " {tx::ADDED.get(lang)}" } + span { b { class: "rel-diff-updated-text", "{c.updated}" } " {tx::UPDATED.get(lang)}" } + span { b { "{c.removed}" } " {tx::REMOVED_COUNT.get(lang)}" } + span { "{c.unchanged} {tx::UNCHANGED.get(lang)}" } + } + p { class: "rel-changes-text", + if c.added + c.updated + c.removed == 0 { + {tx::same_as(&c.against, lang)} + } else { + {tx::examples(&c.added_names, &c.updated_names, lang)} + } + } + }, + } + } + div { class: "rel-sieve", role: "group", "aria-label": tx::SIEVE.get(lang), + div { class: "rel-sieve-side", + span { class: "rel-sieve-title goes", {tx::GOES.get(lang)} } + span { class: "rel-pills", + for item in tx::GOES_ITEMS { + span { class: "rel-pill goes", {item.get(lang)} } + } + } + } + div { class: "rel-sieve-mesh", "aria-hidden": "true" } + div { class: "rel-sieve-side", + span { class: "rel-sieve-title", {tx::STAYS.get(lang)} } + span { class: "rel-pills", + for item in tx::STAYS_ITEMS { + span { class: "rel-pill stays", {item.get(lang)} } + } + } + } + } + } + div { class: "rel-publish-foot", + span { class: "rel-recipients", {tx::recipients(&typed, &receive_now, &receive_later, lang)} } + button { + class: "btn btn-secondary", + r#type: "button", + disabled: blocked.is_some(), + onclick: move |_| { + let target = preview_target.clone(); + let preview_label = if label().trim().is_empty() { tx::NEXT.get(lang).to_string() } else { label().trim().to_string() }; + spawn(async move { + match fetch_version_preview(target, preview_label).await { + Ok(text) => save_json(&text, "release-preview.cdx.json"), + Err(e) => toasts.push(ToastType::Error, tx::refusal(&e.to_string(), lang)), + } + }); + }, + {tx::PREVIEW.get(lang)} + } + button { + class: "btn btn-primary", + r#type: "button", + disabled: !can_publish, + onclick: move |_| { + let (target, published) = (target_id.clone(), label().trim().to_string()); + publishing.set(true); + spawn(async move { + match publish_version(target, published.clone()).await { + Ok(_) => { + toasts.push(ToastType::Success, tx::published(&published, lang)); + label.set(String::new()); + } + Err(e) => toasts.push(ToastType::Error, tx::refusal(&e.to_string(), lang)), + } + publishing.set(false); + on_published.call(()); + }); + }, + if publishing() { {tx::PUBLISHING.get(lang)} } else { {tx::publish(&typed, lang)} } + } + } + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use chrono::{TimeZone, Utc}; + + fn release(id: &str, connection: &str, answer: Option, active: bool) -> ReleaseDto { + ReleaseDto { + id: id.into(), + connection_id: connection.into(), + peer_name: format!("Beispiel {connection}"), + created_at: Utc.with_ymd_and_hms(2026, 11, 10, 9, 0, 0).unwrap(), + ended_at: (!active).then(|| Utc.with_ymd_and_hms(2026, 11, 12, 9, 0, 0).unwrap()), + active, + answer, + delivered_label: None, + delivered_at: None, + } + } + + fn connection(id: &str) -> ConnectionDto { + ConnectionDto { + id: id.into(), + peer_name: format!("Beispiel {id}"), + } + } + + #[test] + fn each_connection_is_one_row_with_its_active_release() { + let releases = [ + release("r-old", "c-1", Some(Answer::Declined), false), + release("r-1", "c-1", Some(Answer::Accepted), true), + release("r-gone", "c-9", None, true), + ]; + let listed = rows(Some(&[connection("c-1"), connection("c-2")]), &releases); + + assert_eq!(listed.len(), 3, "an ended release is history, not a row"); + assert_eq!( + listed[0].release.as_ref().map(|r| r.id.as_str()), + Some("r-1") + ); + assert_eq!(listed[1].release, None); + assert_eq!(RowState::of(&listed[1], Lang::De), RowState::Open); + assert!(!listed[2].connected); + assert_eq!(RowState::of(&listed[2], Lang::De), RowState::Gone); + } + + #[test] + fn unreadable_connections_show_the_active_releases_as_connected() { + let releases = [ + release("r-1", "c-1", None, true), + release("r-2", "c-2", None, false), + ]; + let listed = rows(None, &releases); + + assert_eq!(listed.len(), 1); + assert_eq!(RowState::of(&listed[0], Lang::De), RowState::Waiting); + } + + #[test] + fn an_accepted_release_shows_what_it_received() { + let mut accepted = release("r-1", "c-1", Some(Answer::Accepted), true); + let row = |r: &ReleaseDto| Row { + connection_id: "c-1".into(), + peer_name: "Beispiel".into(), + release: Some(r.clone()), + connected: true, + }; + assert_eq!(RowState::of(&row(&accepted), Lang::De), RowState::Accepted); + accepted.delivered_label = Some("1.4.0".into()); + accepted.delivered_at = Some(Utc.with_ymd_and_hms(2026, 11, 14, 10, 0, 0).unwrap()); + let state = RowState::of(&row(&accepted), Lang::De); + assert_eq!(state.chip(Lang::De).as_deref(), Some("1.4.0 am 14.11.")); + assert_eq!(state.tone(), "live"); + } + + #[test] + fn the_route_grows_with_the_customers_without_overlapping() { + for n in [0, 1, 3, 4, 12] { + let g = Geometry::for_rows(n); + assert_eq!(g.row_y.len(), n.max(1)); + assert!(g.trunk_y - TARGET_H / 2 >= 0, "{n}: the target fits"); + assert!(g.trunk_y + TARGET_H / 2 <= g.height, "{n}: the target fits"); + for pair in g.row_y.windows(2) { + assert!(pair[1] - pair[0] >= PEER_H + 12, "{n}: boxes apart"); + } + assert!( + g.row_y[g.row_y.len() - 1] + PEER_H / 2 <= g.height, + "{n}: last box fits" + ); + } + } + + fn version(label: &str, day: u32, customers: usize) -> VersionDto { + VersionDto { + id: label.into(), + label: label.into(), + components: 200, + created_at: Utc.with_ymd_and_hms(2026, 11, day, 9, 0, 0).unwrap(), + customers, + } + } + + #[test] + fn the_timeline_shows_the_latest_versions_oldest_first() { + let few = [version("1.4.0", 14, 1), version("1.3.2", 6, 1)]; + let (older, shown) = shown_versions(&few); + assert_eq!(older, 0); + assert_eq!( + shown.iter().map(|v| v.label.as_str()).collect::>(), + ["1.3.2", "1.4.0"] + ); + + let many: Vec = (1..=30) + .rev() + .map(|d| version(&format!("1.{d}"), d, 0)) + .collect(); + let (older, shown) = shown_versions(&many); + assert_eq!(older, 27); + assert_eq!( + shown.iter().map(|v| v.label.as_str()).collect::>(), + ["1.28", "1.29", "1.30"] + ); + } + + #[test] + fn a_version_before_the_first_release_reached_nobody_by_design() { + let releases = [release("r-1", "c-1", None, true)]; + assert_eq!( + reach(&version("1.3.0", 1, 0), &releases), + Reach::BeforeReleases + ); + assert_eq!(reach(&version("1.5.0", 15, 0), &releases), Reach::Nobody); + assert_eq!( + reach(&version("1.4.0", 14, 2), &releases), + Reach::Customers(2) + ); + assert_eq!(reach(&version("1.4.0", 14, 0), &[]), Reach::BeforeReleases); + } + + #[test] + fn the_bar_names_the_largest_ecosystems() { + let count = |m: &str, n| EcosystemCount { + package_manager: m.into(), + components: n, + with_cve: 0, + }; + let parts = ecosystem_parts( + &[ + count("pypi", 22), + count("conan", 146), + count("npm", 53), + count("cargo", 3), + count("go", 2), + ], + "andere", + ); + assert_eq!( + parts, + [ + ("conan".into(), 146), + ("npm".into(), 53), + ("pypi".into(), 22), + ("andere".into(), 5) + ] + ); + } + + #[test] + fn a_refusal_reads_in_words() { + assert_eq!( + tx::refusal( + "error running server function: label_taken (409) (details: None)", + Lang::De + ), + "Diese Versionsangabe gibt es schon. Wählen Sie eine neue." + ); + assert_eq!( + tx::refusal("ServerError(\"released (409)\")", Lang::En), + "The SBOM is already released to this customer." + ); + assert_eq!( + tx::refusal("request failed (502)", Lang::En), + "request failed (502)" + ); + } +} diff --git a/compliance-dashboard/src/pages/target.rs b/compliance-dashboard/src/pages/target.rs index 7360779..6fb04a3 100644 --- a/compliance-dashboard/src/pages/target.rs +++ b/compliance-dashboard/src/pages/target.rs @@ -22,8 +22,8 @@ use crate::components::severity_badge::SeverityBadge; use crate::components::toast::{ToastType, Toasts}; use crate::components::webhook_deliveries::WebhookDeliveries; use crate::i18n::texts::{ - common, compliance::language_name, kinds, onboarding as onboarding_tx, repo_views as rv, - targets as tx, + common, compliance::language_name, kinds, onboarding as onboarding_tx, releases as releases_tx, + repo_views as rv, targets as tx, }; use crate::i18n::{format_ago, use_lang}; use crate::infrastructure::evidence::{fetch_compliance, CraCounts}; @@ -243,6 +243,17 @@ pub fn TargetPage(id: String) -> Element { } } EvidencePackButton { target_id: id.clone() } + // An own target's SBOM can go to connected customers (#1028); a + // bought-in component's came from its supplier. + if SupplierDto::of(&t).is_none() { + Link { + class: "btn btn-ghost", + to: Route::TargetReleasesPage { id: id.clone() }, + title: releases_tx::ENTRY_HINT.get(lang), + Icon { icon: BsSend, width: 14, height: 14 } + {releases_tx::ENTRY.get(lang)} + } + } if can_write { button { class: "btn btn-ghost", -- 2.54.1 From ee2c6138b845581a6ba8fbefabcef31d3b3066f6 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:14:12 +0100 Subject: [PATCH 2/2] fix(dashboard): the release screen claims nothing it has not read (#1028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Until the connections are read, no "no connection" note or portal box; until the draft is read, no component count and nothing to publish. - The page waits for the target, so the title always names it. - Ending a release takes two steps: the x asks, "Freigabe beenden" ends. - The preview needs a label: it is the document's version. - "Ihr Name als Zulieferer" among what goes to customers; "Noch keine Version veröffentlicht" beside a first draft. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- compliance-dashboard/assets/main.css | 13 ++ compliance-dashboard/src/i18n/texts.rs | 25 +++- compliance-dashboard/src/pages/releases.rs | 149 +++++++++++++-------- 3 files changed, 130 insertions(+), 57 deletions(-) diff --git a/compliance-dashboard/assets/main.css b/compliance-dashboard/assets/main.css index 47f90a2..88dba23 100644 --- a/compliance-dashboard/assets/main.css +++ b/compliance-dashboard/assets/main.css @@ -9140,6 +9140,19 @@ span.repo-crumb-name { cursor: pointer; } .rel-end:hover { color: var(--danger); background: var(--danger-bg); } +.rel-end-confirm { + align-self: flex-start; + margin-top: 2px; + padding: 2px 10px; + font: inherit; + font-size: 12px; + font-weight: 600; + color: var(--bg-card); + background: var(--danger); + border: 0; + border-radius: 6px; + cursor: pointer; +} .rel-peer-add { flex-direction: row; align-items: center; diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 9d894fa..40c8147 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -8090,12 +8090,24 @@ pub mod releases { de: "nicht freigegeben", en: "not released", }; + pub const NO_CUSTOMER: Text = Text { + de: "Noch kein Kunde verbunden", + en: "No customer connected yet", + }; pub fn release_to(peer: &str, lang: Lang) -> String { match lang { Lang::De => format!("Freigeben an {peer}"), Lang::En => format!("Release to {peer}"), } } + pub const END_CONFIRM: Text = Text { + de: "Freigabe beenden", + en: "End the release", + }; + pub const KEEP: Text = Text { + de: "Nicht beenden", + en: "Keep the release", + }; pub fn end_hint(peer: &str, lang: Lang) -> String { match lang { Lang::De => { @@ -8256,6 +8268,10 @@ pub mod releases { Lang::En => format!("Your first version: {components} components."), } } + pub const DRAFT_LOADING: Text = Text { + de: "Die nächste Version wird zusammengestellt …", + en: "Putting the next version together …", + }; pub const BLOCKED_EMPTY: Text = Text { de: "Die letzte Prüfung fand keine Komponenten; es gibt nichts zu veröffentlichen.", en: "The last scan found no components; there is nothing to publish.", @@ -8272,8 +8288,9 @@ pub mod releases { de: "Geht an Ihre Kunden", en: "Goes to your customers", }; - /// What a released SBOM keeps of each component (`released_cyclonedx`). - pub const GOES_ITEMS: [Text; 4] = [ + /// What a released SBOM holds (`released_cyclonedx`): each component's + /// identity, licences and hashes, and the workspace as the supplier. + pub const GOES_ITEMS: [Text; 5] = [ Text { de: "Name und Version", en: "Name and version", @@ -8290,6 +8307,10 @@ pub mod releases { de: "Hashes", en: "Hashes", }, + Text { + de: "Ihr Name als Zulieferer", + en: "Your name as the supplier", + }, ]; pub const STAYS: Text = Text { de: "Bleibt bei Ihnen", diff --git a/compliance-dashboard/src/pages/releases.rs b/compliance-dashboard/src/pages/releases.rs index 18beedc..4a8aea2 100644 --- a/compliance-dashboard/src/pages/releases.rs +++ b/compliance-dashboard/src/pages/releases.rs @@ -277,20 +277,19 @@ pub fn TargetReleasesPage(id: String) -> Element { let ecosystems = use_resource(move || async move { fetch_sbom_ecosystems(target_id()).await.ok() }); - let name = target - .read() - .as_ref() - .and_then(|t| t.as_ref()) - .and_then(|t| { - t.data - .get("name") - .and_then(|n| n.as_str()) - .map(String::from) - }) - .unwrap_or_default(); + let name = match &*target.read() { + Some(Some(t)) => t + .data + .get("name") + .and_then(|n| n.as_str()) + .unwrap_or_default() + .to_string(), + Some(None) => String::new(), + None => return rsx! { div { class: "loading", {tx::LOADING.get(lang)} } }, + }; let listed = match &*releases.read() { - Some(Ok(listed)) => listed.clone(), - Some(Err(_)) => { + Some(Ok(listed)) if !name.is_empty() => listed.clone(), + Some(_) => { return rsx! { ReleaseCrumbs { id: id.clone(), name } div { class: "card", p { {tx::LOAD_FAILED.get(lang)} } } @@ -302,9 +301,12 @@ pub fn TargetReleasesPage(id: String) -> Element { // releases are shown as they are; none is taken for ended. let connections_read = connections.read().clone(); let failed = matches!(connections_read, Some(None)); + let connections_known = matches!(connections_read, Some(Some(_))); let known: Option> = connections_read.flatten(); let rows = rows(known.as_deref(), &listed.releases); - let draft = next_version.read().clone().flatten().unwrap_or_default(); + // `None` while it loads or when it cannot be read: nothing is claimed + // about the next version then, and it cannot be published. + let draft = next_version.read().clone().flatten(); let parts = ecosystem_parts( &ecosystems.read().clone().flatten().unwrap_or_default(), tx::OTHER_ECOSYSTEMS.get(lang), @@ -332,7 +334,8 @@ pub fn TargetReleasesPage(id: String) -> Element { draft: draft.clone(), parts, can_write, - portal_url: if failed { String::new() } else { portal_url }, + connections_known, + portal_url, on_change, } VersionTrain { @@ -375,15 +378,19 @@ fn ReleaseRoute( target_id: String, name: String, rows: Vec, - draft: VersionDraftDto, + draft: Option, parts: Vec<(String, u64)>, can_write: bool, + /// The connections were read: an empty list means there are none. + connections_known: bool, portal_url: String, on_change: EventHandler<()>, ) -> Element { let lang = use_lang()(); let mut toasts = use_context::(); let mut busy = use_signal(|| false); + // The release whose end is being asked for. + let mut confirming = use_signal(|| None::); let geometry = Geometry::for_rows(rows.len()); let states: Vec = rows.iter().map(|r| RowState::of(r, lang)).collect(); let trunk = if states.iter().any(|s| s.tone() == "live") { @@ -393,13 +400,17 @@ fn ReleaseRoute( }; let (height, trunk_y) = (geometry.height, geometry.trunk_y); let target_top = trunk_y - TARGET_H / 2; - let scanned = draft.scanned_at.as_ref().map(|t| tx::day(t, lang)); + let scanned = draft + .as_ref() + .and_then(|d| d.scanned_at.as_ref()) + .map(|t| tx::day(t, lang)); let total: u64 = parts.iter().map(|(_, n)| n).sum(); let component_count = if total > 0 { - usize::try_from(total).unwrap_or(usize::MAX) + Some(usize::try_from(total).unwrap_or(usize::MAX)) } else { - draft.components + draft.as_ref().map(|d| d.components) }; + let none_connected = rows.is_empty() && connections_known; // Lines that receive are drawn last, over the dashed ones. let mut order: Vec = (0..rows.len()).collect(); order.sort_by_key(|&i| states[i].tone() == "live"); @@ -427,7 +438,7 @@ fn ReleaseRoute( class: "rel-line {trunk}", d: "M {TARGET_X + TARGET_W} {trunk_y} H {JUNCTION_X}", } - if rows.is_empty() { + if none_connected { path { class: "rel-line off", d: "M {JUNCTION_X} {trunk_y} H {PEER_X}", @@ -464,7 +475,9 @@ fn ReleaseRoute( } } } - span { class: "rel-target-kind", {tx::components(component_count, scanned.as_deref(), lang)} } + if let Some(n) = component_count { + span { class: "rel-target-kind", {tx::components(n, scanned.as_deref(), lang)} } + } } for (i, row) in rows.iter().enumerate() { { @@ -524,36 +537,52 @@ fn ReleaseRoute( let release_id = release.as_ref().map(|r| r.id.clone()); let target = target_id.clone(); let ending = peer.clone(); + // Ending takes two steps: the × asks, the button in the box ends. + let asking = release_id.is_some() && confirming() == release_id; + let ask_id = release_id.clone(); rsx! { div { class: "rel-peer {tone}", style: "{style}", div { class: "rel-peer-top", span { class: "rel-peer-name", title: "{peer}", "{peer}" } - if let (Some(release_id), true) = (release_id, can_write) { + if release_id.is_some() && can_write { button { class: "rel-end", r#type: "button", - title: tx::end_hint(&peer, lang), - "aria-label": tx::end_hint(&peer, lang), + title: if asking { tx::KEEP.get(lang).to_string() } else { tx::end_hint(&peer, lang) }, + "aria-label": if asking { tx::KEEP.get(lang).to_string() } else { tx::end_hint(&peer, lang) }, + "aria-expanded": "{asking}", disabled: busy(), - onclick: move |_| { - let (release_id, target, ending) = (release_id.clone(), target.clone(), ending.clone()); - busy.set(true); - spawn(async move { - match end_release(target, release_id).await { - Ok(()) => toasts.push(ToastType::Success, tx::ended(&ending, lang)), - Err(e) => toasts.push(ToastType::Error, tx::refusal(&e.to_string(), lang)), - } - busy.set(false); - on_change.call(()); - }); - }, + onclick: move |_| confirming.set(if asking { None } else { ask_id.clone() }), svg { width: "14", height: "14", view_box: "0 0 24 24", "aria-hidden": "true", path { d: "M6 6l12 12M18 6L6 18", fill: "none", stroke: "currentColor", stroke_width: "2.2", stroke_linecap: "round" } } } } } - span { class: "rel-peer-status {tone}", {state.status(lang)} } + if let (true, Some(release_id)) = (asking, release_id) { + button { + class: "rel-end-confirm", + r#type: "button", + title: tx::end_hint(&peer, lang), + disabled: busy(), + onclick: move |_| { + let (release_id, target, ending) = (release_id.clone(), target.clone(), ending.clone()); + busy.set(true); + spawn(async move { + match end_release(target, release_id).await { + Ok(()) => toasts.push(ToastType::Success, tx::ended(&ending, lang)), + Err(e) => toasts.push(ToastType::Error, tx::refusal(&e.to_string(), lang)), + } + busy.set(false); + confirming.set(None); + on_change.call(()); + }); + }, + {tx::END_CONFIRM.get(lang)} + } + } else { + span { class: "rel-peer-status {tone}", {state.status(lang)} } + } } } } @@ -561,14 +590,14 @@ fn ReleaseRoute( } } } - if rows.is_empty() { + if none_connected { { let top = trunk_y - PEER_H / 2; let style = format!("left: {PEER_X}px; top: {top}px; width: {PEER_W}px; height: {PEER_H}px;"); rsx! { if portal_url.is_empty() { div { class: "rel-peer off", style: "{style}", - span { class: "rel-peer-status off", {tx::NOT_RELEASED.get(lang)} } + span { class: "rel-peer-status off", {tx::NO_CUSTOMER.get(lang)} } } } else { a { class: "rel-peer rel-peer-add", style: "{style}", href: "{portal_url}", @@ -580,7 +609,7 @@ fn ReleaseRoute( } } } - if rows.is_empty() { + if none_connected { p { class: "rel-route-note", {tx::NO_CONNECTIONS.get(lang)} } } } @@ -592,27 +621,34 @@ fn ReleaseRoute( fn VersionTrain( versions: Vec, releases: Vec, - draft: VersionDraftDto, + draft: Option, show_draft: bool, ) -> Element { let lang = use_lang()(); let (older, shown) = shown_versions(&versions); - let with_draft = show_draft && draft.blocked.is_none() && draft.components > 0; + let with_draft = show_draft + && draft + .as_ref() + .is_some_and(|d| d.blocked.is_none() && d.components > 0); let stops = shown.len() + usize::from(older > 0) + usize::from(with_draft); let slot = (WIDTH - 120) / i32::try_from(stops.max(1)).unwrap_or(1); let x = |i: usize| 60 + slot * i32::try_from(i).unwrap_or(0) + slot / 2; let fold = usize::from(older > 0); let last_version = (fold + shown.len()).checked_sub(1); - let scanned = draft.scanned_at.as_ref().map(|t| tx::day(t, lang)); + let scanned = draft + .as_ref() + .and_then(|d| d.scanned_at.as_ref()) + .map(|t| tx::day(t, lang)); const LINE_Y: i32 = 106; rsx! { section { class: "rel-train", "aria-labelledby": "rel-train-h", div { class: "rel-train-canvas", style: "width: {WIDTH}px;", h2 { id: "rel-train-h", {tx::VERSIONS.get(lang)} } - if stops == 0 { + if shown.is_empty() { p { class: "rel-route-note", {tx::NO_VERSIONS.get(lang)} } - } else { + } + if stops > 0 { svg { class: "rel-lines", width: "{WIDTH}", height: "200", "aria-hidden": "true", if let Some(last) = last_version.filter(|&l| l > 0) { path { class: "rel-line live thick", d: "M {x(0)} {LINE_Y} H {x(last)}" } @@ -675,7 +711,7 @@ fn VersionTrain( fn PublishPanel( target_id: String, rows: Vec, - draft: VersionDraftDto, + draft: Option, last: Option, on_published: EventHandler<()>, ) -> Element { @@ -701,8 +737,10 @@ fn PublishPanel( }) .map(|r| r.peer_name.clone()) .collect(); - let blocked = draft.blocked; - let can_publish = blocked.is_none() && !typed.is_empty() && !publishing(); + let blocked = draft.as_ref().and_then(|d| d.blocked); + // A label is needed for the preview too: it is the document's version. + let ready = draft.is_some() && blocked.is_none() && !typed.is_empty(); + let can_publish = ready && !publishing(); let preview_target = target_id.clone(); rsx! { @@ -725,11 +763,12 @@ fn PublishPanel( } div { class: "rel-publish-body", div { class: "rel-changes", - match (blocked, &draft.changes) { - (Some(Unpublishable::Empty), _) => rsx! { p { class: "rel-blocked", {tx::BLOCKED_EMPTY.get(lang)} } }, - (Some(Unpublishable::TooManyComponents), _) => rsx! { p { class: "rel-blocked", {tx::BLOCKED_TOO_MANY.get(lang)} } }, - (None, None) => rsx! { p { class: "rel-changes-text", {tx::first_version(draft.components, lang)} } }, - (None, Some(c)) => rsx! { + match (draft.as_ref(), blocked, draft.as_ref().and_then(|d| d.changes.as_ref())) { + (None, _, _) => rsx! { p { class: "rel-changes-text", {tx::DRAFT_LOADING.get(lang)} } }, + (Some(_), Some(Unpublishable::Empty), _) => rsx! { p { class: "rel-blocked", {tx::BLOCKED_EMPTY.get(lang)} } }, + (Some(_), Some(Unpublishable::TooManyComponents), _) => rsx! { p { class: "rel-blocked", {tx::BLOCKED_TOO_MANY.get(lang)} } }, + (Some(d), None, None) => rsx! { p { class: "rel-changes-text", {tx::first_version(d.components, lang)} } }, + (Some(_), None, Some(c)) => rsx! { span { class: "rel-changes-title", {tx::against(&c.against, lang)} } span { class: "rel-diff", @@ -780,10 +819,10 @@ fn PublishPanel( button { class: "btn btn-secondary", r#type: "button", - disabled: blocked.is_some(), + disabled: !ready, onclick: move |_| { let target = preview_target.clone(); - let preview_label = if label().trim().is_empty() { tx::NEXT.get(lang).to_string() } else { label().trim().to_string() }; + let preview_label = label().trim().to_string(); spawn(async move { match fetch_version_preview(target, preview_label).await { Ok(text) => save_json(&text, "release-preview.cdx.json"), -- 2.54.1