Skip to content

Commit 5bd3f38

Browse files
feat: update UI for reply w/ Reviewed-by to subset of patches
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, the button will look like ``` [x] reviewed-by (1,2,7) ``` Signed-off-by: David Tadokoro <[email protected]>
1 parent 9338d9d commit 5bd3f38

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

src/app.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ impl App {
153153
.into_text()?;
154154
patches_preview.push(patch_preview);
155155
}
156+
let has_cover_letter = representative_patch.number_in_series() == 0;
156157
let patches_to_reply = vec![false; raw_patches.len()];
157158
self.patchset_details_and_actions_state = Some(PatchsetDetailsAndActionsState {
158159
representative_patch,
159160
raw_patches,
160161
patches_preview,
161162
patches_to_reply,
163+
has_cover_letter,
162164
preview_index: 0,
163165
preview_scroll_offset: 0,
164166
preview_pan: 0,

src/app/screens/details_actions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub struct PatchsetDetailsAndActionsState {
1414
pub raw_patches: Vec<String>,
1515
/// Patches in the format to be displayed as preview
1616
pub patches_preview: Vec<Text<'static>>,
17+
/// Indicates if patchset has a cover letter
18+
pub has_cover_letter: bool,
1719
/// Which patches to reply
1820
pub patches_to_reply: Vec<bool>,
1921
pub preview_index: usize,

src/ui/details_actions.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,29 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
6363

6464
f.render_widget(patchset_details, details_chunk);
6565

66+
let mut patches_to_reply = String::new();
67+
if let Some(true) = patchset_details_and_actions
68+
.patchset_actions
69+
.get(&PatchsetAction::ReplyWithReviewedBy)
70+
{
71+
patches_to_reply.push('(');
72+
let number_offset = if patchset_details_and_actions.has_cover_letter {
73+
0
74+
} else {
75+
1
76+
};
77+
let patches_to_reply_numbers: Vec<usize> = patchset_details_and_actions
78+
.patches_to_reply
79+
.iter()
80+
.enumerate()
81+
.filter_map(|(i, &val)| if val { Some(i + number_offset) } else { None })
82+
.collect();
83+
for number in patches_to_reply_numbers {
84+
patches_to_reply.push_str(&format!("{number},"));
85+
}
86+
patches_to_reply = format!("{})", &patches_to_reply[..patches_to_reply.len() - 1]);
87+
}
88+
6689
let patchset_actions = &patchset_details_and_actions.patchset_actions;
6790
let patchset_actions = vec![
6891
Line::from(vec![
@@ -81,8 +104,9 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
81104
Span::styled("ookmark", Style::default().fg(Color::Cyan)),
82105
]),
83106
Line::from(vec![
84-
if *patchset_actions
85-
.get(&PatchsetAction::ReplyWithReviewedBy)
107+
if *patchset_details_and_actions
108+
.patches_to_reply
109+
.get(patchset_details_and_actions.preview_index)
86110
.unwrap()
87111
{
88112
Span::styled("[x] ", Style::default().fg(Color::Green))
@@ -96,7 +120,8 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
96120
.add_modifier(Modifier::UNDERLINED)
97121
.add_modifier(Modifier::BOLD),
98122
),
99-
Span::styled("eviewed-by", Style::default().fg(Color::Cyan)),
123+
Span::styled("eviewed-by ", Style::default().fg(Color::Cyan)),
124+
Span::styled(patches_to_reply, Style::default().fg(Color::DarkGray)),
100125
]),
101126
];
102127
let patchset_actions = Paragraph::new(patchset_actions)
@@ -122,10 +147,17 @@ fn render_preview(f: &mut Frame, app: &App, chunk: Rect) {
122147
.message_id()
123148
.href;
124149
let mut preview_title = String::from(" Preview ");
125-
if let Some(successful_indexes) = app.reviewed_patchsets.get(representative_patch_message_id) {
126-
if successful_indexes.contains(&preview_index) {
127-
preview_title = " Preview [REVIEWED] ".to_string();
128-
}
150+
if matches!(
151+
app.reviewed_patchsets.get(representative_patch_message_id),
152+
Some(successful_indexes) if successful_indexes.contains(&preview_index)
153+
) {
154+
preview_title = " Preview [REVIEWED-BY] ".to_string();
155+
} else if *patchset_details_and_actions
156+
.patches_to_reply
157+
.get(preview_index)
158+
.unwrap()
159+
{
160+
preview_title = " Preview [REVIEWED-BY]* ".to_string();
129161
};
130162

131163
let preview_offset = patchset_details_and_actions.preview_scroll_offset;

0 commit comments

Comments
 (0)