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, ..
|
code: Key::Enter, ..
|
||||||
}) => self
|
}) => self
|
||||||
.selected_item()
|
.selected_item()
|
||||||
.map(|item| Message::Patch(PatchMessage::Show(item.id()))),
|
.map(|item| Message::Patch(PatchMessage::Show(item.id().to_owned()))),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +85,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<IssueBrowser> {
|
||||||
code: Key::Enter, ..
|
code: Key::Enter, ..
|
||||||
}) => self
|
}) => self
|
||||||
.selected_item()
|
.selected_item()
|
||||||
.map(|item| Message::Issue(IssueMessage::Show(item.id()))),
|
.map(|item| Message::Issue(IssueMessage::Show(item.id().to_owned()))),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,36 @@ pub struct PatchItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PatchItem {
|
impl PatchItem {
|
||||||
pub fn id(&self) -> PatchId {
|
pub fn id(&self) -> &PatchId {
|
||||||
self.id
|
&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 {
|
impl IssueItem {
|
||||||
pub fn id(&self) -> IssueId {
|
pub fn id(&self) -> &IssueId {
|
||||||
self.id
|
&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![];
|
let mut items = vec![];
|
||||||
if let Ok(mut issues) = issues {
|
if let Ok(issues) = issues {
|
||||||
issues.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
|
|
||||||
issues.sort_by(|(_, a, _), (_, b, _)| a.state().cmp(b.state()));
|
|
||||||
|
|
||||||
for (id, patch, _) in issues {
|
for (id, patch, _) in issues {
|
||||||
if let Ok(item) = IssueItem::try_from((context.profile(), &repo, id, patch)) {
|
if let Ok(item) = IssueItem::try_from((context.profile(), &repo, id, patch)) {
|
||||||
items.push(item);
|
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()))
|
let table = Widget::new(Table::new(&items, header, widths, theme.clone()))
|
||||||
.highlight(theme.colors.item_list_highlighted_bg);
|
.highlight(theme.colors.item_list_highlighted_bg);
|
||||||
|
|
||||||
|
|
@ -162,10 +162,7 @@ impl PatchBrowser {
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut items = vec![];
|
let mut items = vec![];
|
||||||
if let Ok(mut patches) = patches {
|
if let Ok(patches) = patches {
|
||||||
patches.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
|
|
||||||
patches.sort_by(|(_, a, _), (_, b, _)| a.state().cmp(b.state()));
|
|
||||||
|
|
||||||
for (id, patch, _) in patches {
|
for (id, patch, _) in patches {
|
||||||
if let Ok(item) = PatchItem::try_from((context.profile(), &repo, id, patch)) {
|
if let Ok(item) = PatchItem::try_from((context.profile(), &repo, id, patch)) {
|
||||||
items.push(item);
|
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()))
|
let table = Widget::new(Table::new(&items, header, widths, theme.clone()))
|
||||||
.highlight(theme.colors.item_list_highlighted_bg);
|
.highlight(theme.colors.item_list_highlighted_bg);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue