1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Navigation state types.
use crate::tui::app::TabKind;
// Navigation Context for Cross-View Navigation
// ============================================================================
/// Breadcrumb entry for navigation history
#[derive(Debug, Clone)]
pub struct Breadcrumb {
/// Tab we came from
pub tab: TabKind,
/// Description of what was selected (e.g., "CVE-2024-1234", "lodash")
pub label: String,
/// Selection index to restore when going back
pub selection_index: usize,
}
/// Navigation context for cross-view navigation and breadcrumbs
#[derive(Debug, Clone, Default)]
pub struct NavigationContext {
/// Breadcrumb trail for back navigation
pub breadcrumbs: Vec<Breadcrumb>,
/// Target component name to navigate to (for vuln → component navigation)
pub target_component: Option<String>,
/// Target vulnerability ID to navigate to (for component → vuln navigation)
pub target_vulnerability: Option<String>,
}
impl NavigationContext {
pub const fn new() -> Self {
Self {
breadcrumbs: Vec::new(),
target_component: None,
target_vulnerability: None,
}
}
/// Push a new breadcrumb onto the trail
pub fn push_breadcrumb(&mut self, tab: TabKind, label: String, selection_index: usize) {
self.breadcrumbs.push(Breadcrumb {
tab,
label,
selection_index,
});
}
/// Pop the last breadcrumb and return it (for back navigation)
pub fn pop_breadcrumb(&mut self) -> Option<Breadcrumb> {
self.breadcrumbs.pop()
}
/// Check if we have navigation history
pub fn has_history(&self) -> bool {
!self.breadcrumbs.is_empty()
}
/// Get the current breadcrumb trail as a string
pub fn breadcrumb_trail(&self) -> String {
self.breadcrumbs
.iter()
.map(|b| format!("{}: {}", b.tab.title(), b.label))
.collect::<Vec<_>>()
.join(" > ")
}
/// Clear navigation targets
pub fn clear_targets(&mut self) {
self.target_component = None;
self.target_vulnerability = None;
}
}