feat: implement filter
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-10 23:23:47 +02:00
parent 63420d9187
commit 07b768d0be
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
2 changed files with 42 additions and 13 deletions

View File

@ -12,6 +12,23 @@ use super::{
render_graph::summarize::SummarizeRenderGraph,
};
#[derive(Clone)]
pub enum FilterBy {
NotDone,
None,
}
impl Default for FilterBy {
fn default() -> Self {
Self::NotDone
}
}
#[derive(Default, Clone)]
pub struct DisplayOptions {
pub filter_by: FilterBy,
}
pub struct GraphExplorer<'a> {
state: SharedState,
@ -24,6 +41,8 @@ pub struct GraphExplorerState<'a> {
current_path: Option<&'a str>,
current_position: Vec<usize>,
display_options: DisplayOptions,
graph: Option<GraphItem>,
}
@ -36,6 +55,7 @@ impl<'a> GraphExplorer<'a> {
current_path: None,
current_position: Vec::new(),
graph: None,
display_options: DisplayOptions::default(),
},
}
}

View File

@ -1,8 +1,8 @@
use std::ops::Deref;
use hyperlog_core::log::{GraphItem, ItemState};
use itertools::Itertools;
use super::graph_explorer::{DisplayOptions, FilterBy};
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum GraphItemType {
Section,
@ -109,28 +109,31 @@ impl MovementGraph {
None => Vec::new(),
}
}
}
impl From<Box<GraphItem>> for MovementGraph {
fn from(value: Box<GraphItem>) -> Self {
value.deref().clone().into()
}
}
impl From<GraphItem> for MovementGraph {
fn from(value: GraphItem) -> Self {
pub fn new(graph_item: GraphItem, display_options: &DisplayOptions) -> MovementGraph {
let mut graph = MovementGraph::default();
match value {
match graph_item {
GraphItem::User(sections) | GraphItem::Section(sections) => {
let graph_items = sections
.iter()
.sorted_by(|(a, _), (b, _)| Ord::cmp(a, b))
.filter(|(_, item)| {
if let GraphItem::Item { state, .. } = item {
if matches!(display_options.filter_by, FilterBy::NotDone)
&& matches!(state, ItemState::Done)
{
return false;
}
}
true
})
.enumerate()
.map(|(i, (key, value))| MovementGraphItem {
index: i,
name: key.clone(),
values: value.clone().into(),
values: Self::new(value.clone(), display_options),
item_type: match value {
GraphItem::User(_) => GraphItemType::Section,
GraphItem::Section(_) => GraphItemType::Section,
@ -150,6 +153,12 @@ impl From<GraphItem> for MovementGraph {
}
}
impl From<GraphItem> for MovementGraph {
fn from(value: GraphItem) -> Self {
MovementGraph::new(value, &DisplayOptions::default())
}
}
#[cfg(test)]
mod test {
use std::collections::BTreeMap;