feat: implement filter
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
63420d9187
commit
07b768d0be
@ -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(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user