From f1278ccb12adab8ec9a172d61fd34a95264bb16a Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Sat, 7 Nov 2026 10:54:46 +0100 Subject: [PATCH] feat(dashboard): a PLC PROGRAM is a "Programm" in the code graph (t82) The graph keeps a PLC PROGRAM as a module. "Modul" names a bookable product, so the tooltip, the inspector, the search suggestions and the legend call it "Programm" (Program); a graph with PLC and other code shows both in the legend. Co-Authored-By: Claude Opus 5.5 --- compliance-dashboard/assets/graph-viz.js | 7 ++- .../src/components/code_inspector.rs | 3 +- compliance-dashboard/src/i18n/texts.rs | 32 +++++++++++++ .../src/pages/graph_explorer.rs | 47 ++++++++++++++----- 4 files changed, 73 insertions(+), 16 deletions(-) diff --git a/compliance-dashboard/assets/graph-viz.js b/compliance-dashboard/assets/graph-viz.js index f8ed61b..42f5f9d 100644 --- a/compliance-dashboard/assets/graph-viz.js +++ b/compliance-dashboard/assets/graph-viz.js @@ -42,7 +42,7 @@ var edgesDataset = null; var rawNodes = []; var rawEdges = []; - var texts = { kinds: {}, edges: {}, layout: "", entry: "", file: "" }; + var texts = { kinds: {}, edges: {}, program: "", plc: [], layout: "", entry: "", file: "" }; function token(name) { return getComputedStyle(document.documentElement).getPropertyValue(name).trim(); @@ -81,7 +81,10 @@ function toVisNode(node, counts, colors) { var color = colors.kinds[node.kind] || colors.fallback; var isGroup = node.kind === "community" || node.kind === "folder"; - var kindName = texts.kinds[node.kind] || node.kind; + // A PLC PROGRAM is kept as a module; it is named a program. + var kindName = node.kind === "module" && texts.plc.indexOf(node.language) >= 0 + ? texts.program + : texts.kinds[node.kind] || node.kind; // A group is sized by its members through `value`, which also scales its // label, so the large groups stay legible when the overview is zoomed out. var size = Math.max(8, Math.min(30, 8 + (counts[node.qualified_name] || 0) * 1.5)); diff --git a/compliance-dashboard/src/components/code_inspector.rs b/compliance-dashboard/src/components/code_inspector.rs index 0e2c3c2..922f838 100644 --- a/compliance-dashboard/src/components/code_inspector.rs +++ b/compliance-dashboard/src/components/code_inspector.rs @@ -11,6 +11,7 @@ pub fn CodeInspector( file_path: String, node_name: String, node_kind: String, + node_language: String, start_line: u32, end_line: u32, on_close: EventHandler<()>, @@ -37,7 +38,7 @@ pub fn CodeInspector( span { class: "code-inspector-file-name", "{file_path}" } } div { class: "code-inspector-meta", - span { class: "node-label-badge graph-kind-{node_kind}", {tx::kind(&node_kind).get(lang)} } + span { class: "node-label-badge graph-kind-{node_kind}", {tx::node_kind(&node_kind, &node_language).get(lang)} } span { class: "code-inspector-node-name", "{node_name}" } if start_line > 0 && end_line > 0 { span { class: "code-inspector-lines", "{tx::LINES.get(lang)} {start_line}–{end_line}" } diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 014b8fc..c0238aa 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -4736,6 +4736,25 @@ pub mod graph { } } + /// A PLC PROGRAM, which the graph keeps as a module ("Modul" names a + /// bookable product, so it is not used for PLC code). + pub const PROGRAM: Text = Text { + de: "Programm", + en: "Program", + }; + + /// The languages a PLC project is parsed as; their modules are programs. + pub const PLC_LANGUAGES: [&str; 2] = ["structured_text", "plcopen"]; + + /// A node's kind name, given its language: a PLC PROGRAM is a "Programm". + pub fn node_kind(kind: &str, language: &str) -> Text { + if kind == "module" && PLC_LANGUAGES.contains(&language) { + PROGRAM + } else { + self::kind(kind) + } + } + /// A node kind's name, for the legend, the tooltip and the inspector. pub fn kind(kind: &str) -> Text { match kind { @@ -4882,4 +4901,17 @@ pub mod graph { de: "Im Codegraph öffnen", en: "Open in the code graph", }; + + #[cfg(test)] + mod tests { + use super::*; + + #[test] + fn a_plc_program_is_named_a_program_not_a_module() { + assert_eq!(node_kind("module", "structured_text").de, "Programm"); + assert_eq!(node_kind("module", "plcopen").de, "Programm"); + assert_eq!(node_kind("module", "python").de, "Modul"); + assert_eq!(node_kind("class", "structured_text").de, "Klasse"); + } + } } diff --git a/compliance-dashboard/src/pages/graph_explorer.rs b/compliance-dashboard/src/pages/graph_explorer.rs index 01a78a7..712f027 100644 --- a/compliance-dashboard/src/pages/graph_explorer.rs +++ b/compliance-dashboard/src/pages/graph_explorer.rs @@ -54,6 +54,8 @@ fn viz_labels(lang: Lang) -> Value { .collect(); json!({ "kinds": kinds, + "program": tx::PROGRAM.get(lang), + "plc": tx::PLC_LANGUAGES, "edges": edges, "layout": tx::LAYOUT.get(lang), "entry": tx::ENTRY_POINT.get(lang), @@ -72,6 +74,10 @@ struct GraphFacts { groups: u64, /// The languages parsed, by name. languages: Vec, + /// Whether the graph has PLC code, and code in other languages: which + /// names its modules get in the legend. + has_plc: bool, + has_other: bool, /// `(edges sent, edges in the graph)` when the agent sent only part. truncated: Option<(usize, u64)>, } @@ -80,21 +86,22 @@ impl GraphFacts { fn of(data: &GraphData) -> Self { let build = data.build.as_ref(); let count = |key: &str| build.and_then(|b| b[key].as_u64()).unwrap_or(0); + let codes: Vec<&str> = build + .and_then(|b| b["languages_parsed"].as_array()) + .map(|codes| codes.iter().filter_map(Value::as_str).collect()) + .unwrap_or_default(); + let is_plc = |code: &&str| tx::PLC_LANGUAGES.contains(code); Self { drawable: data.nodes.len(), units: data.total_nodes.max(count("node_count")), relations: data.total_edges.max(count("edge_count")), groups: count("community_count"), - languages: build - .and_then(|b| b["languages_parsed"].as_array()) - .map(|codes| { - codes - .iter() - .filter_map(Value::as_str) - .map(|code| language_name(code).to_string()) - .collect() - }) - .unwrap_or_default(), + languages: codes + .iter() + .map(|code| language_name(code).to_string()) + .collect(), + has_plc: codes.iter().any(is_plc), + has_other: !codes.iter().all(is_plc), truncated: data .truncated .then_some((data.edges.len(), data.total_edges)), @@ -231,6 +238,18 @@ pub fn GraphExplorerPage(repo_id: String) -> Element { let relations = format_count(facts.relations, lang); let groups = format_count(facts.groups, lang); let capped = drawn.read().as_ref().and_then(|d| d.capped); + // A module is a "Programm" in PLC code; a graph with both shows both. + let legend: Vec<(&str, &str)> = LEGEND_KINDS + .into_iter() + .flat_map(|kind| match kind { + "module" => [ + facts.has_other.then(|| (kind, tx::kind(kind).get(lang))), + facts.has_plc.then(|| (kind, tx::PROGRAM.get(lang))), + ], + _ => [Some((kind, tx::kind(kind).get(lang))), None], + }) + .flatten() + .collect(); let sel = selected(); let layout_class = if sel.is_some() { "graph-explorer-layout inspector-open" @@ -334,6 +353,7 @@ pub fn GraphExplorerPage(repo_id: String) -> Element { for node in search_results() { { let kind = node["kind"].as_str().unwrap_or_default().to_string(); + let language = node["language"].as_str().unwrap_or_default().to_string(); let name = node["name"].as_str().unwrap_or_default().to_string(); let path = node["file_path"].as_str().unwrap_or_default().to_string(); rsx! { @@ -346,7 +366,7 @@ pub fn GraphExplorerPage(repo_id: String) -> Element { search_results.set(Vec::new()); }, span { class: "search-suggestion-name", "{name}" } - span { class: "search-suggestion-kind", {tx::kind(&kind).get(lang)} } + span { class: "search-suggestion-kind", {tx::node_kind(&kind, &language).get(lang)} } span { class: "search-suggestion-path", "{path}" } } } @@ -440,6 +460,7 @@ pub fn GraphExplorerPage(repo_id: String) -> Element { file_path: node["file_path"].as_str().unwrap_or_default().to_string(), node_name: node["name"].as_str().unwrap_or_default().to_string(), node_kind: node["kind"].as_str().unwrap_or_default().to_string(), + node_language: node["language"].as_str().unwrap_or_default().to_string(), start_line: node["start_line"].as_u64().unwrap_or(0) as u32, end_line: node["end_line"].as_u64().unwrap_or(0) as u32, on_close: move |_| selected.set(None), @@ -457,8 +478,8 @@ pub fn GraphExplorerPage(repo_id: String) -> Element { } } ul { class: "graph-legend", - for kind in LEGEND_KINDS { - li { span { class: "graph-legend-dot graph-kind-{kind}" } {tx::kind(kind).get(lang)} } + for (kind, name) in legend { + li { span { class: "graph-legend-dot graph-kind-{kind}" } {name} } } li { span { class: "graph-legend-dot graph-legend-entry" } {tx::ENTRY_POINT.get(lang)} } if current != GraphView::All {