From 63f3db04274c57927aefeeb3191c6033bc132698 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 4 Mar 2024 23:55:36 +0100 Subject: [PATCH] patch: Hide irrelevant footer blocks when filtered --- bin/commands/patch/flux/select/ui.rs | 91 +++++++++++++++++++--------- 1 file changed, 62 insertions(+), 29 deletions(-) diff --git a/bin/commands/patch/flux/select/ui.rs b/bin/commands/patch/flux/select/ui.rs index 7b3ba10a..3a8a360f 100644 --- a/bin/commands/patch/flux/select/ui.rs +++ b/bin/commands/patch/flux/select/ui.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::vec; -use radicle::patch; +use radicle::patch::{self}; use tokio::sync::mpsc::UnboundedSender; @@ -14,7 +14,7 @@ use ratatui::text::Line; use radicle_tui as tui; -use tui::common::cob::patch::Filter; +use tui::common::cob::patch::{Filter, State}; use tui::flux::ui::cob::PatchItem; use tui::flux::ui::span; use tui::flux::ui::widget::container::{Footer, FooterProps, Header, HeaderProps}; @@ -372,6 +372,7 @@ impl Patches { ] .to_vec(), ); + let draft = Line::from( [ span::default(self.props.stats.get("Draft").unwrap_or(&0).to_string()).dim(), @@ -379,6 +380,7 @@ impl Patches { ] .to_vec(), ); + let open = Line::from( [ span::positive(self.props.stats.get("Open").unwrap_or(&0).to_string()).dim(), @@ -386,6 +388,7 @@ impl Patches { ] .to_vec(), ); + let merged = Line::from( [ span::default(self.props.stats.get("Merged").unwrap_or(&0).to_string()) @@ -395,6 +398,7 @@ impl Patches { ] .to_vec(), ); + let archived = Line::from( [ span::default(self.props.stats.get("Archived").unwrap_or(&0).to_string()) @@ -404,6 +408,7 @@ impl Patches { ] .to_vec(), ); + let sum = Line::from( [ span::default("Σ ".to_string()).dim(), @@ -417,33 +422,61 @@ impl Patches { .progress_percentage(self.props.patches.len(), self.props.page_size); let progress = span::default(format!("{}%", progress)).dim(); - self.footer.render::( - frame, - area, - FooterProps { - cells: [ - filter.into(), - draft.clone().into(), - open.clone().into(), - merged.clone().into(), - archived.clone().into(), - sum.clone().into(), - progress.clone().into(), - ], - widths: [ - Constraint::Fill(1), - Constraint::Min(draft.width() as u16), - Constraint::Min(open.width() as u16), - Constraint::Min(merged.width() as u16), - Constraint::Min(archived.width() as u16), - Constraint::Min(sum.width() as u16), - Constraint::Min(4), - ], - focus: self.props.focus, - cutoff: self.props.cutoff, - cutoff_after: self.props.cutoff_after, - }, - ); + match self.props.filter.state() { + Some(state) => { + let block = match state { + State::Draft => draft, + State::Open => open, + State::Merged => merged, + State::Archived => archived, + }; + + self.footer.render::( + frame, + area, + FooterProps { + cells: [filter.into(), block.clone().into(), progress.clone().into()], + widths: [ + Constraint::Fill(1), + Constraint::Min(block.width() as u16), + Constraint::Min(4), + ], + focus: self.props.focus, + cutoff: self.props.cutoff, + cutoff_after: self.props.cutoff_after, + }, + ); + } + None => { + self.footer.render::( + frame, + area, + FooterProps { + cells: [ + filter.into(), + draft.clone().into(), + open.clone().into(), + merged.clone().into(), + archived.clone().into(), + sum.clone().into(), + progress.clone().into(), + ], + widths: [ + Constraint::Fill(1), + Constraint::Min(draft.width() as u16), + Constraint::Min(open.width() as u16), + Constraint::Min(merged.width() as u16), + Constraint::Min(archived.width() as u16), + Constraint::Min(sum.width() as u16), + Constraint::Min(4), + ], + focus: self.props.focus, + cutoff: self.props.cutoff, + cutoff_after: self.props.cutoff_after, + }, + ); + } + }; } }