Skip to content

Commit dcc51b9

Browse files
committed
feat(patch): Adds review action to list interface
1 parent 9aa7fb2 commit dcc51b9

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

bin/commands/patch.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct ListOptions {
8181
json: bool,
8282
}
8383

84-
#[derive(Debug, Clone, PartialEq, Eq)]
84+
#[derive(Debug, Default, Clone, PartialEq, Eq)]
8585
pub struct ReviewOptions {
8686
patch_id: Option<Rev>,
8787
revision_id: Option<Rev>,
@@ -255,7 +255,7 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
255255
let rid = options.repo.unwrap_or(rid);
256256

257257
// Run TUI with patch list interface
258-
let selection = interface::list(opts.clone(), profile, rid).await?;
258+
let selection = interface::list(opts.clone(), profile.clone(), rid).await?;
259259

260260
if opts.json {
261261
let selection = selection
@@ -267,17 +267,24 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
267267

268268
eprint!("{selection}");
269269
} else if let Some(selection) = selection {
270-
let mut args = vec![];
270+
if let Some(operation) = selection.operation.clone() {
271+
let mut args = vec![operation.to_string()];
271272

272-
if let Some(operation) = selection.operation {
273-
args.push(operation.to_string());
274-
}
275-
if let Some(id) = selection.ids.first() {
276-
args.push(format!("{id}"));
277-
}
273+
if let Some(id) = selection.ids.first() {
274+
args.push(format!("{id}"));
278275

279-
let args = args.into_iter().map(OsString::from).collect::<Vec<_>>();
280-
let _ = crate::terminal::run_rad(Some("patch"), &args);
276+
match operation.as_str() {
277+
"review" => {
278+
let opts = ReviewOptions::default();
279+
interface::review(opts, profile, rid, *id).await?;
280+
}
281+
_ => {
282+
let args = args.into_iter().map(OsString::from).collect::<Vec<_>>();
283+
let _ = crate::terminal::run_rad(Some("patch"), &args);
284+
}
285+
}
286+
}
287+
}
281288
}
282289
}
283290
Operation::Review { ref opts } => {

bin/commands/patch/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub enum Mode {
1919
pub enum PatchOperation {
2020
Checkout,
2121
Diff,
22+
Review,
2223
Show,
2324
}
2425

@@ -31,6 +32,9 @@ impl Display for PatchOperation {
3132
PatchOperation::Diff => {
3233
write!(f, "diff")
3334
}
35+
PatchOperation::Review => {
36+
write!(f, "review")
37+
}
3438
PatchOperation::Show => {
3539
write!(f, "show")
3640
}

bin/commands/patch/list.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ fn browser_page(_state: &State, channel: &Channel<Message>) -> Widget<State, Mes
233233
("enter", "show"),
234234
("c", "checkout"),
235235
("d", "diff"),
236+
("r", "review"),
236237
("/", "search"),
237238
("?", "help"),
238239
],
@@ -266,6 +267,9 @@ fn browser_page(_state: &State, channel: &Channel<Message>) -> Widget<State, Mes
266267
Key::Char('d') => Some(Message::Exit {
267268
operation: Some(PatchOperation::Diff),
268269
}),
270+
Key::Char('r') => Some(Message::Exit {
271+
operation: Some(PatchOperation::Review),
272+
}),
269273
_ => None,
270274
}
271275
} else {

bin/commands/patch/list/imui.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ impl Show<Message> for App {
277277
("enter", "show"),
278278
("c", "checkout"),
279279
("d", "diff"),
280+
("r", "review"),
280281
("/", "search"),
281282
("?", "help"),
282283
]
@@ -300,6 +301,11 @@ impl Show<Message> for App {
300301
operation: Some(PatchOperation::Diff),
301302
});
302303
}
304+
if ui.input_global(|key| key == Key::Char('r')) {
305+
ui.send_message(Message::Exit {
306+
operation: Some(PatchOperation::Review),
307+
});
308+
}
303309
if ui.input_global(|key| key == Key::Char('c')) {
304310
ui.send_message(Message::Exit {
305311
operation: Some(PatchOperation::Checkout),

0 commit comments

Comments
 (0)