From 0d652d78e993c371f5bad5d002529535624879b6 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 2 Jun 2023 10:37:41 +0200 Subject: [PATCH] tui: Make patch and issue items sortable --- radicle-tui/src/app/event.rs | 4 +-- radicle-tui/src/ui/cob.rs | 60 ++++++++++++++++++++++++++++--- radicle-tui/src/ui/widget/home.rs | 16 ++++----- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/radicle-tui/src/app/event.rs b/radicle-tui/src/app/event.rs index 55e2f538..8b03958b 100644 --- a/radicle-tui/src/app/event.rs +++ b/radicle-tui/src/app/event.rs @@ -62,7 +62,7 @@ impl tuirealm::Component for Widget { code: Key::Enter, .. }) => self .selected_item() - .map(|item| Message::Patch(PatchMessage::Show(item.id()))), + .map(|item| Message::Patch(PatchMessage::Show(item.id().to_owned()))), _ => None, } } @@ -85,7 +85,7 @@ impl tuirealm::Component for Widget { code: Key::Enter, .. }) => self .selected_item() - .map(|item| Message::Issue(IssueMessage::Show(item.id()))), + .map(|item| Message::Issue(IssueMessage::Show(item.id().to_owned()))), _ => None, } } diff --git a/radicle-tui/src/ui/cob.rs b/radicle-tui/src/ui/cob.rs index 3ef78f97..fa12ae2a 100644 --- a/radicle-tui/src/ui/cob.rs +++ b/radicle-tui/src/ui/cob.rs @@ -55,8 +55,36 @@ pub struct PatchItem { } impl PatchItem { - pub fn id(&self) -> PatchId { - self.id + pub fn id(&self) -> &PatchId { + &self.id + } + + pub fn state(&self) -> &PatchState { + &self.state + } + + pub fn title(&self) -> &String { + &self.title + } + + pub fn author(&self) -> &AuthorItem { + &self.author + } + + pub fn head(&self) -> &Oid { + &self.head + } + + pub fn added(&self) -> u16 { + self.added + } + + pub fn removed(&self) -> u16 { + self.removed + } + + pub fn timestamp(&self) -> &Timestamp { + &self.timestamp } } @@ -140,8 +168,32 @@ pub struct IssueItem { } impl IssueItem { - pub fn id(&self) -> IssueId { - self.id + pub fn id(&self) -> &IssueId { + &self.id + } + + pub fn state(&self) -> &IssueState { + &self.state + } + + pub fn title(&self) -> &String { + &self.title + } + + pub fn author(&self) -> &AuthorItem { + &self.author + } + + pub fn tags(&self) -> &Vec { + &self.tags + } + + pub fn assignees(&self) -> &Vec { + &self.assignees + } + + pub fn timestamp(&self) -> &Timestamp { + &self.timestamp } } diff --git a/radicle-tui/src/ui/widget/home.rs b/radicle-tui/src/ui/widget/home.rs index eae58466..1c0fc75c 100644 --- a/radicle-tui/src/ui/widget/home.rs +++ b/radicle-tui/src/ui/widget/home.rs @@ -84,10 +84,7 @@ impl IssueBrowser { ]; let mut items = vec![]; - if let Ok(mut issues) = issues { - issues.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp())); - issues.sort_by(|(_, a, _), (_, b, _)| a.state().cmp(b.state())); - + if let Ok(issues) = issues { for (id, patch, _) in issues { if let Ok(item) = IssueItem::try_from((context.profile(), &repo, id, patch)) { items.push(item); @@ -95,6 +92,9 @@ impl IssueBrowser { } } + items.sort_by(|a, b| b.timestamp().cmp(a.timestamp())); + items.sort_by(|a, b| a.state().cmp(b.state())); + let table = Widget::new(Table::new(&items, header, widths, theme.clone())) .highlight(theme.colors.item_list_highlighted_bg); @@ -162,10 +162,7 @@ impl PatchBrowser { ]; let mut items = vec![]; - if let Ok(mut patches) = patches { - patches.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp())); - patches.sort_by(|(_, a, _), (_, b, _)| a.state().cmp(b.state())); - + if let Ok(patches) = patches { for (id, patch, _) in patches { if let Ok(item) = PatchItem::try_from((context.profile(), &repo, id, patch)) { items.push(item); @@ -173,6 +170,9 @@ impl PatchBrowser { } } + items.sort_by(|a, b| b.timestamp().cmp(a.timestamp())); + items.sort_by(|a, b| a.state().cmp(b.state())); + let table = Widget::new(Table::new(&items, header, widths, theme.clone())) .highlight(theme.colors.item_list_highlighted_bg);