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,
|
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> {
|
pub struct GraphExplorer<'a> {
|
||||||
state: SharedState,
|
state: SharedState,
|
||||||
|
|
||||||
@ -24,6 +41,8 @@ pub struct GraphExplorerState<'a> {
|
|||||||
current_path: Option<&'a str>,
|
current_path: Option<&'a str>,
|
||||||
current_position: Vec<usize>,
|
current_position: Vec<usize>,
|
||||||
|
|
||||||
|
display_options: DisplayOptions,
|
||||||
|
|
||||||
graph: Option<GraphItem>,
|
graph: Option<GraphItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +55,7 @@ impl<'a> GraphExplorer<'a> {
|
|||||||
current_path: None,
|
current_path: None,
|
||||||
current_position: Vec::new(),
|
current_position: Vec::new(),
|
||||||
graph: None,
|
graph: None,
|
||||||
|
display_options: DisplayOptions::default(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use hyperlog_core::log::{GraphItem, ItemState};
|
use hyperlog_core::log::{GraphItem, ItemState};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
use super::graph_explorer::{DisplayOptions, FilterBy};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
pub enum GraphItemType {
|
pub enum GraphItemType {
|
||||||
Section,
|
Section,
|
||||||
@ -109,28 +109,31 @@ impl MovementGraph {
|
|||||||
None => Vec::new(),
|
None => Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Box<GraphItem>> for MovementGraph {
|
pub fn new(graph_item: GraphItem, display_options: &DisplayOptions) -> MovementGraph {
|
||||||
fn from(value: Box<GraphItem>) -> Self {
|
|
||||||
value.deref().clone().into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<GraphItem> for MovementGraph {
|
|
||||||
fn from(value: GraphItem) -> Self {
|
|
||||||
let mut graph = MovementGraph::default();
|
let mut graph = MovementGraph::default();
|
||||||
|
|
||||||
match value {
|
match graph_item {
|
||||||
GraphItem::User(sections) | GraphItem::Section(sections) => {
|
GraphItem::User(sections) | GraphItem::Section(sections) => {
|
||||||
let graph_items = sections
|
let graph_items = sections
|
||||||
.iter()
|
.iter()
|
||||||
.sorted_by(|(a, _), (b, _)| Ord::cmp(a, b))
|
.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()
|
.enumerate()
|
||||||
.map(|(i, (key, value))| MovementGraphItem {
|
.map(|(i, (key, value))| MovementGraphItem {
|
||||||
index: i,
|
index: i,
|
||||||
name: key.clone(),
|
name: key.clone(),
|
||||||
values: value.clone().into(),
|
values: Self::new(value.clone(), display_options),
|
||||||
item_type: match value {
|
item_type: match value {
|
||||||
GraphItem::User(_) => GraphItemType::Section,
|
GraphItem::User(_) => GraphItemType::Section,
|
||||||
GraphItem::Section(_) => 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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
Loading…
Reference in New Issue
Block a user