diff --git a/bin/commands/patch/list.rs b/bin/commands/patch/list.rs index 1a4cdf32..b853eaf6 100644 --- a/bin/commands/patch/list.rs +++ b/bin/commands/patch/list.rs @@ -27,7 +27,7 @@ use super::common::PatchOperation; use crate::cob::patch; use crate::ui::items::filter::Filter; -use crate::ui::items::patch::{PatchItem, PatchItemFilter}; +use crate::ui::items::patch::{Patch, PatchFilter}; const HELP: &str = r#"# Generic keybindings @@ -121,12 +121,12 @@ pub struct AppState { search: BufferedValue, show_search: bool, help: TextViewState, - filter: PatchItemFilter, + filter: PatchFilter, } #[derive(Clone, Debug)] pub struct App { - patches: Arc>>, + patches: Arc>>, state: AppState, } @@ -139,13 +139,11 @@ impl TryFrom<&Context> for App { let raw = context.filter.to_string(); raw.trim().to_string() }; - let filter = PatchItemFilter::from_str(&context.filter.to_string()).unwrap_or_default(); + let filter = PatchFilter::from_str(&context.filter.to_string()).unwrap_or_default(); let mut items = patches .into_iter() - .flat_map(|patch| { - PatchItem::new(&context.profile, &context.repository, patch.clone()).ok() - }) + .flat_map(|patch| Patch::new(&context.profile, &context.repository, patch.clone()).ok()) .collect::>(); items.sort_by(|a, b| b.timestamp.cmp(&a.timestamp)); @@ -196,7 +194,7 @@ impl store::Update for App { } self.state.filter = - PatchItemFilter::from_str(&self.state.search.read().text).unwrap_or_default(); + PatchFilter::from_str(&self.state.search.read().text).unwrap_or_default(); None } @@ -215,8 +213,8 @@ impl store::Update for App { } Change::Search { search } => { self.state.search = search; - self.state.filter = PatchItemFilter::from_str(&self.state.search.read().text) - .unwrap_or_default(); + self.state.filter = + PatchFilter::from_str(&self.state.search.read().text).unwrap_or_default(); self.state.patches.select_first(); None } diff --git a/bin/ui/items/patch.rs b/bin/ui/items/patch.rs index 569bb9a7..72c66848 100644 --- a/bin/ui/items/patch.rs +++ b/bin/ui/items/patch.rs @@ -15,7 +15,7 @@ use radicle::cob::thread::Comment; use radicle::cob::{CodeLocation, CodeRange, EntryId, Timestamp}; use radicle::git::Oid; use radicle::patch; -use radicle::patch::{Patch, PatchId, Review}; +use radicle::patch::{PatchId, Review}; use radicle::prelude::Did; use radicle::storage::git::Repository; use radicle::storage::WriteRepository; @@ -47,11 +47,11 @@ use super::format; use super::AuthorItem; #[derive(Clone, Debug)] -pub struct PatchItem { +pub struct Patch { /// Patch OID. pub id: PatchId, /// Patch state. - pub state: patch::State, + pub state: radicle::patch::State, /// Patch title. pub title: String, /// Author of the latest revision. @@ -66,11 +66,11 @@ pub struct PatchItem { pub timestamp: Timestamp, } -impl PatchItem { +impl Patch { pub fn new( profile: &Profile, repository: &Repository, - patch: (PatchId, Patch), + patch: (PatchId, radicle::patch::Patch), ) -> Result { let (id, patch) = patch; let (_, revision) = patch.latest(); @@ -90,7 +90,7 @@ impl PatchItem { } } -impl ToRow<9> for PatchItem { +impl ToRow<9> for Patch { fn to_row(&self) -> [Cell<'_>; 9] { let (state, color) = format::patch_state(&self.state); @@ -136,21 +136,21 @@ impl ToRow<9> for PatchItem { } #[derive(Clone, Default, Debug, Eq, PartialEq)] -pub struct PatchItemFilter { +pub struct PatchFilter { status: Option, authored: bool, authors: Vec, search: Option, } -impl PatchItemFilter { +impl PatchFilter { pub fn is_default(&self) -> bool { - *self == PatchItemFilter::default() + *self == PatchFilter::default() } } -impl Filter for PatchItemFilter { - fn matches(&self, patch: &PatchItem) -> bool { +impl Filter for PatchFilter { + fn matches(&self, patch: &Patch) -> bool { use fuzzy_matcher::skim::SkimMatcherV2; use fuzzy_matcher::FuzzyMatcher; @@ -192,7 +192,7 @@ impl Filter for PatchItemFilter { } } -impl FromStr for PatchItemFilter { +impl FromStr for PatchFilter { type Err = anyhow::Error; fn from_str(value: &str) -> Result { @@ -1177,9 +1177,9 @@ mod tests { #[test] fn patch_item_filter_from_str_should_succeed() -> Result<()> { let search = r#"is:open is:authored authors:[did:key:z6MkkpTPzcq1ybmjQyQpyre15JUeMvZY6toxoZVpLZ8YarsB,did:key:z6Mku8hpprWTmCv3BqkssCYDfr2feUdyLSUnycVajFo9XVAx] cli"#; - let actual = PatchItemFilter::from_str(search)?; + let actual = PatchFilter::from_str(search)?; - let expected = PatchItemFilter { + let expected = PatchFilter { status: Some(patch::Status::Open), authored: true, authors: vec![