Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort selected column + Unified table structure #2

Merged
merged 8 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ slog-async = "2.6"
slog-term = "2.8"
strum = "0.23"
strum_macros = "0.23"
num = "0.4"
49 changes: 16 additions & 33 deletions src/layout/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout},
style::{Color, Style},
text::Spans,
widgets::{Block, BorderType, Borders, Cell, Paragraph, Row, Table},
widgets::{Block, BorderType, Borders, Paragraph, Row, Table},
Frame,
};

Expand Down Expand Up @@ -104,7 +103,8 @@ impl MempoolScreen {
"Baker",
"Status",
"Delta",
"Receive",
"Receive hash",
"Receive content",
"Decode",
"Precheck",
"Apply",
Expand All @@ -115,7 +115,7 @@ impl MempoolScreen {
.collect();

// add ▼ to the selected sorted table
if let Some(v) = headers.get_mut(ui_state.endorsement_sorter_state.in_focus()) {
if let Some(v) = headers.get_mut(3) {
*v = format!("{}▼", v)
}

Expand All @@ -124,49 +124,32 @@ impl MempoolScreen {
let selected_style = Style::default().add_modifier(Modifier::REVERSED);
let normal_style = Style::default().bg(Color::Blue);

let header_cells = headers
.iter()
.map(|h| Cell::from(h.as_str()).style(Style::default()));
let renderable_constraints = ui_state
.endorsement_table
.renderable_constraints(f.size().width - 2);
let header_cells = ui_state
.endorsement_table
.renderable_headers(selected_style);
let header = Row::new(header_cells)
.style(normal_style)
.height(1)
.bottom_margin(1);

let rows = data_state
.current_head_endorsement_statuses
.iter()
.map(|item| {
let item = item.construct_tui_table_data();
let height = item
.iter()
.map(|content| content.chars().filter(|c| *c == '\n').count())
.max()
.unwrap_or(0)
+ 1;
let cells = item.iter().map(|c| Cell::from(c.clone()));
Row::new(cells).height(height as u16)
});
let rows = ui_state.endorsement_table.renderable_rows(
&data_state.current_head_endorsement_statuses,
delta_toggle,
);

let table = Table::new(rows)
.header(header)
.block(endorsers)
.highlight_style(selected_style)
.highlight_symbol(">> ")
.widths(&[
Constraint::Length(6),
Constraint::Length(36),
Constraint::Min(11),
Constraint::Min(8),
Constraint::Min(8),
Constraint::Min(8),
Constraint::Min(9),
Constraint::Min(8),
Constraint::Min(10),
]);
.widths(&renderable_constraints);
f.render_stateful_widget(
table,
endorsements_chunk,
&mut ui_state.endorsement_table_state,
&mut ui_state.endorsement_table.table_state.clone(),
);

// let block = Block::default().borders(Borders::ALL).title("Endorsements");
Expand Down
20 changes: 7 additions & 13 deletions src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use statistics::*;
use strum::IntoEnumIterator;
use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Style},
text::{Span, Spans},
widgets::{Block, Borders, Paragraph, Tabs},
Expand All @@ -23,16 +23,10 @@ use crate::model::{ActivePage, CurrentHeadHeader, UiState};
pub fn create_pages_tabs(ui_state: &UiState) -> Tabs {
let titles = ActivePage::iter()
.map(|t| {
Spans::from(vec![
// Span::styled(
// t.shortcut.clone(),
// Style::default().fg(Color::Yellow).bg(Color::Black),
// ),
Span::styled(
t.to_string(),
Style::default().fg(Color::White).bg(Color::Black),
),
])
Spans::from(vec![Span::styled(
t.to_string(),
Style::default().fg(Color::White).bg(Color::Black),
)])
})
.collect();
let page_in_focus = ui_state.active_page.to_index();
Expand All @@ -55,8 +49,8 @@ pub fn create_help_bar<B: Backend>(help_chunk: Rect, f: &mut Frame<B>, delta_tog
"Delta values"
},
),
("j", "Switch sort left"),
("k", "Switch sort right"),
("s", "Sort ascending"),
("^s", "Sort descending"),
("←", "Table left"),
("→", "Table right"),
("↑", "Table up"),
Expand Down
Loading