tui: Make patch and issue items sortable
This commit is contained in:
parent
78344f8a9f
commit
0d652d78e9
|
|
@ -62,7 +62,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<PatchBrowser> {
|
|||
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<Message, NoUserEvent> for Widget<IssueBrowser> {
|
|||
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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Tag> {
|
||||
&self.tags
|
||||
}
|
||||
|
||||
pub fn assignees(&self) -> &Vec<AuthorItem> {
|
||||
&self.assignees
|
||||
}
|
||||
|
||||
pub fn timestamp(&self) -> &Timestamp {
|
||||
&self.timestamp
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue