Skip to content

Commit cc974e9

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, in the tab "Details", there will be an entry like ``` Reviewed-by*: (1,2,7) ``` Closes: #78 Signed-off-by: David Tadokoro <[email protected]>
1 parent f3c5101 commit cc974e9

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-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: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ use crate::app::{screens::details_actions::PatchsetAction, App};
1111
fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, actions_chunk: Rect) {
1212
let patchset_details_and_actions = app.patchset_details_and_actions_state.as_ref().unwrap();
1313

14+
let mut patches_to_reply = String::new();
15+
if let Some(true) = patchset_details_and_actions
16+
.patchset_actions
17+
.get(&PatchsetAction::ReplyWithReviewedBy)
18+
{
19+
patches_to_reply.push('(');
20+
let number_offset = if patchset_details_and_actions.has_cover_letter {
21+
0
22+
} else {
23+
1
24+
};
25+
let patches_to_reply_numbers: Vec<usize> = patchset_details_and_actions
26+
.patches_to_reply
27+
.iter()
28+
.enumerate()
29+
.filter_map(|(i, &val)| if val { Some(i + number_offset) } else { None })
30+
.collect();
31+
for number in patches_to_reply_numbers {
32+
patches_to_reply.push_str(&format!("{number},"));
33+
}
34+
patches_to_reply = format!("{})", &patches_to_reply[..patches_to_reply.len() - 1]);
35+
}
36+
1437
let patchset_details = &patchset_details_and_actions.representative_patch;
1538
let patchset_details = vec![
1639
Line::from(vec![
@@ -48,6 +71,14 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
4871
Style::default().fg(Color::White),
4972
),
5073
]),
74+
if !patches_to_reply.is_empty() {
75+
Line::from(vec![
76+
Span::styled("Reviewed-by*: ", Style::default().fg(Color::Cyan)),
77+
Span::styled(patches_to_reply, Style::default().fg(Color::DarkGray)),
78+
])
79+
} else {
80+
Line::from(Span::default())
81+
},
5182
];
5283

5384
let patchset_details = Paragraph::new(patchset_details)
@@ -81,8 +112,9 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
81112
Span::styled("ookmark", Style::default().fg(Color::Cyan)),
82113
]),
83114
Line::from(vec![
84-
if *patchset_actions
85-
.get(&PatchsetAction::ReplyWithReviewedBy)
115+
if *patchset_details_and_actions
116+
.patches_to_reply
117+
.get(patchset_details_and_actions.preview_index)
86118
.unwrap()
87119
{
88120
Span::styled("[x] ", Style::default().fg(Color::Green))
@@ -96,7 +128,7 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
96128
.add_modifier(Modifier::UNDERLINED)
97129
.add_modifier(Modifier::BOLD),
98130
),
99-
Span::styled("eviewed-by", Style::default().fg(Color::Cyan)),
131+
Span::styled("eviewed-by ", Style::default().fg(Color::Cyan)),
100132
]),
101133
];
102134
let patchset_actions = Paragraph::new(patchset_actions)
@@ -122,10 +154,17 @@ fn render_preview(f: &mut Frame, app: &App, chunk: Rect) {
122154
.message_id()
123155
.href;
124156
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-
}
157+
if matches!(
158+
app.reviewed_patchsets.get(representative_patch_message_id),
159+
Some(successful_indexes) if successful_indexes.contains(&preview_index)
160+
) {
161+
preview_title = " Preview [REVIEWED-BY] ".to_string();
162+
} else if *patchset_details_and_actions
163+
.patches_to_reply
164+
.get(preview_index)
165+
.unwrap()
166+
{
167+
preview_title = " Preview [REVIEWED-BY]* ".to_string();
129168
};
130169

131170
let preview_offset = patchset_details_and_actions.preview_scroll_offset;

0 commit comments

Comments
 (0)