From e0241050f8fb77a1623cb76f8913fc6b031c3a93 Mon Sep 17 00:00:00 2001 From: Slack Coder Date: Thu, 4 May 2023 11:34:04 -0500 Subject: [PATCH] cli: List issues consistent Help the user by ordering issue listing by their creation time to make it consistent. --- radicle-cli/src/commands/issue.rs | 36 ++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/radicle-cli/src/commands/issue.rs b/radicle-cli/src/commands/issue.rs index 3084c54e..73916db9 100644 --- a/radicle-cli/src/commands/issue.rs +++ b/radicle-cli/src/commands/issue.rs @@ -338,6 +338,24 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { None => None, }; + let mut all = Vec::new(); + for result in issues.all()? { + let (id, issue, _) = result?; + + if Some(true) == assignee.map(|a| !issue.assigned().any(|v| v == Did::from(a))) { + continue; + } + + all.push((id, issue)) + } + + all.sort_by(|(id1, i1), (id2, i2)| { + let by_timestamp = i2.timestamp().cmp(&i1.timestamp()); + let by_id = id1.cmp(id2); + + by_timestamp.then(by_id) + }); + let mut t = term::Table::new(term::table::TableOptions::bordered()); t.push([ term::format::dim(String::from("●")), @@ -350,18 +368,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { ]); t.divider(); - for result in issues.all()? { - let (id, issue, _) = result?; - let assigned: Vec<_> = issue.assigned().collect(); - let state = issue.state(); - - if Some(true) == assignee.map(|a| !assigned.contains(&Did::from(a))) { - continue; - } - - let assigned: String = assigned - .iter() - .map(|p| term::format::did(p).to_string()) + for (id, issue) in all { + let assigned: String = issue + .assigned() + .map(|p| term::format::did(&p).to_string()) .collect::>() .join(", "); @@ -369,7 +379,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { tags.sort(); t.push([ - match state { + match issue.state() { State::Open => term::format::positive("●").into(), State::Closed { .. } => term::format::negative("●").into(), },