add 'All Lines' to match view

This commit is contained in:
Robin Appelman 2024-12-17 19:00:15 +01:00
commit 4d9719345f
5 changed files with 35 additions and 21 deletions

View file

@ -38,6 +38,7 @@ pub struct LogMatch {
pub lines: Vec<usize>, pub lines: Vec<usize>,
pub histogram: TimeGraph, pub histogram: TimeGraph,
pub sparkline: String, pub sparkline: String,
pub all: GroupedLines,
pub grouped: Vec<GroupedLines>, pub grouped: Vec<GroupedLines>,
} }
@ -51,6 +52,11 @@ impl LogMatch {
} }
let grouped = group_lines(all_lines, lines.iter().copied()); let grouped = group_lines(all_lines, lines.iter().copied());
let sparkline = histogram.sparkline::<10>(); let sparkline = histogram.sparkline::<10>();
let all = GroupedLines {
sparkline: sparkline.clone(),
histogram: histogram.clone(),
lines: lines.clone(),
};
LogMatch { LogMatch {
result, result,
@ -58,6 +64,7 @@ impl LogMatch {
histogram, histogram,
sparkline, sparkline,
grouped, grouped,
all,
} }
} }

View file

@ -2,6 +2,7 @@ use hdrhistogram::Histogram;
use std::cmp::max; use std::cmp::max;
use time::OffsetDateTime; use time::OffsetDateTime;
#[derive(Clone)]
pub struct TimeGraph { pub struct TimeGraph {
histogram: Histogram<u64>, histogram: Histogram<u64>,
start: u64, start: u64,

View file

@ -10,7 +10,6 @@ use ratatui::text::Text;
use ratatui::widgets::{Cell, Paragraph, Row, Wrap}; use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
pub struct GroupedLogs<'a> { pub struct GroupedLogs<'a> {
line: &'a LogLine<'a>,
lines: &'a [usize], lines: &'a [usize],
app: &'a App<'a>, app: &'a App<'a>,
filter: &'a Filter, filter: &'a Filter,
@ -21,13 +20,7 @@ pub fn grouped_logs<'a>(
lines: &'a [usize], lines: &'a [usize],
filter: &'a Filter, filter: &'a Filter,
) -> GroupedLogs<'a> { ) -> GroupedLogs<'a> {
let line = &app.lines[lines[0]]; GroupedLogs { lines, app, filter }
GroupedLogs {
line,
lines,
app,
filter,
}
} }
impl StatefulWidget for GroupedLogs<'_> { impl StatefulWidget for GroupedLogs<'_> {
@ -37,24 +30,25 @@ impl StatefulWidget for GroupedLogs<'_> {
where where
Self: Sized, Self: Sized,
{ {
let line = &self.app.lines[self.lines[state.selected()]];
let lines = self.lines.iter().copied().map(|i| &self.app.lines[i]); let lines = self.lines.iter().copied().map(|i| &self.app.lines[i]);
let par = Paragraph::new(format!( let par = Paragraph::new(format!(
"{}{}{}\n\n{} from {} - Nextcloud {}", "{}{}{}\n\n{} from {} - Nextcloud {}",
self.line line
.exception .exception
.as_ref() .as_ref()
.map(|e| e.exception.as_ref()) .map(|e| e.exception.as_ref())
.unwrap_or_default(), .unwrap_or_default(),
if self.line.exception.is_some() { if line.exception.is_some() {
":\n" ":\n"
} else { } else {
"" ""
}, },
self.line.message, line.message,
self.line.level.as_str(), line.level.as_str(),
self.line.app, line.app,
self.line.version, line.version,
)) ))
.wrap(Wrap::default()); .wrap(Wrap::default());

View file

@ -4,6 +4,7 @@ use crate::ui::table::ScrollbarTable;
use ratatui::layout::Constraint; use ratatui::layout::Constraint;
use ratatui::text::Text; use ratatui::text::Text;
use ratatui::widgets::{Cell, Row}; use ratatui::widgets::{Cell, Row};
use std::iter::once;
pub fn grouped_lines<'a>( pub fn grouped_lines<'a>(
app: &'a App<'a>, app: &'a App<'a>,
@ -32,10 +33,19 @@ pub fn grouped_lines<'a>(
Constraint::Min(10), Constraint::Min(10),
]; ];
ScrollbarTable::new( ScrollbarTable::new(
grouped once(Row::new([
.iter() Text::from("All lines"),
.filter(|group| group.matches(app, filter)) Text::from(""),
.map(|group| group_row(app, group)), Text::from(""),
Text::from(log_match.sparkline.as_str()),
Text::from(log_match.lines.len().to_string()),
]))
.chain(
grouped
.iter()
.filter(|group| group.matches(app, filter))
.map(|group| group_row(app, group)),
),
widths, widths,
) )
.header(header) .header(header)

View file

@ -88,14 +88,16 @@ impl<'a> MatchState<'a> {
let mut table_state = TableState::default(); let mut table_state = TableState::default();
table_state.select(Some(0)); table_state.select(Some(0));
let selected_line = if self.filter.is_empty() { let selected_line = if selected == 0 {
&self.result.grouped[selected] &self.result.all
} else if self.filter.is_empty() {
&self.result.grouped[selected - 1]
} else { } else {
self.result self.result
.grouped .grouped
.iter() .iter()
.filter(|grouped| grouped.matches(app, &self.filter)) .filter(|grouped| grouped.matches(app, &self.filter))
.nth(selected) .nth(selected - 1)
.expect("filtered select out of bounds") .expect("filtered select out of bounds")
}; };
let lines = selected_line.lines.as_slice(); let lines = selected_line.lines.as_slice();