Skip to content

Commit

Permalink
Makes query log responsive, hide upstream dns + cilents on small scre…
Browse files Browse the repository at this point in the history
…ens (#2)
  • Loading branch information
Lissy93 committed May 29, 2023
1 parent b65a2a9 commit 951e5a5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub async fn draw_ui(

// Make the charts
let gauge = make_gauge(&stats);
let table = make_query_table(&data);
let table = make_query_table(&data, size.width);
let graph = make_history_chart(&stats);
let paragraph = render_status_paragraph(&status, &stats);
let filters = make_filters_list(filters.filters.as_slice(), size.width);
Expand Down
82 changes: 52 additions & 30 deletions src/widgets/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use tui::{
use chrono::{DateTime, Utc};

use crate::fetch::fetch_query_log::{Query, Question};

pub fn make_query_table(data: &[Query]) -> Table<'_> {
pub fn make_query_table(data: &[Query], width: u16) -> Table<'_> {
let rows = data.iter().map(|query| {
let time = Cell::from(
time_ago(query.time.as_str()).unwrap_or("unknown".to_string())
Expand All @@ -30,36 +29,59 @@ pub fn make_query_table(data: &[Query]) -> Table<'_> {
let upstream = Cell::from(query.upstream.as_str()).style(Style::default().fg(Color::Blue));

let color = make_row_color(&query.reason);
Row::new(vec![time, question, status, client, upstream, elapsed_ms])
Row::new(vec![time, question, status, elapsed_ms, client, upstream])
.style(Style::default().fg(color))
}).collect::<Vec<Row>>(); // Clone the data here

let table = Table::new(rows) // Table now owns its data
.header(Row::new(vec![
Cell::from(Span::raw("Time")),
Cell::from(Span::raw("Request")),
Cell::from(Span::raw("Status")),
Cell::from(Span::raw("Client")),
Cell::from(Span::raw("Upstream DNS")),
Cell::from(Span::raw("Time Taken")),
]))
.block(
Block::default()
.title(Span::styled(
"Query Log",
Style::default().add_modifier(Modifier::BOLD),
))
.borders(Borders::ALL))
.widths(&[
Constraint::Percentage(15),
Constraint::Percentage(35),
Constraint::Percentage(10),
Constraint::Percentage(15),
Constraint::Percentage(15),
Constraint::Percentage(10),
}).collect::<Vec<Row>>();


let title = Span::styled(
"Query Log",
Style::default().add_modifier(Modifier::BOLD),
);

let block = Block::default()
.title(title)
.borders(Borders::ALL);

let mut headers = vec![
Cell::from(Span::raw("Time")),
Cell::from(Span::raw("Request")),
Cell::from(Span::raw("Status")),
Cell::from(Span::raw("Time Taken")),
];

if width > 120 {
headers.extend(vec![
Cell::from(Span::raw("Client")),
Cell::from(Span::raw("Upstream DNS")),
]);

table

let widths = &[
Constraint::Percentage(15),
Constraint::Percentage(35),
Constraint::Percentage(10),
Constraint::Percentage(10),
Constraint::Percentage(15),
Constraint::Percentage(15),
];

Table::new(rows)
.header(Row::new(headers))
.widths(widths)
.block(block)
} else {
let widths = &[
Constraint::Percentage(20),
Constraint::Percentage(40),
Constraint::Percentage(20),
Constraint::Percentage(20),
];

Table::new(rows)
.header(Row::new(headers))
.widths(widths)
.block(block)
}
}

// Given a timestamp, return a string representing how long ago that was
Expand Down

0 comments on commit 951e5a5

Please sign in to comment.