From 78ccae8a1b146b23820520af4e6ddf000e3120ac Mon Sep 17 00:00:00 2001 From: kjuulh Date: Fri, 10 May 2024 23:46:51 +0200 Subject: [PATCH] feat: add filtering Signed-off-by: kjuulh --- crates/hyperlog-tui/src/command_parser.rs | 5 +++++ .../src/components/graph_explorer.rs | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/hyperlog-tui/src/command_parser.rs b/crates/hyperlog-tui/src/command_parser.rs index 2d25d9d..d38fe6a 100644 --- a/crates/hyperlog-tui/src/command_parser.rs +++ b/crates/hyperlog-tui/src/command_parser.rs @@ -7,6 +7,9 @@ pub enum Commands { Archive, CreateSection { name: String }, Edit, + + ShowAll, + HideDone, } impl Commands { @@ -37,6 +40,8 @@ impl CommandParser { name: name.to_string(), }), "e" | "edit" => Some(Commands::Edit), + "show-all" => Some(Commands::ShowAll), + "hide-done" => Some(Commands::HideDone), _ => None, }, None => None, diff --git a/crates/hyperlog-tui/src/components/graph_explorer.rs b/crates/hyperlog-tui/src/components/graph_explorer.rs index 93c9449..5c52582 100644 --- a/crates/hyperlog-tui/src/components/graph_explorer.rs +++ b/crates/hyperlog-tui/src/components/graph_explorer.rs @@ -12,7 +12,7 @@ use super::{ render_graph::summarize::SummarizeRenderGraph, }; -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum FilterBy { NotDone, None, @@ -24,7 +24,7 @@ impl Default for FilterBy { } } -#[derive(Default, Clone)] +#[derive(Default, Clone, Debug)] pub struct DisplayOptions { pub filter_by: FilterBy, } @@ -84,7 +84,11 @@ impl<'a> GraphExplorer<'a> { } fn linearize_graph(&self) -> Option { - self.inner.graph.clone().map(|g| g.into()) + tracing::trace!("current display options: {:?}", self.inner.display_options); + self.inner + .graph + .clone() + .map(|g| MovementGraph::new(g, &self.inner.display_options)) } /// Will only incrmeent to the next level @@ -223,6 +227,12 @@ impl<'a> GraphExplorer<'a> { } } } + Commands::ShowAll => { + self.inner.display_options.filter_by = FilterBy::None; + } + Commands::HideDone => { + self.inner.display_options.filter_by = FilterBy::NotDone; + } _ => (), } @@ -257,7 +267,8 @@ impl<'a> StatefulWidget for GraphExplorer<'a> { let _height = height as usize; if let Some(graph) = &state.graph { - let movement_graph: MovementGraph = graph.clone().into(); + let movement_graph: MovementGraph = + MovementGraph::new(graph.clone(), &state.display_options); let lines = movement_graph.render_graph(&state.current_position); let para = Paragraph::new(lines); para.render(area, buf);