Skip to content

Commit

Permalink
Merge pull request #4 from tezedge/new-design
Browse files Browse the repository at this point in the history
New design for endorsements and statistics screen
  • Loading branch information
adonagy authored Feb 3, 2022
2 parents 7eeba13 + 6c634e4 commit 819bb53
Show file tree
Hide file tree
Showing 14 changed files with 667 additions and 430 deletions.
6 changes: 2 additions & 4 deletions src/automaton/automaton_manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crossterm::{
event::KeyCode,
};
use crossterm::event::KeyCode;
use std::time::{Duration, SystemTime};
use tokio::sync::mpsc;
use url::Url;
Expand Down Expand Up @@ -57,7 +55,7 @@ impl<Serv: Service> Automaton<Serv> {
self.store.dispatch(EndorsementsStatusesGetAction {});
}
Some(TuiEvent::Input(key, modifier)) => match key {
KeyCode::Char('q') => {
KeyCode::F(10) => {
self.store.dispatch(ShutdownAction {});
return;
}
Expand Down
143 changes: 85 additions & 58 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use itertools::Itertools;
use strum::IntoEnumIterator;
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Style},
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Span, Spans},
widgets::{Block, Borders, Paragraph, Tabs},
Frame,
Expand All @@ -17,24 +16,34 @@ use crate::{
pub fn create_pages_tabs(ui_state: &UiState) -> Tabs {
let titles = ActivePage::iter()
.map(|t| {
Spans::from(vec![Span::styled(
t.to_string(),
Style::default().fg(Color::White).bg(Color::Black),
)])
Spans::from(vec![
Span::styled(
t.hotkey(),
Style::default().fg(Color::Gray).add_modifier(Modifier::DIM),
),
Span::styled(
t.to_string().to_ascii_uppercase(),
Style::default().fg(Color::White),
),
])
})
.collect();
let page_in_focus = ui_state.active_page.to_index();
Tabs::new(titles)
.block(Block::default().borders(Borders::ALL))
.highlight_style(Style::default().fg(Color::Black).bg(Color::Gray))
.highlight_style(
Style::default()
.fg(Color::White)
.bg(Color::DarkGray)
.remove_modifier(Modifier::DIM),
)
.divider(" ")
.select(page_in_focus)
}

pub fn create_help_bar<B: Backend>(help_chunk: Rect, f: &mut Frame<B>, delta_toggle: bool) {
let help_strings = vec![
("F1 - F3", "PageSwitch"),
("q", "Quit"),
("TAB", "Rotate widgets"),
("←→↑↓", "Navigate Table"),
("s", "Sort"),
(
"d",
if delta_toggle {
Expand All @@ -43,45 +52,28 @@ pub fn create_help_bar<B: Backend>(help_chunk: Rect, f: &mut Frame<B>, delta_tog
"Delta values"
},
),
("s", "Sort ascending"),
("^s", "Sort descending"),
("←", "Table left"),
("→", "Table right"),
("↑", "Table up"),
("↓", "Table down"),
("TAB", "Switch Focus"),
];

let help_chunks = Layout::default()
.direction(Direction::Horizontal)
.margin(1)
.constraints([
Constraint::Length(24),
Constraint::Length(24),
Constraint::Length(24),
Constraint::Length(24),
Constraint::Length(24),
])
.split(help_chunk);

for (index, (row_1, row_2)) in help_strings.iter().tuple_windows().step_by(2).enumerate() {
let p = Paragraph::new(vec![
Spans::from(vec![
let help_spans: Vec<Span> = help_strings
.iter()
.map(|(key, help)| {
vec![
Span::styled(*key, Style::default().fg(Color::White)),
Span::from(" "),
Span::styled(
format!(" {} ", row_1.0),
Style::default().bg(Color::White).fg(Color::Black),
*help,
Style::default().fg(Color::Gray).add_modifier(Modifier::DIM),
),
Span::styled(format!(" {}\n", row_1.1), Style::default()),
]),
Spans::from(vec![
Span::styled(
format!(" {} ", row_2.0),
Style::default().bg(Color::White).fg(Color::Black),
),
Span::styled(format!(" {}\n", row_2.1), Style::default()),
]),
]);
f.render_widget(p, help_chunks[index]);
}
Span::from(" "),
]
})
.flatten()
.collect();

let help_paragraph = Paragraph::new(Spans::from(help_spans))
.block(Block::default().borders(Borders::TOP | Borders::LEFT | Borders::RIGHT));
f.render_widget(help_paragraph, help_chunk);
}

pub fn create_header_bar<B: Backend>(
Expand All @@ -90,42 +82,77 @@ pub fn create_header_bar<B: Backend>(
f: &mut Frame<B>,
) {
// wrap the header info in borders
let block = Block::default().borders(Borders::ALL).title("Current Head");
let block = Block::default()
.borders(Borders::BOTTOM)
.border_style(Style::default().add_modifier(Modifier::DIM));
f.render_widget(block, header_chunk);

let header_chunks = Layout::default()
.direction(Direction::Vertical)
.margin(1)
.constraints([Constraint::Min(1), Constraint::Min(1), Constraint::Min(1)])
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(62),
Constraint::Length(16),
Constraint::Length(18),
])
.split(header_chunk);

let block_hash = Paragraph::new(Spans::from(vec![
Span::styled("Block hash: ", Style::default().fg(Color::Gray)),
Span::styled(
" Block: ",
Style::default().fg(Color::Gray).add_modifier(Modifier::DIM),
),
Span::styled(
format!("{} ", header.hash),
Style::default().fg(Color::Reset),
Style::default().fg(Color::White),
),
]));

f.render_widget(block_hash, header_chunks[0]);

let block_level = Paragraph::new(Spans::from(vec![
Span::styled("Level: ", Style::default().fg(Color::Gray)),
Span::styled(
"Level: ",
Style::default().fg(Color::Gray).add_modifier(Modifier::DIM),
),
Span::styled(
format!("{} ", header.level),
Style::default().fg(Color::Reset),
Style::default().fg(Color::White),
),
]));

f.render_widget(block_level, header_chunks[1]);

// show only the shorter version of the protocol
let protocol_short = if !header.protocol.is_empty() {
header.protocol.split_at(8).0.to_string()
} else {
header.protocol.to_owned()
};

let block_protocol = Paragraph::new(Spans::from(vec![
Span::styled("Protocol: ", Style::default().fg(Color::Gray)),
Span::styled(
format!("{} ", header.protocol),
Style::default().fg(Color::Reset),
"Protocol: ",
Style::default().fg(Color::Gray).add_modifier(Modifier::DIM),
),
Span::styled(
format!("{} ", protocol_short),
Style::default().fg(Color::White),
),
]));

f.render_widget(block_protocol, header_chunks[2]);
}

pub fn create_quit<B: Backend>(last_chunk: Rect, f: &mut Frame<B>) {
let quit = Paragraph::new(Spans::from(vec![
Span::styled(
"F10",
Style::default()
.fg(Color::White)
.add_modifier(Modifier::DIM),
),
Span::styled("QUIT", Style::default().fg(Color::White)),
]))
.alignment(Alignment::Right);
f.render_widget(quit, last_chunk);
}
20 changes: 8 additions & 12 deletions src/endorsements/endorsements_reducer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::collections::BTreeMap;

use crate::{
automaton::{Action, ActionWithMeta, State},
extensions::{SortOrder, SortableByFocus},
};
use crate::automaton::{Action, ActionWithMeta, State};

use super::{
EndorsementState, EndorsementStatus, EndorsementStatusSortable, EndorsementStatusSortableVec,
Expand All @@ -30,7 +27,7 @@ pub fn endorsementrs_reducer(state: &mut State, action: &ActionWithMeta) {
if !slot_mapped.is_empty() {
let mut sumary: BTreeMap<EndorsementState, usize> = BTreeMap::new();

let mut endorsement_operation_time_statistics: EndorsementStatusSortableVec = state
let endorsement_operation_time_statistics: EndorsementStatusSortableVec = state
.endorsmenents
.endorsement_rights
.iter()
Expand All @@ -51,17 +48,16 @@ pub fn endorsementrs_reducer(state: &mut State, action: &ActionWithMeta) {
})
.collect();

let sort_by = state.endorsmenents.endorsement_table.selected();
let delta_toggle = state.delta_toggle;

endorsement_operation_time_statistics.sort_by_focus(sort_by, delta_toggle);
if let SortOrder::Descending = *state.endorsmenents.endorsement_table.sort_order() {
endorsement_operation_time_statistics.reverse();
}

state.endorsmenents.endoresement_status_summary = sumary;
state.endorsmenents.current_head_endorsement_statuses =
state.endorsmenents.endorsement_table.content =
endorsement_operation_time_statistics;

state
.endorsmenents
.endorsement_table
.sort_content(delta_toggle);
}
}
_ => {}
Expand Down
Loading

0 comments on commit 819bb53

Please sign in to comment.