Files
pruefwerk/compliance-dashboard/src/components/code_inspector.rs
T
sharang c8deabd4d9
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 5s
CI / Deploy Agent (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Dashboard (push) Successful in 3m27s
feat(dashboard): show the code graph, from its card and from a finding (t82) (#939)
2026-11-07 10:43:02 +00:00

99 lines
4.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
use dioxus::prelude::*;
use crate::i18n::texts::graph as tx;
use crate::i18n::use_lang;
use crate::infrastructure::graph::fetch_file_content;
/// A file of the code graph, with the selected code unit's lines marked.
#[component]
pub fn CodeInspector(
repo_id: String,
file_path: String,
node_name: String,
node_kind: String,
node_language: String,
start_line: u32,
end_line: u32,
on_close: EventHandler<()>,
) -> Element {
let lang = use_lang()();
let file_path_clone = file_path.clone();
let repo_id_clone = repo_id.clone();
let file_content = use_resource(move || {
let rid = repo_id_clone.clone();
let fp = file_path_clone.clone();
async move {
if fp.is_empty() {
return None;
}
fetch_file_content(rid, fp).await.ok()
}
});
rsx! {
div { class: "code-inspector-panel",
// Header
div { class: "code-inspector-header",
div { class: "code-inspector-title",
span { class: "code-inspector-file-name", "{file_path}" }
}
div { class: "code-inspector-meta",
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}" }
}
}
button {
class: "btn btn-ghost btn-sm code-inspector-close",
r#type: "button",
title: tx::CLOSE.get(lang),
"aria-label": tx::CLOSE.get(lang),
onclick: move |_| on_close.call(()),
"\u{2715}"
}
}
// Content
div { class: "code-inspector-body",
match &*file_content.read() {
Some(Some(resp)) => {
let lines: Vec<&str> = resp.data.content.split('\n').collect();
rsx! {
div { class: "code-inspector-code",
for (i, line) in lines.iter().enumerate() {
{
let line_num = (i + 1) as u32;
let is_highlighted = start_line > 0
&& line_num >= start_line
&& line_num <= end_line;
let class_name = if is_highlighted {
"code-line code-line-highlight"
} else {
"code-line"
};
rsx! {
div {
class: "{class_name}",
id: if is_highlighted && line_num == start_line { "highlighted-line" } else { "" },
span { class: "code-line-number", "{line_num}" }
span { class: "code-line-content", "{line}" }
}
}
}
}
}
}
},
Some(None) => rsx! {
div { class: "code-inspector-empty", {tx::FILE_FAILED.get(lang)} }
},
None => rsx! {
div { class: "loading", {tx::FILE_LOADING.get(lang)} }
},
}
}
}
}
}