Skip to content

Commit

Permalink
feat: update UI for reply w/ Reviewed-by to subset of patches
Browse files Browse the repository at this point in the history
Update the UI for the changes introduced by the two last commits.

This results in the button "[x] reviewed-by" in the "Actions" tab having
a display (in the right side) of the number of the patches that are
staged in gray, e.g., if the patches 1, 2, and 7 are staged, in the tab
"Details", there will be an entry like

```
Reviewed-by*: (1,2,7)
```

Closes: #78

Signed-off-by: David Tadokoro <[email protected]>
  • Loading branch information
davidbtadokoro committed Nov 8, 2024
1 parent f3c5101 commit bb0d654
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ impl App {
.into_text()?;
patches_preview.push(patch_preview);
}
let has_cover_letter = representative_patch.number_in_series() == 0;
let patches_to_reply = vec![false; raw_patches.len()];
self.patchset_details_and_actions_state = Some(PatchsetDetailsAndActionsState {
representative_patch,
raw_patches,
patches_preview,
patches_to_reply,
has_cover_letter,
preview_index: 0,
preview_scroll_offset: 0,
preview_pan: 0,
Expand Down
2 changes: 2 additions & 0 deletions src/app/screens/details_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct PatchsetDetailsAndActionsState {
pub raw_patches: Vec<String>,
/// Patches in the format to be displayed as preview
pub patches_preview: Vec<Text<'static>>,
/// Indicates if patchset has a cover letter
pub has_cover_letter: bool,
/// Which patches to reply
pub patches_to_reply: Vec<bool>,
pub preview_index: usize,
Expand Down
53 changes: 45 additions & 8 deletions src/ui/details_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,31 @@ use crate::app::{screens::details_actions::PatchsetAction, App};
fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, actions_chunk: Rect) {
let patchset_details_and_actions = app.patchset_details_and_actions_state.as_ref().unwrap();

let mut patches_to_reply = String::new();
if let Some(true) = patchset_details_and_actions
.patchset_actions
.get(&PatchsetAction::ReplyWithReviewedBy)
{
patches_to_reply.push('(');
let number_offset = if patchset_details_and_actions.has_cover_letter {
0
} else {
1
};
let patches_to_reply_numbers: Vec<usize> = patchset_details_and_actions
.patches_to_reply
.iter()
.enumerate()
.filter_map(|(i, &val)| if val { Some(i + number_offset) } else { None })
.collect();
for number in patches_to_reply_numbers {
patches_to_reply.push_str(&format!("{number},"));
}
patches_to_reply = format!("{})", &patches_to_reply[..patches_to_reply.len() - 1]);
}

let patchset_details = &patchset_details_and_actions.representative_patch;
let patchset_details = vec![
let mut patchset_details = vec![
Line::from(vec![
Span::styled(r#" Title: "#, Style::default().fg(Color::Cyan)),
Span::styled(
Expand Down Expand Up @@ -49,6 +72,12 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
),
]),
];
if !patches_to_reply.is_empty() {
patchset_details.push(Line::from(vec![
Span::styled("Reviewed-by*: ", Style::default().fg(Color::Cyan)),
Span::styled(patches_to_reply, Style::default().fg(Color::DarkGray)),
]));
}

let patchset_details = Paragraph::new(patchset_details)
.block(
Expand Down Expand Up @@ -81,8 +110,9 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
Span::styled("ookmark", Style::default().fg(Color::Cyan)),
]),
Line::from(vec![
if *patchset_actions
.get(&PatchsetAction::ReplyWithReviewedBy)
if *patchset_details_and_actions
.patches_to_reply
.get(patchset_details_and_actions.preview_index)
.unwrap()
{
Span::styled("[x] ", Style::default().fg(Color::Green))
Expand All @@ -96,7 +126,7 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
.add_modifier(Modifier::UNDERLINED)
.add_modifier(Modifier::BOLD),
),
Span::styled("eviewed-by", Style::default().fg(Color::Cyan)),
Span::styled("eviewed-by ", Style::default().fg(Color::Cyan)),
]),
];
let patchset_actions = Paragraph::new(patchset_actions)
Expand All @@ -122,10 +152,17 @@ fn render_preview(f: &mut Frame, app: &App, chunk: Rect) {
.message_id()
.href;
let mut preview_title = String::from(" Preview ");
if let Some(successful_indexes) = app.reviewed_patchsets.get(representative_patch_message_id) {
if successful_indexes.contains(&preview_index) {
preview_title = " Preview [REVIEWED] ".to_string();
}
if matches!(
app.reviewed_patchsets.get(representative_patch_message_id),
Some(successful_indexes) if successful_indexes.contains(&preview_index)
) {
preview_title = " Preview [REVIEWED-BY] ".to_string();
} else if *patchset_details_and_actions
.patches_to_reply
.get(preview_index)
.unwrap()
{
preview_title = " Preview [REVIEWED-BY]* ".to_string();
};

let preview_offset = patchset_details_and_actions.preview_scroll_offset;
Expand Down

0 comments on commit bb0d654

Please sign in to comment.