bin/ui: Rename patch types

This commit is contained in:
Erik Kundt
2025-12-18 13:31:57 +01:00
parent 19b443ac64
commit b0744f861c
2 changed files with 22 additions and 24 deletions
+8 -10
View File
@@ -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<TextEditState>,
show_search: bool,
help: TextViewState,
filter: PatchItemFilter,
filter: PatchFilter,
}
#[derive(Clone, Debug)]
pub struct App {
patches: Arc<Mutex<Vec<PatchItem>>>,
patches: Arc<Mutex<Vec<Patch>>>,
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::<Vec<_>>();
items.sort_by(|a, b| b.timestamp.cmp(&a.timestamp));
@@ -196,7 +194,7 @@ impl store::Update<Message> 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<Message> 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
}
+14 -14
View File
@@ -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<Self, anyhow::Error> {
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<patch::Status>,
authored: bool,
authors: Vec<Did>,
search: Option<String>,
}
impl PatchItemFilter {
impl PatchFilter {
pub fn is_default(&self) -> bool {
*self == PatchItemFilter::default()
*self == PatchFilter::default()
}
}
impl Filter<PatchItem> for PatchItemFilter {
fn matches(&self, patch: &PatchItem) -> bool {
impl Filter<Patch> for PatchFilter {
fn matches(&self, patch: &Patch) -> bool {
use fuzzy_matcher::skim::SkimMatcherV2;
use fuzzy_matcher::FuzzyMatcher;
@@ -192,7 +192,7 @@ impl Filter<PatchItem> for PatchItemFilter {
}
}
impl FromStr for PatchItemFilter {
impl FromStr for PatchFilter {
type Err = anyhow::Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
@@ -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![